1 |
#include <iostream> |
2 |
#include <stdexcept> |
3 |
|
4 |
#include "variable.h" |
5 |
#include "relation.h" |
6 |
#include "simulation.h" |
7 |
|
8 |
extern "C"{ |
9 |
#include <ascend/general/platform.h> |
10 |
#include <ascend/general/ascMalloc.h> |
11 |
|
12 |
#include <ascend/general/dstring.h> |
13 |
|
14 |
#include <ascend/compiler/symtab.h> |
15 |
#include <ascend/compiler/instance_enum.h> |
16 |
#include <ascend/compiler/instance_io.h> |
17 |
} |
18 |
|
19 |
using namespace std; |
20 |
|
21 |
Variable::Variable(){ |
22 |
sim=NULL; |
23 |
var=NULL; |
24 |
|
25 |
// default ctor |
26 |
} |
27 |
|
28 |
Variable::Variable(const Variable &old) : sim(old.sim), var(old.var){ |
29 |
// copy ctor |
30 |
} |
31 |
|
32 |
Variable::Variable(Simulation *sim, struct var_variable *var) : sim(sim), var(var){ |
33 |
if(var==NULL)throw runtime_error("Variable::Variable: var is NULL"); |
34 |
} |
35 |
|
36 |
const string |
37 |
Variable::getName() const{ |
38 |
if(var==NULL)throw runtime_error("Variable::Variable: var is NULL"); |
39 |
char *n = WriteInstanceNameString((struct Instance *)var_instance(var),sim->getModel().getInternalType()); |
40 |
if(n==NULL)throw runtime_error("Variable::Variable: n is NULL"); |
41 |
string name = n; |
42 |
ascfree(n); |
43 |
|
44 |
return name; |
45 |
} |
46 |
|
47 |
const double |
48 |
Variable::getValue() const{ |
49 |
return var_value(var); |
50 |
} |
51 |
|
52 |
const double |
53 |
Variable::getNominal() const{ |
54 |
return var_nominal(var); |
55 |
} |
56 |
|
57 |
const double |
58 |
Variable::getLowerBound() const{ |
59 |
return var_lower_bound(var); |
60 |
} |
61 |
|
62 |
const double |
63 |
Variable::getUpperBound() const{ |
64 |
return var_upper_bound(var); |
65 |
} |
66 |
|
67 |
/** |
68 |
Get the var_incidence_list for the variable in question. |
69 |
Note that this is from the solver's point of view; all sorts |
70 |
of important things might occur due to 'WHEN' sections in the model, |
71 |
and perhaps other things. |
72 |
|
73 |
Not clear what happens here with 'inactive' vars, need to check the |
74 |
solver-side implementation of this. |
75 |
*/ |
76 |
const vector<Relation> |
77 |
Variable::getIncidentRelations() const{ |
78 |
struct rel_relation **incid = var_incidence_list_to_modify(var); |
79 |
int n = var_n_incidences(var); |
80 |
vector<Relation> v; |
81 |
for(int i=0; i<n; ++i){ |
82 |
v.push_back(Relation(sim,incid[i])); |
83 |
} |
84 |
return v; |
85 |
} |
86 |
|
87 |
const int |
88 |
Variable::getNumIncidentRelations() const{ |
89 |
return var_n_incidences(var); |
90 |
} |
91 |
|
92 |
Instanc |
93 |
Variable::getInstance(){ |
94 |
return Instanc((struct Instance *)var_instance(var),"variablefromsolver"); |
95 |
} |