16 #include <cppad/cppad.hpp>
24 #include "OSInstance.h"
34 #include "CglGomory.hpp"
35 #include "CglSimpleRounding.hpp"
36 #include "CglKnapsackCover.hpp"
38 #include "CbcModel.hpp"
45 WindowsErrorPopupBlocker();
49 const char dirsep = CoinFindDirSeparator();
52 dataDir = dirsep ==
'/' ?
"../data/" :
"..\\data\\";
53 cout <<
"Start Building the Model" << endl;
56 std::string osilFileName;
57 osilFileName = dataDir +
"osilFiles" + dirsep +
"p0033.osil";
58 std::cout <<
"Try to read a sample file" << std::endl;
59 std::cout <<
"The file is: " ;
60 std::cout << osilFileName << std::endl;
65 osinstance = osilreader->
readOSiL( osil);
67 cout <<
"Done writing the Model" << endl;
74 solver->
osiSolver->setHintParam(OsiDoReducePrint,
true, OsiHintTry);
76 cout <<
"Here is the initial objective value " << solver->
osiSolver->getObjValue() << endl;
78 CglKnapsackCover cover;
79 CglSimpleRounding round;
81 CbcModel *model =
new CbcModel( *solver->
osiSolver);
84 model->setMaximumNodes(100000);
86 model->addCutGenerator(&gomory, 1,
"Gomory");
87 model->addCutGenerator(&cover, 1,
"Cover");
88 model->addCutGenerator(&round, 1,
"Round");
89 model->branchAndBound();
97 std::string *rcost = NULL;
100 throw ErrorClass(
"OSResult error: setServiceName");
102 throw ErrorClass(
"OSResult error: setInstanceName");
104 throw ErrorClass(
"OSResult error: setVariableNumer");
106 throw ErrorClass(
"OSResult error: setObjectiveNumber");
108 throw ErrorClass(
"OSResult error: setConstraintNumber");
110 throw ErrorClass(
"OSResult error: setSolutionNumer");
112 std::string description =
"";
114 std::cout <<
"PROVEN OPTIMAL " << model->isProvenOptimal() << std::endl;
116 if (model->isProvenOptimal() == 1){
124 *(z + 0) = model->getObjValue();
127 *(x + i) = model->getColSolution()[i];
132 *(y + i) = model->getRowPrice()[ i];
137 int numberOfOtherVariableResult = 1;
142 std::ostringstream outStr;
144 for(i=0; i < numberOfVar; i++){
145 outStr << model->getReducedCost()[ i];
146 rcost[ i] = outStr.str();
154 if(solver->
osiSolver->isProvenPrimalInfeasible() ==
true)
157 if(solver->
osiSolver->isProvenDualInfeasible() ==
true)
163 std::cout << osrlwriter->
writeOSrL( osresult) << std::endl;
189 cout <<
"Done with garbage collection" << endl;
190 cout <<
"Program terminates normally" << endl;
195 std::cout << eclass.
errormsg << std::endl;
bool setSolutionStatus(int solIdx, std::string type, std::string description)
Set the [i]th optimization solution status, where i equals the given solution index.
bool setPrimalVariableValuesDense(int solIdx, double *x)
Set the [i]th optimization solution's primal variable values, where i equals the given solution index...
int getVariableNumber()
Get number of variables.
bool setServiceName(std::string serviceName)
Set service name.
bool setVariableNumber(int variableNumber)
Set the variable number.
std::string errormsg
errormsg is the error that is causing the exception to be thrown
int main(int argc, char *argv[])
OsiSolverInterface * osiSolver
osiSolver is the osi solver object – in this case clp, glpk, cbc, cplex, symphony or dylp ...
Take an OSResult object and write a string that validates against OSrL.
bool setDualVariableValuesDense(int solIdx, double *y)
Set the [i]th optimization solution's dual variable values, where i equals the given solution index...
bool setAnOtherVariableResultDense(int solIdx, int otherIdx, std::string name, std::string value, std::string description, std::string *s)
Set the [i]th optimization solution's other (non-standard/solver specific)variable-related results...
bool setObjectiveNumber(int objectiveNumber)
Set the objective number.
bool setInstanceName(std::string instanceName)
Set instance name.
OSInstance * readOSiL(const std::string &osil)
parse the OSiL model instance.
std::string writeOSrL(OSResult *theosresult)
create an osrl string from an OSResult object
virtual void buildSolverInstance()
The implementation of the corresponding virtual function.
bool setSolutionNumber(int number)
set the number of solutions.
Used to read an OSiL string.
bool setNumberOfOtherVariableResults(int solIdx, int numberOfOtherVariableResults)
Set the [i]th optimization solution's other (non-standard/solver specific) variable-related results...
OSInstance * osinstance
osinstance holds the problem instance in-memory as an OSInstance object
bool setGeneralStatusType(std::string type)
Set the general status type, which can be: success, error, warning.
std::string getInstanceName()
Get instance name.
int getConstraintNumber()
Get number of constraints.
bool setConstraintNumber(int constraintNumber)
Set the constraint number.
std::string sSolverName
sSolverName is the name of the Coin solver used, e.g.
Implements a solve method for the Coin solvers.
std::string getFileAsString(const char *fname)
read a file and return contents as a string.
bool setObjectiveValuesDense(int solIdx, double *objectiveValues)
Set the [i]th optimization solution's objective values, where i equals the given solution index...
The in-memory representation of an OSiL instance..
class used to make it easy to read and write files.
used for throwing exceptions.
void fint fint fint real fint real * x