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

Annotation of /trunk/pygtk/instance.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1960 - (hide annotations) (download) (as text)
Mon Nov 17 12:15:56 2008 UTC (15 years, 8 months ago) by jpye
File MIME type: text/x-c++src
File size: 18651 byte(s)
Add setIntValue to Python wrapper for Instance class.
Added getModule method for Type, planned for use with canvas-based modeller.
1 johnpye 132
2 johnpye 1039 /* needs to be first so that <Python.h> gets included before <iostream> */
3     #include "library.h"
4    
5     #include "instance.h"
6     #include "variable.h"
7     #include "name.h"
8     #include "set.h"
9     #include "plot.h"
10     #include "instanceinterfacedata.h"
11    
12 johnpye 132 extern "C"{
13     #include <utilities/ascConfig.h>
14 johnpye 1039 #include <compiler/instance_types.h>
15 johnpye 132 #include <utilities/ascSignal.h>
16     #include <utilities/ascMalloc.h>
17     #include <general/dstring.h>
18 johnpye 1210
19 johnpye 132 #include <compiler/symtab.h>
20     #include <compiler/instance_io.h>
21     #include <compiler/instantiate.h>
22     #include <compiler/bintoken.h>
23     #include <compiler/instquery.h>
24     #include <compiler/check.h>
25     #include <compiler/name.h>
26     #include <compiler/parentchild.h>
27     #include <compiler/instance_name.h>
28     #include <compiler/atomvalue.h>
29     #include <utilities/readln.h>
30 johnpye 172 #include <compiler/plot.h>
31 johnpye 669 #include <compiler/expr_types.h>
32 johnpye 207 #include <compiler/find.h>
33     #include <compiler/exprs.h>
34     #include <compiler/relation.h>
35     #include <compiler/relation_io.h>
36 johnpye 273 #include <compiler/functype.h>
37     #include <compiler/relation_util.h>
38 jpye 1741 #include <compiler/logrel_util.h>
39     #include <compiler/mathinst.h>
40 johnpye 132 }
41    
42 johnpye 1039 #include <iostream>
43     #include <stdexcept>
44     #include <sstream>
45 johnpye 132
46 johnpye 732 using namespace std;
47    
48 johnpye 132 /**
49     Create an instance of a type. @see Simulation for instantiation.
50     */
51     Instanc::Instanc(Instance *i) : i(i), name("unnamed1"){
52     if(i==NULL){
53     stringstream ss;
54     ss << "Attempted to create Instance object will null 'Instance *', name " << name;
55     throw runtime_error(ss.str());
56     }
57     //throw runtime_error("Created unnamed instance");
58     // nothing else;
59     }
60    
61     Instanc::Instanc(Instance *i, const SymChar &name) : i(i), name(name){
62     /*if(i==NULL){
63     stringstream ss;
64     ss << "Attempted to create Instance object will null 'Instance *', name " << name;
65     throw runtime_error(ss.str());
66     }*/
67 johnpye 876 //cerr << "A NEW INSTANCE " << name << endl;
68 johnpye 132 }
69    
70     Instanc::Instanc(const Instanc&old) : i(old.i), name(old.name){
71     // nothing else
72     }
73    
74 johnpye 1198 Instanc::Instanc() : i(NULL), name("unnamed0"){
75     // nothing else
76 johnpye 132 }
77    
78     /*
79     Create a child instance given the parent
80     */
81 johnpye 190 Instanc::Instanc(const Instanc &parent, const unsigned long &childnum)
82 johnpye 132 : i( InstanceChild(parent.i,childnum) ), name( ChildName(parent.i,childnum) ){
83     // cerr << "CREATED CHILD #" << childnum << ", named '" << getName() << "' OF " << parent.getName() << endl;
84     }
85    
86 johnpye 844 /**
87     Destructor
88 johnpye 732
89     There's no data owned by this object, so nothing to be done here.
90     */
91     Instanc::~Instanc(){
92 johnpye 1197 /* we seriously need a way to free 'interface pointer' data. this doesn't work
93     though, because Python gets messed up
94     InstanceInterfaceData *d = (InstanceInterfaceData *)GetInterfacePtr(i);
95     if(d){
96     cerr << "Destroying interface pointer data" << endl;
97     delete d;
98     }
99     */
100 johnpye 732 //cerr << "DESTROYING INSTANC OBJECT" << endl;
101     }
102    
103 johnpye 132 const SymChar &
104     Instanc::getName() const{
105     return name;
106     }
107    
108     void
109     Instanc::setName(SymChar name){
110     this->name=name;
111 johnpye 190 }
112 johnpye 132
113     Instance *
114     Instanc::getInternalType() const{
115     return i;
116     }
117    
118     const enum inst_t
119     Instanc::getKind() const{
120 johnpye 1300 if(i==NULL){
121     return DUMMY_INST;
122     }
123 johnpye 132 return InstanceKind(i);
124     }
125    
126     /**
127     Return the type of this instance as a string
128     */
129     const string
130     Instanc::getKindStr() const{
131     enum inst_t k = getKind();
132     stringstream ss;
133    
134     switch(k){
135     case ERROR_INST: ss << "Error"; break;
136     case SIM_INST: ss << "Simulation"; break;
137     case MODEL_INST: ss << "Model"; break;
138     case REL_INST: ss << "Numerical Relation"; break;
139     case LREL_INST: ss << "Logical relation"; break;
140     case WHEN_INST: ss << "WHEN"; break;
141     case ARRAY_INT_INST: ss << "Indexed Array"; break;
142     case ARRAY_ENUM_INST: ss << "Enumerated Array"; break;
143     case REAL_INST: ss << "Real"; break;
144     case INTEGER_INST: ss << "Integer"; break;
145     case BOOLEAN_INST: ss << "Boolean"; break;
146     case SYMBOL_INST: ss << "Symbol"; break;
147     case SET_INST: ss << "Set"; break;
148     case REAL_ATOM_INST: ss << "Real atom"; break;
149     case INTEGER_ATOM_INST: ss << "Integer atom"; break;
150     case BOOLEAN_ATOM_INST: ss << "Boolean atom"; break;
151     case SYMBOL_ATOM_INST: ss << "Symbol atom"; break;
152     case SET_ATOM_INST: ss << "Set atom"; break;
153     case REAL_CONSTANT_INST: ss << "Real constant"; break;
154     case BOOLEAN_CONSTANT_INST: ss << "Boolean constant"; break;
155     case INTEGER_CONSTANT_INST: ss << "Integer constant"; break;
156     case SYMBOL_CONSTANT_INST: ss << "Symbol constant"; break;
157     case DUMMY_INST: ss << "Dummy"; break;
158     default:
159     throw runtime_error("Invalid instance type");
160     }
161    
162     ss << " instance";
163     return ss.str();
164     }
165    
166     const Type
167     Instanc::getType() const{
168 johnpye 1300 if(i==NULL){
169     throw runtime_error("Invalid NULL instance (getType)");
170     }
171 johnpye 132 try{
172     const TypeDescription *t = InstanceTypeDesc(i);
173     if(t==NULL)throw runtime_error("No type defined");
174    
175     return Type(t);
176     }catch(runtime_error &e){
177     stringstream ss;
178     ss << "Instance::getType: with name=" << getName() << ":" << e.what();
179     throw runtime_error(ss.str());
180     }
181     }
182    
183     const bool
184     Instanc::isAtom() const{
185     return getKind() & IATOM;
186     //return IsAtomicInstance(i);
187     }
188    
189     const bool
190     Instanc::isFixed() const{
191 johnpye 973 if(getKind()!=REAL_ATOM_INST) throw runtime_error("Instanc::isFixed: not a REAL_ATOM_INST");
192     if(isFund()) throw runtime_error("Instanc::isFixed: not a fundamental type");
193     Type T = getType();
194     if(!T.isRefinedSolverVar()){
195     stringstream ss;
196     ss << "Instanc::isFixed: type '" << T.getName() << "' is not a refined solver_var";
197     throw runtime_error(ss.str());
198 johnpye 132 }
199 johnpye 973 return getChild("fixed").getBoolValue();
200 johnpye 132 }
201    
202 jpye 1360 /** Is the relation currently included in the simulation */
203 johnpye 132 const bool
204 jpye 1360 Instanc::isIncluded() const{
205 johnpye 806 if(getKind()==REL_INST){
206     return getChild("included").getBoolValue();
207     }
208 jpye 1360 throw runtime_error("Instanc::isIncluded: Not a relation");
209 johnpye 806 }
210    
211     const bool
212 johnpye 132 Instanc::isCompound() const{
213     return getKind() & ICOMP;
214     }
215    
216     const bool
217     Instanc::isRelation() const{
218 johnpye 799 if(getKind()==REL_INST){
219     return true;
220 johnpye 132 }
221 johnpye 799 return false;
222 johnpye 132 }
223    
224     const bool
225 johnpye 799 Instanc::isLogicalRelation() const{
226     if(getKind()==LREL_INST){
227     return true;
228     }
229     return false;
230     }
231    
232     const bool
233 johnpye 132 Instanc::isWhen() const{
234     if(getKind()==WHEN_INST)return true;
235     return false;
236     }
237    
238     const bool
239     Instanc::isSet() const{
240     return (getKind() == SET_INST || getKind() == SET_ATOM_INST);
241     }
242    
243     const bool
244     Instanc::isSetInt() const{
245     return isSet() && getSetType()==integer_set;
246     }
247    
248     const bool
249     Instanc::isSetString() const{
250     return isSet() && getSetType()==string_set;
251     }
252    
253     const bool
254     Instanc::isSetEmpty() const{
255     return isSet() && getSetType()==empty_set;
256     }
257    
258     const bool
259     Instanc::isFund() const{
260     return getKind() & IFUND;
261     //return IsFundamentalInstance(i);
262     }
263    
264     const bool
265     Instanc::isConst() const{
266     return getKind() & ICONS;
267     //return IsConstantInstance(i);
268     }
269    
270     const bool
271     Instanc::isAssigned() const{
272     if(!isAtom()){
273     throw runtime_error("Instanc::isAssigned: not an Atom");
274     }
275     return AtomAssigned(i);
276     }
277    
278     const bool
279     Instanc::isArray() const{
280     return getKind() & IARR;
281     //return IsArrayInstance(i);
282     }
283    
284     const bool
285     Instanc::isChildless() const{
286     return getKind() & ICHILDLESS;
287     //return IsChildlessInstance(i);
288     }
289    
290     const bool
291     Instanc::isBool() const{
292     switch(getKind()){
293     case BOOLEAN_INST:
294     case BOOLEAN_ATOM_INST:
295     case BOOLEAN_CONSTANT_INST:
296     return true;
297 johnpye 709 default:
298     return false;
299 johnpye 132 }
300     }
301    
302     const bool
303     Instanc::isInt() const{
304     switch(getKind()){
305     case INTEGER_INST:
306     case INTEGER_ATOM_INST:
307     case INTEGER_CONSTANT_INST:
308     return true;
309 johnpye 709 default:
310     return false;
311 johnpye 132 }
312     }
313    
314     const bool
315     Instanc::isReal() const{
316     switch(getKind()){
317     case REAL_INST:
318     case REAL_ATOM_INST:
319     case REAL_CONSTANT_INST:
320     return true;
321 johnpye 709 default:
322     return false;
323 johnpye 132 }
324     }
325    
326     const bool
327     Instanc::isSymbol() const{
328     switch(getKind()){
329     case SYMBOL_INST:
330     case SYMBOL_ATOM_INST:
331     case SYMBOL_CONSTANT_INST:
332     return true;
333 johnpye 709 default:
334     return false;
335 johnpye 132 }
336     }
337    
338     const bool
339     Instanc::isDefined() const{
340     if(!isAtom() && !isFund())throw runtime_error("Instanc::isDefined: not an atom/fund");
341     return AtomAssigned(i);
342     }
343    
344 johnpye 774 const bool
345     Instanc::isModel() const{
346     if(getKind()==MODEL_INST){
347     return true;
348     }
349     return false;
350     }
351    
352 johnpye 132 const double
353     Instanc::getRealValue() const{
354     // Check that the instance has a real value:
355     switch(getKind()){
356     case REAL_INST:
357     case REAL_CONSTANT_INST:
358     case REAL_ATOM_INST:
359     //cerr << "REAL VALUE FOR " << getName() << endl;
360     break;
361     default:
362 johnpye 190 ERROR_REPORTER_NOLINE(ASC_USER_ERROR,"Variable '%s' is not real-valued (%s)", \
363 johnpye 132 getName().toString(),getKindStr().c_str());
364     return 0;
365     }
366     if(!isConst() && !isDefined()){
367 johnpye 190 ERROR_REPORTER_NOLINE(ASC_USER_ERROR,"Variable '%s' is not defined (%s)", \
368 johnpye 132 getName().toString(),getKindStr().c_str());
369     return 0;
370     }
371 johnpye 190 return RealAtomValue(i);
372 johnpye 132 }
373    
374     const bool
375     Instanc::isDimensionless() const{
376     if(!isReal())return true;
377     return Dimensions( RealAtomDims(i) ).isDimensionless();
378     }
379    
380     const Dimensions
381     Instanc::getDimensions() const{
382     if(!isReal())throw runtime_error("Instanc::getDimensions: not a real-valued instance");
383     return Dimensions( RealAtomDims(i) );
384     }
385    
386     const bool
387     Instanc::getBoolValue() const{
388     // Check that the instance has a bool value:
389     switch(getKind()){
390     case BOOLEAN_INST:
391     case BOOLEAN_ATOM_INST:
392     case BOOLEAN_CONSTANT_INST:
393     //cerr << "BOOL VALUE FOR " << getName() << endl;
394     break;
395     default:
396 johnpye 190 ERROR_REPORTER_NOLINE(ASC_USER_ERROR,"Variable '%s' is not boolean-valued",getName().toString());
397 johnpye 132 return false;
398     }
399     if(!isConst() && !isDefined()){
400 johnpye 190 ERROR_REPORTER_NOLINE(ASC_USER_ERROR,"Variable '%s' is not defined",getName().toString());
401 johnpye 132 return false;
402     }
403     return GetBooleanAtomValue(i);
404     }
405    
406    
407     const long
408     Instanc::getIntValue() const{
409     // Check that the instance has a bool value:
410     switch(getKind()){
411     case INTEGER_INST:
412     case INTEGER_ATOM_INST:
413     case INTEGER_CONSTANT_INST:
414     //cerr << "INT VALUE FOR " << getName() << endl;
415     break;
416     default:
417 johnpye 190 ERROR_REPORTER_NOLINE(ASC_USER_ERROR,"Variable '%s' is not integer-valued",getName().toString());
418 johnpye 132 return 0;
419     }
420     if(!isConst() && !isDefined()){
421 johnpye 190 ERROR_REPORTER_NOLINE(ASC_USER_ERROR,"Variable '%s' is not defined",getName().toString());
422 johnpye 132 return 0;
423     }
424     return GetIntegerAtomValue(i);
425     }
426    
427     const SymChar
428     Instanc::getSymbolValue() const{
429     if(!isSymbol()){
430 johnpye 190 ERROR_REPORTER_NOLINE(ASC_USER_ERROR,"Variable '%s' is not symbol-valued",getName().toString());
431 johnpye 132 return SymChar("ERROR");
432     }
433     if(!isConst() && !isDefined()){
434 johnpye 190 ERROR_REPORTER_NOLINE(ASC_USER_ERROR,"Variable '%s' is not defined",getName().toString());
435 johnpye 132 return SymChar("UNDEFINED");
436     }
437     return SCP(GetSymbolAtomValue(i));
438     }
439    
440 johnpye 844 void
441     Instanc::setSymbolValue(const SymChar &sym){
442     stringstream ss;
443     if(!isSymbol()){
444     ss << "Variable '" << getName().toString() << "' is not symbol-valued.";
445     throw runtime_error(ss.str());
446     }
447     if(isConst() && isDefined()){
448     ss << "Variable '" << getName().toString() << "' has already been defined.";
449     throw runtime_error(ss.str());
450     }
451    
452     SetSymbolAtomValue(i,sym.getInternalType());
453     }
454    
455 johnpye 215 const string
456     Instanc::getRelationAsString(const Instanc &relative_to) const{
457     stringstream ss;
458     if(isRelation()){
459     int len;
460     char *str = WriteRelationString(i,relative_to.getInternalType()
461     ,NULL,NULL,relio_ascend,&len);
462     ss << str;
463     ascfree(str);
464     }else{
465     throw runtime_error("getRelationString: Instance is not a relation");
466     }
467     return ss.str();
468     }
469 johnpye 273
470     const double
471     Instanc::getResidual() const{
472     if(!isRelation()){
473     throw runtime_error("getResidual: not a relation");
474     }
475 johnpye 844 struct RelationInstance * const ri = (struct RelationInstance * const) i;
476 johnpye 1300 if(NULL == ri->ptr){
477     throw runtime_error("getResidual: ri->ptr is NULL");
478     }
479 johnpye 273 return RelationResidual( ri->ptr );
480     }
481 johnpye 569
482 jpye 1741 const bool
483     Instanc::getLogicalResidual() const{
484     if(!isLogicalRelation()){
485     throw runtime_error("getResidual: not a relation");
486     }
487    
488     return 0!=LogRelResidual(GetInstanceLogRelOnly(i));
489     }
490    
491    
492 johnpye 207 /**
493     Return the numerical value of an instance if it is an assigned atom.
494     If it is a relation, return the string form of the relation (ie the equation)
495     Else return the string 'undefined'.
496     */
497 johnpye 175 const string
498     Instanc::getValueAsString() const{
499     stringstream ss;
500 johnpye 207
501 johnpye 215 if(isAssigned()){
502 johnpye 175 if(isReal()){
503     ss << getRealValue();
504     }else if(isInt()){
505     ss << getIntValue();
506     }else if(isSymbol()){
507     ss << getSymbolValue();
508     }else if(isBool()){
509     ss << getBoolValue();
510     }else{
511     throw runtime_error("Invalid type in Instanc::getValueAsString");
512     }
513     }else{
514     ss << "undefined";
515     }
516     return ss.str();
517     }
518    
519 johnpye 190 const bool
520 johnpye 172 Instanc::isPlottable() const{
521     if(plot_allowed(i)){
522     return true;
523     }
524     return false;
525     }
526    
527 johnpye 190 const enum set_kind
528 johnpye 132 Instanc::getSetType() const{
529 jpye 1376 if(!isSet())throw runtime_error("Not a set");
530     if(!isConst() && !isDefined()){
531     stringstream ss;
532     ss << "Value of set '" << getName().toString() << "' is not defined";
533     throw runtime_error(ss.str());
534 johnpye 132 }
535 jpye 1376 if(SetAtomList(i)==NULL)return empty_set;
536 johnpye 132 return SetKind(SetAtomList(i));
537     }
538    
539     /// Get the child instances :)
540     vector<Instanc> &
541     Instanc::getChildren()
542     {
543     Type t = getType();
544    
545     children = vector<Instanc>();
546    
547     if(i==NULL)throw runtime_error("NULL 'i' in Instanc::getChildren");
548    
549     unsigned long len = NumberChildren(i);
550     if(!len)return children;
551     //cerr << "FOUND " << len << " CHILDREN" << endl;
552    
553     if(isArray()){
554     for(unsigned long ci=1; ci<=len; ++ci){
555     Instanc c(*this, ci);
556     if(!TypeShow(c.getType().getInternalType()))continue;
557 johnpye 1301 if(c.i==NULL)continue;
558 johnpye 132 children.push_back(c);
559     }
560     return children;
561     /* stringstream ss;
562     ss << "Instance '" << getName() << "' is an array, type '" << t.getName() << "'";
563 johnpye 190 ERROR_REPORTER_NOLINE(ASC_PROG_WARNING,ss.str().c_str()); */
564 johnpye 132 }
565    
566    
567     ChildListPtr clist = GetChildList(t.getInternalType());
568     if(!clist){
569     stringstream ss;
570     ss << "Child list of instance '" << getName() << "' of type '" << t.getName() << "' (" << getKindStr() << ") is NULL";
571     ss << " (isChildless=" << isChildless() << ")";
572 johnpye 190 ERROR_REPORTER_NOLINE(ASC_PROG_WARNING,ss.str().c_str());
573 johnpye 132 return children;
574     //throw runtime_error(ss.str());
575     }
576    
577     /// FIXME 1-based array:
578     for(unsigned long ci=1; ci<=len; ++ci){
579     if(!ChildVisible(clist,ci))continue;
580    
581     Instanc c( *this, ci );
582 johnpye 1301 if(c.i==NULL)continue;
583 johnpye 132 //cerr << "FOUND CHILD #" << ci << ": " << c.getName() << endl;
584    
585     children.push_back(c);
586     }
587     return children;
588     }
589    
590     Instanc
591     Instanc::getChild(const SymChar &name) const{
592     struct Instance *c = ChildByChar(i,name.getInternalType());
593 johnpye 876 stringstream ss;
594     if(c==NULL){
595     ss << "Child '" << name << "' not found in " << getName();
596     throw runtime_error(ss.str());
597     }
598     return Instanc(c,name);
599 johnpye 132 }
600    
601 johnpye 952 Instanc
602     Instanc::getChild(const long &index) const{
603     if(!isArray()){
604     stringstream ss;
605     ss << "Instance '" << getName() << "' is not an array; can't retrieve child index " << index;
606     throw runtime_error(ss.str());
607     }
608     struct InstanceName n;
609     InstanceNameType(n) = IntArrayIndex;
610     InstanceIntIndex(n) = index;
611     long childindex = ChildSearch(i,&n);
612     if(childindex){
613 johnpye 1198 return Instanc(InstanceChild(i,childindex));
614 johnpye 952 }
615     stringstream ss;
616     ss << "Invalid child index '" << index << "' for instance '" << getName() << "'";
617     throw runtime_error(ss.str());
618    
619     }
620    
621 johnpye 176 Plot
622     Instanc::getPlot() const{
623     if(isPlottable()){
624     return Plot(*this);
625     }
626     throw runtime_error("Not a plottable instance");
627     }
628    
629 johnpye 132 void
630 jpye 1350 Instanc::write(FILE *fp) const{
631     if(!fp)throw runtime_error("NULL file pointer");
632 jpye 1347 WriteInstance(fp,i);
633 johnpye 132 }
634    
635     //----------------------------
636     // SETTING VALUES of stuff
637    
638     void
639     Instanc::setFixed(const bool &val){
640     if(isFixed()==val)return;
641 jpye 1355 //CONSOLE_DEBUG("Fixing solver_var at %p",i);
642 johnpye 132 getChild("fixed").setBoolValue(val);
643     }
644    
645     void
646 jpye 1360 Instanc::setIncluded(const bool &val){
647     if(isIncluded()==val)return;
648     getChild("included").setBoolValue(val);
649     }
650    
651     void
652 johnpye 132 Instanc::setBoolValue(const bool &val, const unsigned &depth){
653     SetBooleanAtomValue(i, val, depth);
654     }
655    
656     void
657 jpye 1960 Instanc::setIntValue(const long &val, const unsigned &depth){
658     SetIntegerAtomValue(i, val, depth);
659     }
660    
661     void
662 johnpye 132 Instanc::setRealValue(const double &val, const unsigned &depth){
663     SetRealAtomValue(i,val, depth);
664 johnpye 190 //ERROR_REPORTER_HERE(ASC_USER_NOTE,"Set %s to %f",getName().toString(),val);
665 johnpye 132 }
666    
667     /**
668 johnpye 569 Borrow the workings of this from tcltk UnitsProc.c
669 johnpye 132 */
670     void
671     Instanc::setRealValueWithUnits(double val, const char *units, const unsigned &depth){
672    
673     if(isConst()){
674 johnpye 190 ERROR_REPORTER_NOLINE(ASC_USER_ERROR,"Can't change the value of a constant");
675 johnpye 132 return;
676     }
677    
678     if(!isReal() || !isAtom()){
679     throw runtime_error("Instanc::setRealValueWithUnits: not a real-valued instance");
680     }
681    
682     if(units == NULL || strlen(units)==0 || strcmp(units,"*")==0){
683     // No units were specified, so the base (SI) units are implied.
684     }else{
685     // We need to parse the units string
686     UnitsM u = UnitsM(units);
687     Dimensions d = u.getDimensions();
688 johnpye 190
689 johnpye 132 // If no dimensions yet assigned, assign them. Otheriwse check for consistency.
690     if(getDimensions().isWild()){
691     // Set the dimensions for a wildcard atom:
692     SetRealAtomDims(i, d.getInternalType());
693     }else if(d != getDimensions()){
694     throw runtime_error("Dimensionally incompatible units");
695     }
696 johnpye 190
697 johnpye 132 // Not going to worry about FPEs here, let the program crash if it must.
698     val = val * u.getConversion();
699     }
700    
701     SetRealAtomValue(i,val,depth);
702     }
703    
704 johnpye 255 /**
705 jpye 1362 Set the instance variable status. See @getInstanceStatus
706 johnpye 255 */
707 johnpye 569 void
708 jpye 1362 Instanc::setStatus(const InstanceStatus &s){
709 johnpye 255 InstanceInterfaceData *d;
710     d = (InstanceInterfaceData *)GetInterfacePtr(i);
711 jpye 1362 if(d==NULL && s!=ASCXX_INST_STATUS_UNKNOWN){
712 johnpye 255 d = new InstanceInterfaceData();
713     SetInterfacePtr(i,d);
714     }
715 jpye 1335 if(d!=NULL){
716     d->status = s;
717     }
718 johnpye 255 }
719    
720 johnpye 569 /**
721 johnpye 255 Return the instance variable status.
722     This data is stored in the 'interface_ptr' of the instance, so
723 johnpye 569 that we can be sure we'll get it, regardless of which
724 johnpye 255 instance of an Instanc we have in our hands :-)
725     */
726 jpye 1362 const InstanceStatus
727     Instanc::getStatus() const{
728 johnpye 255 InstanceInterfaceData *d;
729     d = (InstanceInterfaceData *)GetInterfacePtr(i);
730     if(d==NULL){
731 jpye 1362 return ASCXX_INST_STATUS_UNKNOWN;
732 johnpye 255 }
733 johnpye 268 return d->status;
734 johnpye 255 }
735    
736 johnpye 268
737    
738     /*------------------------------------------------------
739     Macros to declare
740     setUpperBound
741     setLowerBound
742     setNominal
743     and their 'get' equivalents
744     */
745    
746     #define DEFINE_GET_REAL_CHILD(METHOD,CHILD) \
747     const double \
748     Instanc::get##METHOD() const{ \
749     Instanc c = getChild(CHILD); \
750     return c.getRealValue(); \
751     }
752    
753     #define DEFINE_SET_REAL_CHILD(METHOD,CHILD) \
754     void \
755     Instanc::set##METHOD(const double &v){ \
756     Instanc c = getChild(CHILD); \
757     c.setRealValue(v); \
758     }
759    
760     #define DEFINE_CHILD_METHODS(D) \
761     D(LowerBound,"lower_bound") \
762     D(UpperBound,"upper_bound") \
763     D(Nominal,"nominal")
764    
765     DEFINE_CHILD_METHODS(DEFINE_SET_REAL_CHILD)
766     DEFINE_CHILD_METHODS(DEFINE_GET_REAL_CHILD)
767    
768     //------------------------------------------------------
769    
770 johnpye 732 const vector<Instanc>
771 johnpye 271 Instanc::getClique() const{
772 johnpye 732 vector<Instanc> v;
773 johnpye 271 struct Instance *i1 = i;
774     do{
775 johnpye 732 v.push_back(Instanc(i1));
776 johnpye 271 i1=NextCliqueMember(i1);
777 johnpye 732 }while(i1 != i); // ie we've gone around the circuit
778     return v;
779 johnpye 271 }
780    
781     //------------------------------------------------------
782 johnpye 132 // static properties
783     SymChar
784     Instanc::fixedsym = SymChar("fixed");
785    
786     SymChar
787     Instanc::solvervarsym = SymChar("solver_var");

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