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

Contents of /trunk/pygtk/solver.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 532 - (show annotations) (download) (as text)
Mon Apr 24 02:23:08 2006 UTC (13 years, 11 months ago) by johnpye
File MIME type: text/x-c++src
File size: 2197 byte(s)
Removed 'interface' directory in trunk/pygtk/interface (moved everything up a level)
Made corresponding changes to SCons* and spec files.
1 #include "config.h"
2 #include "reporter.h"
3 #include "solver.h"
4
5 #include <stdexcept>
6 #include <iostream>
7 #include <sstream>
8 using namespace std;
9
10 extern "C"{
11 #include <solver/slv0.h>
12 #include <solver/slv1.h>
13 #include <solver/slv2.h>
14 #include <solver/slv3.h>
15 #include <solver/slv9.h>
16 }
17
18 /**
19 Create a solver by name (it must already be registered)
20 Warning, this ctor throws an exception if the name is invalid!
21 */
22 Solver::Solver(const string &name){
23 //cerr << "CREATING SOLVER, name = " << name << endl;
24 this->name = name;
25 }
26
27 Solver::Solver(const Solver &old){
28 this->name = old.name;
29 //cerr << "COPIED SOLVER, name = " << name << endl;
30 }
31
32 const int
33 Solver::getIndex() const{
34 int index = slv_lookup_client(name.c_str());
35 if(index < 0){
36 stringstream ss;
37 ss << "Unknown or unregistered solver '" << name << "'";
38 throw runtime_error(ss.str());
39 }
40 //cerr << "))))))))))))))SOLVER INDEX RETURNED IS " << index << endl;
41 return index;
42 }
43
44 const string &
45 Solver::getName() const{
46 return name;
47 }
48
49 //---------------------------------
50 // >>>> GLOBAL FUNCTIONS <<<<
51 // for registering solvers and querying the complete list
52
53 void
54 registerSolver(SlvRegistration regfuncptr){
55 int newclient =-1;
56 int res = slv_register_client(regfuncptr,NULL,NULL,&newclient);
57 if(res!=0){
58 ERROR_REPORTER_NOLINE(ASC_PROG_ERROR,"Unable to register solver");
59 throw runtime_error("Solver::registerSolver: Unable to register solver");
60 }else{
61 string name = slv_solver_name(newclient);
62 cerr << "Registered solver '" << name << "' (index " << newclient << ")" << endl;
63 }
64 }
65
66 const vector<Solver>
67 getSolvers(){
68 ASC_DLLSPEC(int) g_SlvNumberOfRegisteredClients;
69 vector<Solver> v;
70 for(int i=0; i < g_SlvNumberOfRegisteredClients; ++i){
71 v.push_back(Solver(slv_solver_name(i)));
72 }
73 return v;
74 }
75
76 /**
77 Register the solvers which will be accessible via index number. The order you
78 register them determines the resulting index ids, so don't mess around with the
79 order of stuff in this function.
80
81 Add to this list as you feel necessary...
82 */
83 void
84 registerStandardSolvers(){
85 //cerr << "------------- REGISTERING SOLVERS -----------------" << endl;
86 registerSolver(slv3_register);
87 registerSolver(slv9_register);
88 }
89

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