23 #include "OSInstance.h"
34 #include "CoinError.hpp"
35 #include "CoinHelperFunctions.hpp"
65 WindowsErrorPopupBlocker();
68 cout <<
"Start Building the Model" << endl;
71 const char dirsep = CoinFindDirSeparator();
75 std::string osilFileName;
77 dataDir = dirsep ==
'/' ?
"../data/" :
"..\\data\\";
94 std::cout << std::endl << std::endl;
95 std::cout <<
"CLP EXAMPLE" << std::endl;
100 std::string mpsFileName;
101 mpsFileName = dataDir +
"mpsFiles" + dirsep +
"parinc.mps";
104 mps2osil =
new OSmps2OS( mpsFileName);
122 std::cout << osolwriter-> writeOSoL( osoption);
171 std::cout << std::endl << std::endl;
172 std::cout <<
"CBC EXAMPLE" << std::endl;
177 osilFileName = dataDir +
"osilFiles" + dirsep +
"p0033.osil";
180 osinstance = osilreader->
readOSiL( osil);
200 std::cout << osolwriter-> writeOSoL( osoption);
240 #ifdef OS_HAS_COUENNE
243 std::cout << std::endl << std::endl;
244 std::cout <<
"COUENNE EXAMPLE" << std::endl;
249 std::string nlFileName;
250 nlFileName = dataDir +
"amplFiles" + dirsep +
"bonminEx1.nl";
253 nl2osil->
readNl(nlFileName);
260 if (osoption == NULL)
286 xinitial =
new double[numVar];
287 for(i = 0; i < numVar; i++){
292 std::cout << osolwriter-> writeOSoL( osoption);
317 std::cout <<
"call get osresult" << std::endl;
318 std::cout << solver->
osrl << std::endl;
340 #endif //end of OS_HAS_COUENNE
344 std::cout << std::endl << std::endl;
345 std::cout <<
"SYMPHONY EXAMPLE" << std::endl;
351 osilFileName = dataDir +
"osilFiles" + dirsep +
"p0033.osil";
354 osinstance = osilreader->
readOSiL( osil);
369 std::cout << osolwriter-> writeOSoL( osoption);
410 std::cout << std::endl << std::endl;
411 std::cout <<
"IPOPT EXAMPLE" << std::endl;
416 osilFileName = dataDir +
"osilFiles" + dirsep +
"rosenbrockmod.osil";
437 xinitial =
new double[numVar];
438 for(i = 0; i < numVar; i++){
443 std::cout << osolwriter-> writeOSoL( osoption);
485 #endif //end of OS_HAS_IPOPT
491 std::cout << std::endl << std::endl;
492 std::cout <<
"BONMIN EXAMPLE" << std::endl;
497 osilFileName = dataDir +
"osilFiles" + dirsep +
"wayneQuadratic.osil";
500 osinstance = osilreader->
readOSiL( osil);
518 std::cout << osolwriter-> writeOSoL( osoption);
538 std::cout <<
"call get osresult" << std::endl;
539 std::cout << solver->
osrl << std::endl;
541 std::cout <<
"finish call get osresult" << std::endl;
557 #endif //end of OS_HAS_BONMIN
562 std::cout <<
"\nSolverDemo COMPLETED WITHOUT ERROR\n";
568 std::cout << eclass.
errormsg << std::endl;
569 std::cout <<
"\nSolverDemo COMPLETED, BUT THERE WERE ERRORS\n";
578 std::cout << std::endl << std::endl << std::endl;
582 osresult = osrlreader->
readOSrL( osrl);
586 std::string solStatus;
591 if( solStatus.find(
"ptimal") != string::npos ){
594 std::cout <<
"OPTIMAL SOLUTION VALUE " << optSolValue << std::endl;
596 std::cout << std::endl;
597 std::cout <<
"We are not optimal!" << std::endl;
598 std::cout << solStatus << std::endl;
604 std::vector<IndexValuePair*> primalValPair;
606 vecSize = primalValPair.size();
607 for(i = 0; i < vecSize; i++){
608 if(primalValPair[ i]->value > 0 || primalValPair[ i]->value < 0){
609 std::cout <<
"index = " << primalValPair[ i]->idx ;
610 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.
OSInstance * osinstance
osinstance is a pointer to the OSInstance object that gets created from the instance represented in M...
bool readNl(std::string stub)
read the nl file
bool createOSObjects()
create an OSInstance and OSOption representation from the AMPL nl content (Some of the information in...
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
bool createOSObjects()
create an OSInstance from the MPS instance representation and an OSOption in case of nonstandard sect...
std::string sSolverName
sSolverName is the name of the Coin solver used, e.g.
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 information in the nl fil...
used for throwing exceptions.