00001
00015 #ifndef OSRUNSOLVER_H
00016 #define OSRUNSOLVER_H
00017
00018
00019 #include "OSCoinSolver.h"
00020 #include "OSResult.h"
00021 #include "OSiLReader.h"
00022 #include "OSiLWriter.h"
00023 #include "OSoLReader.h"
00024 #include "OSrLReader.h"
00025 #include "OSrLWriter.h"
00026 #include "OSInstance.h"
00027 #include "OSOption.h"
00028 #include "OSoLWriter.h"
00029 #include "OSFileUtil.h"
00030 #include "OSConfig.h"
00031 #include "OSDefaultSolver.h"
00032 #include "OSWSUtil.h"
00033 #include "OSSolverAgent.h"
00034 #include "OShL.h"
00035 #include "OSErrorClass.h"
00036 #include "OSmps2osil.h"
00037 #include "OSBase64.h"
00038
00039 #ifdef COIN_HAS_KNITRO
00040 #include "OSKnitroSolver.h"
00041 #endif
00042
00043 #ifdef COIN_HAS_LINDO
00044 #include "OSLindoSolver.h"
00045 #endif
00046
00047 #ifdef COIN_HAS_ASL
00048 #include "OSnl2osil.h"
00049 #endif
00050
00051 #ifdef COIN_HAS_GAMSUTILS
00052 #include "OSgams2osil.hpp"
00053 #endif
00054
00055
00056
00057
00058
00059 #ifdef COIN_HAS_IPOPT
00060 #ifndef COIN_HAS_ASL
00061 #include "OSIpoptSolver.h"
00062 #undef COIN_HAS_ASL
00063 #else
00064 #include "OSIpoptSolver.h"
00065 #endif
00066 #endif
00067
00068 #ifdef COIN_HAS_BONMIN
00069 #include "OSBonminSolver.h"
00070 #endif
00071
00072 #ifdef COIN_HAS_COUENNE
00073 #include "OSCouenneSolver.h"
00074 #endif
00075
00076 #include "OSOptionsStruc.h"
00077
00078 #include<stdio.h>
00079 #include <map>
00080
00081
00082 using std::cout;
00083 using std::endl;
00084 using std::ostringstream;
00085 using std::string;
00086 using std::map;
00087
00088
00089 std::string runSolver(std::string solverName, std::string osol,
00090 OSInstance *osinstance)
00091 {
00092 DefaultSolver *solverType = NULL;
00093
00094 try
00095 {
00096 if (solverName == "")
00097 {
00098 if (osinstance == NULL)
00099 throw ErrorClass(
00100 "there was a NULL instance sent to buildSolver");
00101
00102 if (osinstance->getNumberOfIntegerVariables()
00103 + osinstance->getNumberOfBinaryVariables() > 0)
00104 {
00105 if ((osinstance->getNumberOfNonlinearExpressions() > 0)
00106 || (osinstance->getNumberOfQuadraticTerms() > 0))
00107 {
00108 solverName = "bonmin";
00109 }
00110 else
00111 {
00112 solverName = "cbc";
00113 }
00114 }
00115 else
00116 {
00117 if ((osinstance->getNumberOfNonlinearExpressions() > 0)
00118 || (osinstance->getNumberOfQuadraticTerms() > 0))
00119 {
00120 solverName = "ipopt";
00121 }
00122 else
00123 {
00124 solverName = "clp";
00125 }
00126 }
00127 }
00128
00129
00130
00131
00132
00133 if (solverName.find("ipopt") != std::string::npos)
00134 {
00135
00136
00137 #ifdef COIN_HAS_IPOPT
00138 solverType = new IpoptSolver();
00139 solverType->sSolverName = "ipopt";
00140 #else
00141 throw ErrorClass("the Ipopt solver requested is not present");
00142 #endif
00143 }
00144 else
00145 {
00146 if (solverName.find("lindo") != std::string::npos)
00147 {
00148
00149 #ifdef COIN_HAS_LINDO
00150 solverType = new LindoSolver();
00151 solverType->sSolverName = "lindo";
00152 #else
00153 throw ErrorClass( "the Lindo solver requested is not present");
00154 #endif
00155 }
00156 else
00157 {
00158 if (solverName.find("clp") != std::string::npos)
00159 {
00160
00161 solverType = new CoinSolver();
00162
00163 solverType->sSolverName = "clp";
00164 }
00165 else
00166 {
00167 if (solverName.find("cplex") != std::string::npos)
00168 {
00169 #ifdef COIN_HAS_CPX
00170 solverType = new CoinSolver();
00171 solverType->sSolverName = "cplex";
00172 #else
00173 throw ErrorClass( "the Cplex solver requested is not present");
00174 #endif
00175 }
00176 else
00177 {
00178 if (solverName.find("glpk") != std::string::npos)
00179 {
00180 #ifdef COIN_HAS_GLPK
00181 solverType = new CoinSolver();
00182 solverType->sSolverName = "glpk";
00183 #else
00184 throw ErrorClass( "the GLPK solver requested is not present");
00185 #endif
00186 }
00187 else
00188 {
00189 if (solverName.find("dylp") != std::string::npos)
00190 {
00191 #ifdef COIN_HAS_DYLP
00192 solverType = new CoinSolver();
00193 solverType->sSolverName = "dylp";
00194 #else
00195 throw ErrorClass( "the DyLP solver requested is not present");
00196 #endif
00197 }
00198 else
00199 {
00200 if (solverName.find("symphony")
00201 != std::string::npos)
00202 {
00203 #ifdef COIN_HAS_SYMPHONY
00204 solverType = new CoinSolver();
00205 solverType->sSolverName = "symphony";
00206 #else
00207 throw ErrorClass( "the SYMPHONY solver requested is not present");
00208 #endif
00209 }
00210 else
00211 {
00212 if (solverName.find("knitro")
00213 != std::string::npos)
00214 {
00215 #ifdef COIN_HAS_KNITRO
00216
00217 solverType = new KnitroSolver();
00218 solverType->sSolverName = "knitro";
00219
00220 #else
00221 throw ErrorClass( "the Knitro solver requested is not present");
00222 #endif
00223 }
00224 else
00225 {
00226 if (solverName.find("vol")
00227 != std::string::npos)
00228 {
00229 #ifdef COIN_HAS_VOL
00230 solverType = new CoinSolver();
00231 solverType->sSolverName = "vol";
00232 #else
00233 throw ErrorClass( "the Vol solver requested is not present");
00234 #endif
00235 }
00236 else
00237 {
00238 if (solverName.find("bonmin")
00239 != std::string::npos)
00240 {
00241
00242 #ifdef COIN_HAS_BONMIN
00243
00244 solverType = new BonminSolver();
00245 solverType->sSolverName = "bonmin";
00246 #else
00247 throw ErrorClass( "the Bonmin solver requested is not present");
00248 #endif
00249 }
00250 else
00251 {
00252 if (solverName.find("couenne")
00253 != std::string::npos)
00254 {
00255
00256 #ifdef COIN_HAS_COUENNE
00257 solverType = new CouenneSolver();
00258 solverType->sSolverName = "couenne";
00259 #else
00260 throw ErrorClass( "the Couenne solver requested is not present");
00261 #endif
00262 }
00263 else
00264 {
00265 if(solverName.find("cbc") != std::string::npos)
00266 {
00267 solverType = new CoinSolver();
00268 solverType->sSolverName = "cbc";
00269 }
00270 else
00271 {
00272 std::string errorMessage;
00273 errorMessage = "solver type " + solverName + " is not supported";
00274 throw ErrorClass( errorMessage );
00275
00276
00277 }
00278 }
00279 }
00280 }
00281 }
00282 }
00283 }
00284 }
00285 }
00286 }
00287 }
00288 }
00289
00290
00291
00292
00293 solverType->osinstance = osinstance;
00294 solverType->osol = osol;
00295 solverType->buildSolverInstance();
00296 solverType->setSolverOptions();
00297 solverType->solve();
00298 std::string resultString = solverType->osrl;
00299 if (solverType != NULL)
00300 delete solverType;
00301 solverType = NULL;
00302 return resultString;
00303
00304
00305 }
00306 catch (const ErrorClass& eclass)
00307 {
00308 throw eclass;
00309 }
00310
00311 }
00312
00313 #endif