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

Diff of /trunk/pygtk/simulation.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 190 by johnpye, Mon Jan 16 08:53:30 2006 UTC revision 196 by johnpye, Tue Jan 17 15:58:23 2006 UTC
# Line 9  extern "C"{ Line 9  extern "C"{
9  #include <utilities/ascSignal.h>  #include <utilities/ascSignal.h>
10  #include <utilities/ascMalloc.h>  #include <utilities/ascMalloc.h>
11  #include <general/dstring.h>  #include <general/dstring.h>
12    #include <general/tm_time.h>
13  #include <compiler/instance_enum.h>  #include <compiler/instance_enum.h>
14  #include <compiler/fractions.h>  #include <compiler/fractions.h>
15  #include <compiler/compiler.h>  #include <compiler/compiler.h>
# Line 265  Simulation::getFixableVariables(){ Line 266  Simulation::getFixableVariables(){
266      return vars;      return vars;
267  }  }
268    
269        
270  void  void
271  Simulation::solve(Solver solver){  Simulation::solve(Solver solver){
272      if(!is_built){      if(!is_built){
# Line 290  Simulation::solve(Solver solver){ Line 292  Simulation::solve(Solver solver){
292      cerr << "... DONE PRESOLVING" << endl;      cerr << "... DONE PRESOLVING" << endl;
293    
294      cerr << "SOLVING SYSTEM..." << endl;      cerr << "SOLVING SYSTEM..." << endl;
295      slv_solve(sys);      // Add some stuff here for cleverer iteration....
296        unsigned niter = 300;
297        double updateinterval = 0.02;
298    
299        double starttime = tm_cpu_time();
300        double lastupdate = starttime;
301        slv_status_t status;
302        int solved_vars=0;
303        bool stop=false;
304    
305        for(int iter = 0; iter < niter && !stop; ++iter){
306            slv_get_status(sys,&status);
307            if(status.ready_to_solve){
308                slv_iterate(sys);
309            }
310            if(tm_cpu_time() - lastupdate > updateinterval && iter > 0){
311                if(solved_vars < status.block.previous_total_size){
312                    solved_vars = status.block.previous_total_size;
313                    CONSOLE_DEBUG("Solved %5d vars. Now block %3d/%-3d...", solved_vars, status.block.current_block, status.block.number_of);
314                }else{
315                    CONSOLE_DEBUG("Total %5d iterations (%5d in current block of %d vars)", iter, status.block.iteration, status.block.current_size);
316                }
317                lastupdate = tm_cpu_time();
318            }
319        }
320    
321      slv_status_t slvstat;      if(status.ok){
     slv_get_status(sys,&slvstat);  
     if(slvstat.ok){  
322          cerr << "... DONE SOLVING SYSTEM" << endl;          cerr << "... DONE SOLVING SYSTEM" << endl;
323      }else{      }else{
324          ERROR_REPORTER_NOLINE(ASC_USER_ERROR,"Solver failed");          ERROR_REPORTER_NOLINE(ASC_USER_ERROR,"Solver failed");
325      }      }
326    
327      cerr << "SOLVER PERFORMED " << slvstat.iteration << " ITERATIONS IN " << slvstat.cpu_elapsed << "s" << endl;      cerr << "SOLVER PERFORMED " << status.iteration << " ITERATIONS IN " << (tm_cpu_time() - starttime) << "s" << endl;
328    
329      if(slvstat.iteration_limit_exceeded){      if(status.iteration_limit_exceeded){
330          ERROR_REPORTER_NOLINE(ASC_USER_ERROR,"Exceeded interation limit");          ERROR_REPORTER_NOLINE(ASC_USER_ERROR,"Exceeded interation limit");
331      }      }
332    
333      if(slvstat.converged){      if(status.converged){
334          ERROR_REPORTER_NOLINE(ASC_USER_SUCCESS,"Solver converged: %d iterations, %3.2e s"          ERROR_REPORTER_NOLINE(ASC_USER_SUCCESS,"Solver converged: %d iterations, %3.2e s"
335              ,slvstat.iteration,slvstat.cpu_elapsed);              ,status.iteration,status.cpu_elapsed);
336      }else{      }else{
337          ERROR_REPORTER_NOLINE(ASC_USER_ERROR,"Solver not converged after %d iteratoins.",slvstat.iteration);          ERROR_REPORTER_NOLINE(ASC_USER_ERROR,"Solver not converged after %d iterations.",status.iteration);
338      }      }
339    
   
     //slv_print_output(stderr,solver);  
   
     /*  
     if(s==NULL){  
         throw runtime_error("System not yet built");  
     }  
     cerr << "PRESOLVING SYSTEM..." << endl;  
     slv_presolve(s);  
     cerr << "... DONE PRESOLVING" << endl;  
     */  
340  }  }
341    
342  void  void

Legend:
Removed from v.190  
changed lines
  Added in v.196

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