00001 #ifndef __SOLVER_API_H
00002 #define __SOLVER_API_H
00003
00004 #include <string>
00005 #include <list>
00006
00007 enum API {
00008 CPLEX=0,
00009 GLPK=1,
00010 GLPSOL=1
00011 };
00012
00016 struct solverVAR_NomVal
00017 {
00018 std::string nom;
00019 float val;
00020
00022 solverVAR_NomVal() {};
00023 solverVAR_NomVal(const std::string& _nom, const float _val) : nom(_nom), val(_val) {};
00024
00025 };
00026
00027
00033 class SolverAPI
00034 {
00035 protected:
00036 unsigned solver;
00037
00038 std::string fLP;
00039 std::string path;
00040 std::list<std::string> option;
00041
00042 bool isSolved;
00043 bool isOptimal;
00044 bool isMIP;
00045
00046
00047
00048
00049
00050
00051 std::list<std::string> contraintesNOM;
00052 std::list<std::string> variablesNOM;
00053 std::list<float> contraintesVAL;
00054 std::list<float> variablesVAL;
00055
00056 solverVAR_NomVal objective;
00057 std::string typeRetour;
00058 std::string typeOperation;
00059
00060 protected:
00061
00071 int SystemFork (const char *str);
00072
00073
00074
00080 std::string AvoidSpaces(std::string& s);
00089 void Tokenize(const std::string& str, std::list<std::string>& tokens,const std::string& delimiters);
00090
00091 public:
00092 SolverAPI() : solver(GLPK) {};
00093 SolverAPI(const std::string& _fLP) : solver(GLPK) , fLP(_fLP) {};
00094
00098 void Init(const std::string& _fLP="./tmp.solver.lp", const std::string& _path="")
00099 {
00100 fLP = _fLP;
00101 path = _path;
00102 }
00105 void SetAPI(API _solver)
00106 {
00107 solver = _solver;
00108 }
00109
00110 API GetAPI() const
00111 {
00112 return static_cast<API>(solver);
00113 }
00114
00117 const char * GetfLP()
00118 {
00119 return fLP.c_str();
00120 }
00121 void SetfLP(const std::string& _flp)
00122 {
00123 fLP = _flp;
00124 }
00125
00128 bool IsSolved() const
00129 {
00130 return isSolved;
00131 }
00134 bool IsOptimal() const
00135 {
00136 return isOptimal;
00137 }
00138
00139 void SetMIP( bool isMip )
00140 {
00141 isMIP = isMip;
00142 }
00146 void Infos(std::string& _operation, std::string& _information)
00147 {
00148 _operation = typeOperation;
00149 _information = typeRetour;
00150 }
00151
00152
00153
00154 std::list<float> & OutNumVarValues () {return variablesVAL;}
00155 std::list<std::string>& GetNumVarNoms () {return variablesNOM;}
00156 std::list<float> & OutConstraintValues() {return contraintesVAL;}
00157 std::list<std::string>& GetConstraintNoms () {return contraintesNOM;}
00158
00163 float Solve();
00164
00171 void Options(const std::string& _options);
00175 void RemoveOptions()
00176 {
00177 option.clear();
00178 }
00179
00188 bool glpk_GetObj(std::string& _s, float& objval);
00189
00198 bool cplx_GetObj(std::string& _s, float& objval);
00199
00200 ~SolverAPI() {};
00201 };
00202
00203 #endif