23 #include "OSInstance.h"
31 #include "OSnl2osil.h"
35 #include "CoinError.hpp"
36 #include "CoinHelperFunctions.hpp"
42 #include "OSnl2osil.h"
66 WindowsErrorPopupBlocker();
69 cout <<
"Start Building the Model" << endl;
74 const char dirsep = CoinFindDirSeparator();
78 std::string osilFileName;
80 dataDir = dirsep ==
'/' ?
"../data/" :
"..\\data\\";
98 std::cout << std::endl << std::endl;
99 std::cout <<
"CLP EXAMPLE" << std::endl;
104 std::string mpsFileName;
105 mpsFileName = dataDir +
"mpsFiles" + dirsep +
"parinc.mps";
126 std::cout << osolwriter-> writeOSoL( osoption);
175 std::cout << std::endl << std::endl;
176 std::cout <<
"CBC EXAMPLE" << std::endl;
181 osilFileName = dataDir +
"osilFiles" + dirsep +
"p0033.osil";
184 osinstance = osilreader->
readOSiL( osil);
204 std::cout << osolwriter-> writeOSoL( osoption);
244 #ifdef OS_HAS_COUENNE
247 std::cout << std::endl << std::endl;
248 std::cout <<
"COUENNE EXAMPLE" << std::endl;
253 std::string nlFileName;
254 nlFileName = dataDir +
"amplFiles" + dirsep +
"bonminEx1.nl";
256 OSnl2osil *nl2osil = NULL;
257 nl2osil =
new OSnl2osil( nlFileName);
259 nl2osil->createOSInstance() ;
260 osinstance = nl2osil->osinstance;
290 xinitial =
new double[numVar];
291 for(i = 0; i < numVar; i++){
296 std::cout << osolwriter-> writeOSoL( osoption);
321 std::cout <<
"call get osresult" << std::endl;
322 std::cout << solver->
osrl << std::endl;
342 #endif //end of OS_HAS_COUENNE
349 std::cout << std::endl << std::endl;
350 std::cout <<
"SYMPHONY EXAMPLE" << std::endl;
356 osilFileName = dataDir +
"osilFiles" + dirsep +
"p0033.osil";
359 osinstance = osilreader->
readOSiL( osil);
374 std::cout << osolwriter-> writeOSoL( osoption);
415 std::cout << std::endl << std::endl;
416 std::cout <<
"IPOPT EXAMPLE" << std::endl;
421 osilFileName = dataDir +
"osilFiles" + dirsep +
"rosenbrockmod.osil";
442 xinitial =
new double[numVar];
443 for(i = 0; i < numVar; i++){
448 std::cout << osolwriter-> writeOSoL( osoption);
488 #endif //end of OS_HAS_IPOPT
494 std::cout << std::endl << std::endl;
495 std::cout <<
"BONMIN EXAMPLE" << std::endl;
500 osilFileName = dataDir +
"osilFiles" + dirsep +
"wayneQuadratic.osil";
503 osinstance = osilreader->
readOSiL( osil);
521 std::cout << osolwriter-> writeOSoL( osoption);
541 std::cout <<
"call get osresult" << std::endl;
542 std::cout << solver->
osrl << std::endl;
544 std::cout <<
"finish call get osresult" << std::endl;
558 #endif //end of OS_HAS_BONMIN
563 std::cout <<
"\nSolverDemo COMPLETED WITHOUT ERROR\n";
569 std::cout << eclass.
errormsg << std::endl;
570 std::cout <<
"\nSolverDemo COMPLETED, BUT THERE WERE ERRORS\n";
579 std::cout << std::endl << std::endl << std::endl;
583 osresult = osrlreader->
readOSrL( osrl);
587 std::string solStatus;
592 if( solStatus.find(
"ptimal") != string::npos ){
595 std::cout <<
"OPTIMAL SOLUTION VALUE " << optSolValue << std::endl;
597 std::cout << std::endl;
598 std::cout <<
"We are not optimal!" << std::endl;
599 std::cout << solStatus << std::endl;
605 std::vector<IndexValuePair*> primalValPair;
607 vecSize = primalValPair.size();
608 for(i = 0; i < vecSize; i++){
609 if(primalValPair[ i]->value > 0 || primalValPair[ i]->value < 0){
610 std::cout <<
"index = " << primalValPair[ i]->idx ;
611 std::cout <<
" value = " << primalValPair[ i]->value << std::endl;
std::string getSolutionStatusType(int solIdx)
Get the [i]th optimization solution status type, where i equals the given solution index...
The CouenneSolver class solves problems using Ipopt.
int getVariableNumber()
Get number of variables.
bool setAnotherSolverOption(std::string name, std::string value, std::string solver, std::string category, std::string type, std::string description)
std::string osrl
osrl holds the solution or result of the model
std::string osil
osil holds the problem instance as a std::string
std::string errormsg
errormsg is the error that is causing the exception to be thrown
int main(int argc, char *argv[])
std::vector< IndexValuePair * > getOptimalPrimalVariableValues(int solIdx)
Get one solution of optimal primal variable values.
bool setInitVarValuesDense(int numberOfVar, double *value)
OSResult * readOSrL(const std::string &posrl)
Get an OSResult object from an OSrL string.
double getOptimalObjValue(int objIdx, int solIdx)
Get one solution's optimal objective value.
Take an OSOption object and write a string that validates against the OSoL schema.
OSInstance * readOSiL(const std::string &osil)
parse the OSiL model instance.
The IpoptSolver class solves problems using Ipopt.
void getOSResult(std::string osrl)
std::string osol
osol holds the options for the solver
virtual void solve()=0
solve is a virtual function – the actual solvers will implement their own solve method ...
Used to read an OSiL string.
OSOption * osoption
osoption holds the solver options in-memory as an OSOption object
The Default Solver Class.
OSInstance * osinstance
osinstance holds the problem instance in-memory as an OSInstance object
std::string sSolverName
sSolverName is the name of the Coin solver used, e.g.
bool createOSInstance()
create an OSInstance from the MPS instance representation
virtual void setSolverOptions()=0
setSolverOptions is a virtual function – the actual solvers will implement their own setSolverOptions...
std::string getSolutionStatusDescription(int solIdx)
Get the [i]th optimization solution status description, where i equals the given solution index...
Implements a solve method for the Coin solvers.
std::string getFileAsString(const char *fname)
read a file and return contents as a string.
The BonminSolver class solves problems using Ipopt.
virtual void buildSolverInstance()=0
buildSolverInstance is a virtual function – the actual solvers will implement their own buildSolverIn...
The in-memory representation of an OSiL instance..
class used to make it easy to read and write files.
OSInstance * osinstance
osinstance is a pointer to the OSInstance object that gets created from the instance represented in N...
used for throwing exceptions.