/[ascend]/trunk/pygtk/variable.cpp
ViewVC logotype

Contents of /trunk/pygtk/variable.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 732 - (show annotations) (download) (as text)
Tue Jul 4 14:40:17 2006 UTC (17 years, 11 months ago) by johnpye
File MIME type: text/x-c++src
File size: 1976 byte(s)
Added general-purpose text-information dialog to PyGTK interface.
Added reporting of clique of a variable to PyGTK GUI.
Changed 'fixable' and 'new bounds' to use the new dialog.
Removed 'set<...>' from ascpy.i (it wasn't working), changed to vector<...>.
Exported a couple of var incidences fns to the DLL/SO.
1 #include <iostream>
2 #include <stdexcept>
3
4 #include "variable.h"
5 #include "simulation.h"
6
7 extern "C"{
8 #include <utilities/ascConfig.h>
9 #include <utilities/ascMalloc.h>
10
11 #include <general/dstring.h>
12 #include <compiler/compiler.h>
13 #include <compiler/symtab.h>
14 #include <compiler/instance_enum.h>
15 #include <compiler/instance_io.h>
16 }
17
18 using namespace std;
19
20 Variable::Variable(){
21 sim=NULL;
22 var=NULL;
23
24 // default ctor
25 }
26
27 Variable::Variable(const Variable &old) : sim(old.sim), var(old.var){
28 // copy ctor
29 }
30
31 Variable::Variable(Simulation *sim, struct var_variable *var) : sim(sim), var(var){
32 if(var==NULL)throw runtime_error("Variable::Variable: var is NULL");
33 }
34
35 const string
36 Variable::getName() const{
37 if(var==NULL)throw runtime_error("Variable::Variable: var is NULL");
38 char *n = WriteInstanceNameString((struct Instance *)var_instance(var),sim->getModel().getInternalType());
39 if(n==NULL)throw runtime_error("Variable::Variable: n is NULL");
40 string name = n;
41 ascfree(n);
42
43 return name;
44 }
45
46 const double
47 Variable::getValue() const{
48 return var_value(var);
49 }
50
51 const double
52 Variable::getNominal() const{
53 return var_nominal(var);
54 }
55
56 const double
57 Variable::getLowerBound() const{
58 return var_lower_bound(var);
59 }
60
61 const double
62 Variable::getUpperBound() const{
63 return var_upper_bound(var);
64 }
65
66 /**
67 Get the var_incidence_list for the variable in question.
68 Note that this is from the solver's point of view; all sorts
69 of important things might occur due to 'WHEN' sections in the model,
70 and perhaps other things.
71
72 Not clear what happens here with 'inactive' vars, need to check the
73 solver-side implementation of this.
74 */
75 const vector<Relation>
76 Variable::getIncidentRelations() const{
77 struct rel_relation **incid = var_incidence_list_to_modify(var);
78 int n = var_n_incidences(var);
79 vector<Relation> v;
80 for(int i=0; i<n; ++i){
81 v.push_back(Relation(sim,incid[i]));
82 }
83 return v;
84 }
85
86 const int
87 Variable::getNumIncidentRelations() const{
88 return var_n_incidences(var);
89 }
90
91

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22