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

Contents of /trunk/pygtk/simulation.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 775 - (show annotations) (download) (as text)
Sat Jul 15 07:18:54 2006 UTC (14 years, 2 months ago) by johnpye
File MIME type: text/x-c++src
File size: 20928 byte(s)
Tidied up headers in slvDOF.h
Added 'show freeable vars' to GUI.
Fixed up the 'check' function a bit. It was doing strange things.
1 /* ASCEND modelling environment
2 Copyright (C) 2006 Carnegie Mellon University
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA.
18 */
19 #include <iostream>
20 #include <iomanip>
21 #include <stdexcept>
22 #include <sstream>
23 using namespace std;
24
25 #include "config.h"
26
27 extern "C"{
28 #include <utilities/ascConfig.h>
29 #include <utilities/error.h>
30 #include <utilities/ascSignal.h>
31 #include <utilities/ascMalloc.h>
32 #include <general/dstring.h>
33 #include <general/tm_time.h>
34 #include <compiler/instance_enum.h>
35 #include <compiler/fractions.h>
36 #include <compiler/compiler.h>
37 #include <compiler/dimen.h>
38 #include <compiler/symtab.h>
39 #include <compiler/instance_io.h>
40 #include <compiler/instantiate.h>
41 #include <compiler/bintoken.h>
42 #include <compiler/instance_enum.h>
43 #include <compiler/instquery.h>
44 #include <compiler/check.h>
45 #include <compiler/name.h>
46 #include <compiler/pending.h>
47
48 #include <utilities/readln.h>
49 #include <solver/mtx.h>
50 #include <solver/slv_types.h>
51 #include <solver/var.h>
52 #include <solver/rel.h>
53 #include <solver/discrete.h>
54 #include <solver/conditional.h>
55 #include <solver/logrel.h>
56 #include <solver/bnd.h>
57 #include <solver/calc.h>
58 #include <solver/relman.h>
59 #include <solver/slv_common.h>
60 #include <solver/linsol.h>
61 #include <solver/linsolqr.h>
62 #include <solver/slv_client.h>
63 #include <solver/system.h>
64 #include <solver/slv_interface.h>
65 #include <solver/slvDOF.h>
66 #include <solver/slv3.h>
67 #include <solver/slv_stdcalls.h>
68 #include <solver/slv_server.h>
69 }
70
71 #include "simulation.h"
72 #include "solver.h"
73 #include "solverparameters.h"
74 #include "name.h"
75 #include "incidencematrix.h"
76 #include "variable.h"
77 #include "solverstatus.h"
78 #include "solverreporter.h"
79
80 /**
81 Create an instance of a type (call compiler etc)
82
83 @TODO fix mutex on compile command filenames
84 */
85 Simulation::Simulation(Instance *i, const SymChar &name) : Instanc(i, name), simroot(GetSimulationRoot(i),SymChar("simroot")){
86 is_built = false;
87 // Create an Instance object for the 'simulation root' (we'll call
88 // it the 'simulation model') and it can be fetched using 'getModel()'
89 // any time later.
90 //simroot = Instanc(GetSimulationRoot(i),name);
91 }
92
93 Simulation::Simulation(const Simulation &old) : Instanc(old), simroot(old.simroot){
94 is_built = old.is_built;
95 sys = old.sys;
96 bin_srcname = old.bin_srcname;
97 bin_objname = old.bin_objname;
98 bin_libname = old.bin_libname;
99 bin_cmd = old.bin_cmd;
100 bin_rm = old.bin_rm;
101 sing = NULL;
102 }
103
104 Simulation::~Simulation(){
105 //CONSOLE_DEBUG("Deleting simulation %s", getName().toString());
106 }
107
108 Instanc &
109 Simulation::getModel(){
110 if(!simroot.getInternalType()){
111 throw runtime_error("Simulation::getModel: simroot.getInternalType()is NULL");
112 }
113 return simroot;
114 }
115
116
117 slv_system_structure *
118 Simulation::getSystem(){
119 if(!sys)throw runtime_error("Can't getSystem: simulation not yet built");
120 return sys;
121 }
122
123
124 const string
125 Simulation::getInstanceName(const Instanc &i) const{
126 char *n;
127 n = WriteInstanceNameString(i.getInternalType(),simroot.getInternalType());
128 string s(n);
129 ascfree(n);
130 return s;
131 }
132
133 const int
134 Simulation::getNumVars(){
135 return slv_get_num_solvers_vars(getSystem());
136 }
137
138
139 void
140 Simulation::write(){
141 simroot.write();
142 }
143
144 //------------------------------------------------------------------------------
145 // RUNNING MODEL 'METHODS'
146
147 void
148 Simulation::run(const Method &method){
149 Instanc &model = getModel();
150 this->run(method,model);
151 }
152
153 void
154 Simulation::run(const Method &method, Instanc &model){
155
156 cerr << "RUNNING PROCEDURE " << method.getName() << endl;
157 Nam name = Nam(method.getSym());
158 //cerr << "CREATED NAME '" << name.getName() << "'" << endl;
159 Proc_enum pe;
160 pe = Initialize(
161 &*(model.getInternalType()) ,name.getInternalType(), "__not_named__"
162 ,ASCERR
163 ,0, NULL, NULL
164 );
165
166 if(pe == Proc_all_ok){
167 ERROR_REPORTER_NOLINE(ASC_PROG_NOTE,"Method '%s' was run (check above for errors)\n",method.getName());
168 //cerr << "METHOD " << method.getName() << " COMPLETED OK" << endl;
169 }else{
170 stringstream ss;
171 ss << "Simulation::run: Method '" << method.getName() << "' returned error: ";
172 switch(pe){
173 case Proc_CallOK: ss << "Call OK"; break;
174 case Proc_CallError: ss << "Error occurred in call"; break;
175 case Proc_CallReturn: ss << "Request that caller return (OK)"; break;
176 case Proc_CallBreak: ss << "Break out of enclosing loop"; break;
177 case Proc_CallContinue: ss << "Skip to next iteration"; break;
178
179 case Proc_break: ss << "Break"; break;
180 case Proc_continue: ss << "Continue"; break;
181 case Proc_fallthru: ss << "Fall-through"; break;
182 case Proc_return: ss << "Return"; break;
183 case Proc_stop: ss << "Stop"; break;
184 case Proc_stack_exceeded: ss << "Stack exceeded"; break;
185 case Proc_stack_exceeded_this_frame: ss << "Stack exceeded this frame"; break;
186 case Proc_case_matched: ss << "Case matched"; break;
187 case Proc_case_unmatched: ss << "Case unmatched"; break;
188
189 case Proc_case_undefined_value: ss << "Undefined value in case"; break;
190 case Proc_case_boolean_mismatch: ss << "Boolean mismatch in case"; break;
191 case Proc_case_integer_mismatch: ss << "Integer mismatch in case"; break;
192 case Proc_case_symbol_mismatch: ss << "Symbol mismatch in case"; break;
193 case Proc_case_wrong_index: ss << "Wrong index in case"; break;
194 case Proc_case_wrong_value: ss << "Wrong value in case"; break;
195 case Proc_case_extra_values: ss << "Extra values in case"; break;
196 case Proc_bad_statement: ss << "Bad statement"; break;
197 case Proc_bad_name: ss << "Bad name"; break;
198 case Proc_for_duplicate_index: ss << "Duplicate index"; break;
199 case Proc_for_set_err: ss << "For set error"; break;
200 case Proc_for_not_set: ss << "For not set"; break;
201 case Proc_illegal_name_use: ss << "Illegal name use"; break;
202 case Proc_name_not_found: ss << "Name not found"; break;
203 case Proc_instance_not_found: ss << "Instance not found"; break;
204 case Proc_type_not_found: ss << "Type not found"; break;
205 case Proc_illegal_type_use: ss << "Illegal use"; break;
206 case Proc_proc_not_found: ss << "Method not found"; break;
207 case Proc_if_expr_error_typeconflict: ss << "Type conflict in 'if' expression"; break;
208 case Proc_if_expr_error_nameunfound: ss << "Name not found in 'if' expression"; break;
209 case Proc_if_expr_error_incorrectname: ss << "Incorrect name in 'if' expression"; break;
210 case Proc_if_expr_error_undefinedvalue: ss << "Undefined value in 'if' expression"; break;
211 case Proc_if_expr_error_dimensionconflict: ss << "Dimension conflict in 'if' expression"; break;
212 case Proc_if_expr_error_emptychoice: ss << "Empty choice in 'if' expression"; break;
213 case Proc_if_expr_error_emptyintersection: ss << "Empty intersection in 'if' expression"; break;
214 case Proc_if_expr_error_confused: ss << "Confused in 'if' expression"; break;
215 case Proc_if_real_expr: ss << "Real-valued result in 'if' expression"; break;
216 case Proc_if_integer_expr: ss << "Integeter-valued result in 'if' expression"; break;
217 case Proc_if_symbol_expr: ss << "Symbol-valued result in 'if' expression"; break;
218 case Proc_if_set_expr: ss << "Set-valued result in 'if' expression"; break;
219 case Proc_if_not_logical: ss << "If expression is not logical"; break;
220 case Proc_user_interrupt: ss << "User interrupt"; break;
221 case Proc_infinite_loop: ss << "Infinite loop"; break;
222 case Proc_declarative_constant_assignment: ss << "Declarative constant assignment"; break;
223 case Proc_nonsense_assignment: ss << "Nonsense assginment (bogus)"; break;
224 case Proc_nonconsistent_assignment: ss << "Inconsistent assignment"; break;
225 case Proc_nonatom_assignment: ss << "Non-atom assignment"; break;
226 case Proc_nonboolean_assignment: ss << "Non-boolean assignment"; break;
227 case Proc_noninteger_assignment: ss << "Non-integer assignment"; break;
228 case Proc_nonreal_assignment: ss << "Non-real assignment"; break;
229 case Proc_nonsymbol_assignment: ss << "Non-symbol assignment"; break;
230 case Proc_lhs_error: ss << "Left-hand-side error"; break;
231 case Proc_rhs_error: ss << "Right-hand-side error"; break;
232 case Proc_unknown_error: ss << "Unknown error"; break;
233 default:
234 ss << "Invalid error code";
235 }
236
237 ss << " (" << int(pe) << ")";
238 throw runtime_error(ss.str());
239 }
240 }
241
242 //-----------------------------------------------------------------------------
243 // CHECKING METHODS
244
245 /**
246 Check that all the analysis went OK: solver lists are all there, etc...?
247
248 Can't return anything here because of limitations in the C API
249 */
250 void
251 Simulation::checkInstance(){
252 cerr << "CHECKING SIMULATION INSTANCE" << endl;
253 Instance *i1 = getModel().getInternalType();
254 CheckInstance(stderr, &*i1);
255 cerr << "DONE CHECKING INSTANCE" << endl;
256 }
257
258 /**
259 @return 1 = underspecified, 2 = square, 3 = structurally singular, 4 = overspecified
260 */
261 enum StructuralStatus
262 Simulation::checkDoF() const{
263 cerr << "CHECKING DOF..." << endl;
264 int dof, status;
265 if(!sys){
266 throw runtime_error("System not yet built");
267 }
268 slvDOF_status(sys, &status, &dof);
269 switch(status){
270 case ASCXX_DOF_UNDERSPECIFIED:
271 case ASCXX_DOF_SQUARE:
272 case ASCXX_DOF_OVERSPECIFIED:
273 case ASCXX_DOF_STRUCT_SINGULAR:
274 return (enum StructuralStatus)status;
275 case 5:
276 throw runtime_error("Unable to resolve degrees of freedom"); break;
277 default:
278 throw runtime_error("Invalid return status from slvDOF_status");
279 }
280 }
281
282 /**
283 Check consistency
284
285 @TODO what is the difference between this and checkStructuralSingularity?
286
287 @return list of freeable variables. List will be empty if sys is consistent.
288 */
289 vector<Variable>
290 Simulation::getFreeableVariables(){
291 vector<Variable> v;
292
293 cerr << "CHECKING CONSISTENCY..." << endl;
294 int *fixedarrayptr;
295
296 int res = consistency_analysis(sys, &fixedarrayptr);
297 struct var_variable **vp = slv_get_master_var_list(sys);
298
299 if(res==1){
300 cerr << "STRUCTURALLY CONSISTENT" << endl;
301 }else{
302 for(int i=0; fixedarrayptr[i]!=-1; ++i){
303 v.push_back( Variable(this, vp[fixedarrayptr[i]]) );
304 }
305 }
306 return v;
307 }
308
309 /** Returns TRUE if all is OK (not singular) */
310 bool
311 Simulation::checkStructuralSingularity(){
312 int *vil;
313 int *ril;
314 int *fil;
315
316 cerr << "RETREIVING slfDOF_structsing INFO" << endl;
317
318 int res = slvDOF_structsing(sys, mtx_FIRST, &vil, &ril, &fil);
319 struct var_variable **varlist = slv_get_solvers_var_list(sys);
320 struct rel_relation **rellist = slv_get_solvers_rel_list(sys);
321
322 if(this->sing){
323 cerr << "DELETING OLD SINGULATING INFO" << endl;
324 delete this->sing;
325 this->sing = NULL;
326 }
327
328 if(res==1){
329 CONSOLE_DEBUG("processing singularity data...");
330 sing = new SingularityInfo();
331
332 // pull in the lists of vars and rels, and the freeable vars:
333 for(int i=0; ril[i]!=-1; ++i){
334 sing->rels.push_back( Relation(this, rellist[ril[i]]) );
335 }
336
337 for(int i=0; vil[i]!=-1; ++i){
338 sing->vars.push_back( Variable(this, varlist[vil[i]]) );
339 }
340
341 for(int i=0; fil[i]!=-1; ++i){
342 sing->freeablevars.push_back( Variable(this, varlist[fil[i]]) );
343 }
344
345 // we're done with those lists now
346 ASC_FREE(vil);
347 ASC_FREE(ril);
348 ASC_FREE(fil);
349
350 if(sing->isSingular()){
351 CONSOLE_DEBUG("singularity found");
352 this->sing = sing;
353 return FALSE;
354 }
355 CONSOLE_DEBUG("no singularity");
356 delete sing;
357 return TRUE;
358 }else{
359 if(res==0){
360 throw runtime_error("Unable to determine singularity lists");
361 }else{
362 throw runtime_error("Invalid return from slvDOF_structsing.");
363 }
364 }
365 }
366
367 /**
368 If the checkStructuralSingularity analysis has been done,
369 this funciton will let you access the SingularityInfo data that was
370 stored.
371 */
372 const SingularityInfo &
373 Simulation::getSingularityInfo() const{
374 if(sing==NULL){
375 throw runtime_error("No singularity info present");
376 }
377 return *sing;
378 }
379
380 //------------------------------------------
381 // ASSIGNING SOLVER TO SIMULATION
382
383 void
384 Simulation::setSolver(Solver &solver){
385 cerr << "SETTING SOLVER ON SIMULATION TO " << solver.getName() << endl;
386
387 if(!sys)throw runtime_error("Can't solve: Simulation system has not been built yet.");
388 // Update the solver object because sometimes an alternative solver can be returned, apparently.
389
390 int selected = slv_select_solver(sys, solver.getIndex());
391 //cerr << "Simulation::setSolver: slv_select_solver returned " << selected << endl;
392
393 if(selected<0){
394 ERROR_REPORTER_NOLINE(ASC_PROG_ERROR,"Failed to select solver");
395 throw runtime_error("Failed to select solver");
396 }
397
398 if(selected!=solver.getIndex()){
399 solver = Solver(slv_solver_name(selected));
400 ERROR_REPORTER_NOLINE(ASC_PROG_NOTE,"Substitute solver '%s' (index %d) selected.\n", solver.getName().c_str(), selected);
401 }
402
403 if( slv_eligible_solver(sys) <= 0){
404 ERROR_REPORTER_NOLINE(ASC_PROG_ERROR,"Inelegible solver '%s'", solver.getName().c_str() );
405 throw runtime_error("Inelegible solver");
406 }
407 }
408
409 const Solver
410 Simulation::getSolver() const{
411 int index = slv_get_selected_solver(sys);
412 //cerr << "Simulation::getSolver: index = " << index << endl;
413 if(index<0)throw runtime_error("No solver selected");
414
415 return Solver(slv_solver_name(index));
416 }
417
418 //------------------------------------------------------------------------------
419 // BUILD THE SYSTEM (SEND IT TO THE SOLVER)
420
421 /**
422 Build the system (send it to the solver)
423 */
424 void
425 Simulation::build(){
426 cerr << "BUILDING SIMULATION..." << endl;
427 Instance *i1 = getModel().getInternalType();
428 sys = system_build(&*i1);
429 if(!sys){
430 throw runtime_error("Unable to build system");
431 }
432 is_built = true;
433 cerr << "...DONE BUILDING" << endl;
434 }
435
436
437 //------------------------------------------------------------------------------
438 // SOLVER CONFIGURATION PARAMETERS
439
440 /**
441 Get solver parameters struct wrapped up as a SolverParameters class.
442 */
443 SolverParameters
444 Simulation::getSolverParameters() const{
445 if(!sys)throw runtime_error("Can't getSolverParameters: Simulation system has not been built yet.");
446
447 slv_parameters_t p;
448 slv_get_parameters(sys,&p);
449 return SolverParameters(p);
450 }
451
452 /**
453 Update the solver parameters by passing a new set back
454 */
455 void
456 Simulation::setSolverParameters(SolverParameters &P){
457 if(!sys)throw runtime_error("Can't set solver parameters: simulation has not been built yet.");
458 slv_set_parameters(sys, &(P.getInternalType()));
459 }
460
461 //------------------------------------------------------------------------------
462 // PRE-SOLVE DIAGNOSTICS
463
464 /**
465 Get a list of variables to fix to make an underspecified system
466 become square. Also seems to return stuff when you have a structurally
467 singuler system.
468 */
469 vector<Variable>
470 Simulation::getFixableVariables(){
471 cerr << "GETTING FIXABLE VARIABLES..." << endl;
472 vector<Variable> vars;
473
474 if(!sys){
475 throw runtime_error("Simulation system not yet built");
476 }
477
478 int32 *vip; /** TODO ensure 32 bit integers are used */
479
480 // Get IDs of elegible variables in array at vip...
481 if(!slvDOF_eligible(sys,&vip)){
482 ERROR_REPORTER_NOLINE(ASC_USER_NOTE,"No fixable variables found.");
483 }else{
484 struct var_variable **vp = slv_get_solvers_var_list(sys);
485
486 if(vp==NULL){
487 throw runtime_error("Simulation variable list is null");
488 }
489
490 // iterate through this list until we find a -1:
491 int i=0;
492 int var_index = vip[i];
493 while(var_index >= 0){
494 struct var_variable *var = vp[var_index];
495 vars.push_back( Variable(this, var) );
496 ++i;
497 var_index = vip[i];
498 }
499 ERROR_REPORTER_NOLINE(ASC_USER_NOTE,"Found %d fixable variables.",i);
500 ascfree(vip);
501 }
502
503 return vars;
504 }
505
506 /**
507 Get the list of variables near their bounds. Helps to indentify why
508 you might be having non-convergence problems.
509 */
510 vector<Variable>
511 Simulation::getVariablesNearBounds(const double &epsilon){
512 cerr << "GETTING VARIABLES NEAR BOUNDS..." << endl;
513 vector<Variable> vars;
514
515 if(!sys){
516 throw runtime_error("Simulation system not yet built");
517 }
518
519 int *vip;
520 if(slv_near_bounds(sys,epsilon,&vip)){
521 struct var_variable **vp = slv_get_solvers_var_list(sys);
522 struct var_variable *var;
523 cerr << "VARS FOUND NEAR BOUNDS" << endl;
524 int nlow = vip[0];
525 int nhigh = vip[1];
526 int lim1 = 2 + nlow;
527 for(int i=2; i<lim1; ++i){
528 var = vp[vip[i]];
529 char *var_name = var_make_name(sys,var);
530 cerr << "AT LOWER BOUND: " << var_name << endl;
531 ascfree(var_name);
532 vars.push_back(Variable(this,var));
533 };
534 int lim2 = lim1 + nhigh;
535 for(int i=lim1; i<lim2; ++i){
536 var = vp[vip[i]];
537 char *var_name = var_make_name(sys,var);
538 cerr << "AT UPPER BOUND: " << var_name << endl;
539 ascfree(var_name);
540 vars.push_back(Variable(this,var));
541 }
542 }
543 ascfree(vip);
544 return vars;
545 }
546
547
548 bool
549 SingularityInfo::isSingular() const{
550 if(vars.size()||rels.size()){
551 return true;
552 }
553 return false;
554 }
555
556 //------------------------------------------------------------------------------
557 // SOLVING
558
559 /**
560 Solve the system through to convergence. This function is hardwired with
561 a maximum of 1000 iterations, but will interrupt itself when the 'stop'
562 condition comes back from the SolverReporter.
563 */
564 void
565 Simulation::solve(Solver solver, SolverReporter &reporter){
566 if(!is_built){
567 throw runtime_error("Simulation::solver: simulation is not yet built, can't start solving.");
568 }
569
570 cerr << "SIMULATION::SOLVE STARTING..." << endl;
571 enum inst_t k = getModel().getKind();
572 if(k!=MODEL_INST)throw runtime_error("Can't solve: not an instance of type MODEL_INST");
573
574 Instance *i1 = getInternalType();
575 int npend = NumberPendingInstances(&*i1);
576 if(npend)throw runtime_error("Can't solve: There are still %d pending instances");
577
578 if(!sys)throw runtime_error("Can't solve: Simulation system has not been built yet.");
579
580 cerr << "SIMULATION::SOLVE: SET SOLVER..." << endl;
581 setSolver(solver);
582
583
584 cerr << "PRESOLVING SYSTEM...";
585 slv_presolve(sys);
586 cerr << "DONE" << endl;
587
588 cerr << "SOLVING SYSTEM..." << endl;
589 // Add some stuff here for cleverer iteration....
590 unsigned niter = 1000;
591 //double updateinterval = 0.02;
592
593 double starttime = tm_cpu_time();
594 //double lastupdate = starttime;
595 SolverStatus status;
596 //int solved_vars=0;
597 bool stop=false;
598
599 status.getSimulationStatus(*this);
600 reporter.report(&status);
601
602 for(unsigned iter = 1; iter <= niter && !stop; ++iter){
603
604 if(status.isReadyToSolve()){
605 slv_iterate(sys);
606 }
607
608 status.getSimulationStatus(*this);
609
610 if(reporter.report(&status)){
611 stop = true;
612 }
613 }
614
615 double elapsed = tm_cpu_time() - starttime;
616
617
618 activeblock = status.getCurrentBlockNum();
619
620 reporter.finalise(&status);
621
622 // Just a little bit of console output:
623
624 if(status.isOK()){
625 cerr << "... SOLVED, STATUS OK" << endl;
626 }else{
627 cerr << "... SOLVER FAILED" << endl;
628 }
629
630 cerr << "SOLVER PERFORMED " << status.getIterationNum() << " ITERATIONS IN " << elapsed << "s" << endl;
631 }
632
633 //------------------------------------------------------------------------------
634 // POST-SOLVE DIAGNOSTICS
635
636 const int
637 Simulation::getActiveBlock() const{
638 return activeblock;
639 }
640
641 /**
642 Return an IncidenceMatrix built from the current state of the solver system.
643
644 This will actually return something meaningful even before solve.
645 */
646 IncidenceMatrix
647 Simulation::getIncidenceMatrix(){
648 return IncidenceMatrix(*this);
649 }
650
651 /**
652 This function looks at all the variables in the solve's list and updates
653 the variable status for the corresponding instances.
654
655 It does this by using the 'interface pointer' in the Instance, see
656 the C-API function GetInterfacePtr.
657
658 This is used to display visually which variables have been solved, which
659 ones have not yet been attempted, and which ones were active when the solver
660 failed (ASCXX_VAR_ACTIVE).
661 */
662 void
663 Simulation::processVarStatus(){
664
665 // this is a cheap function call:
666 const mtx_block_t *bb = slv_get_solvers_blocks(getSystem());
667
668 var_variable **vlist = slv_get_solvers_var_list(getSystem());
669 int nvars = slv_get_num_solvers_vars(getSystem());
670
671 slv_status_t status;
672 slv_get_status(getSystem(), &status);
673
674 if(status.block.number_of == 0){
675 cerr << "Variable statuses can't be set: block structure not yet determined." << endl;
676 return;
677 }
678
679 int activeblock = status.block.current_block;
680 int low = bb->block[activeblock].col.low;
681 int high = bb->block[activeblock].col.high;
682 bool allsolved = status.converged;
683 for(int c=0; c < nvars; ++c){
684 var_variable *v = vlist[c];
685 Instanc i((Instance *)var_instance(v));
686 VarStatus s = ASCXX_VAR_STATUS_UNKNOWN;
687 if(i.isFixed()){
688 s = ASCXX_VAR_FIXED;
689 }else if(var_incident(v) && var_active(v)){
690 if(allsolved || c < low){
691 s = ASCXX_VAR_SOLVED;
692 }else if(c <= high){
693 s = ASCXX_VAR_ACTIVE;
694 }else{
695 s = ASCXX_VAR_UNSOLVED;
696 }
697 }
698 i.setVarStatus(s);
699 }
700 }
701

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