33using std::ostringstream;
71 std::string osol =
"";
86 if(
sSolverName.find(
"lindo") != std::string::npos)
89 bool bLindoIsPresent =
false;
91 bLindoIsPresent =
true;
94 if(bLindoIsPresent ==
false)
throw ErrorClass(
"the Lindo solver requested is not present");
112 if(
sSolverName.find(
"cplex") != std::string::npos)
119 if(
sSolverName.find(
"glpk") != std::string::npos)
128 if(
sSolverName.find(
"ipopt") != std::string::npos)
132 bool bIpoptIsPresent =
false;
136 bIpoptIsPresent =
true;
138 ipoptSolver->
osol = osol;
140 ipoptSolver->
solve();
141 return ipoptSolver->
osrl ;
143 if(bIpoptIsPresent ==
false)
throw ErrorClass(
"the Ipopt solver requested is not present");
148 if(
sSolverName.find(
"symphony") != std::string::npos)
155 if(
sSolverName.find(
"dylp") != std::string::npos)
162 throw ErrorClass(
"a supported solver is not present");
202 ostringstream outStr;
215 std::string *varNames;
216 varNames =
new std::string[
numVar];
218 for(i = 0; i <
numVar; i++)
222 varNames[ i] = outStr.str();
234 for(i = 0; i <
numVar; i++)
239 std::string maxOrMin =
"min";
240 if(
objType ==
true) maxOrMin =
"max";
244 std::string *conNames;
245 conNames =
new std::string[
numCon];
248 for(i = 0; i <
numCon; i++)
252 conNames[ i] = outStr.str();
Implements a solve method for the Coin solvers.
std::string sSolverName
sSolverName is the name of the Coin solver used, e.g.
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
std::string osrl
osrl holds the solution or result of the model
OSInstance * osinstance
osinstance holds the problem instance in-memory as an OSInstance object
used for throwing exceptions.
std::string errormsg
errormsg is the error that is causing the exception to be thrown
The IpoptSolver class solves problems using Ipopt.
virtual void solve()
solve results in an instance being read into the Ipopt data structures and optimize
the LindoSolver class solves problems using Lindo.
The in-memory representation of an OSiL instance..
bool setConstraintNumber(int number)
set the number of constraints.
bool addVariable(int index, std::string name, double lowerBound, double upperBound, char type)
add a variable.
bool addConstraint(int index, std::string name, double lowerBound, double upperBound, double constant)
add a constraint.
bool setQuadraticTermsInNonlinearExpressions(int number, int *rowIndexes, int *varOneIndexes, int *varTwoIndexes, double *coefficients)
set quadratic terms in nonlinearExpressions
bool setLinearConstraintCoefficients(int numberOfValues, bool isColumnMajor, double *values, int valuesBegin, int valuesEnd, int *indexes, int indexesBegin, int indexesEnd, int *starts, int startsBegin, int startsEnd)
set linear constraint coefficients
bool setInstanceDescription(std::string description)
set the instance description.
bool setInstanceName(std::string name)
set the instance name.
bool addObjective(int index, std::string name, std::string maxOrMin, double constant, double weight, SparseVector *objectiveCoefficients)
add an objective.
bool setObjectiveNumber(int number)
set the number of objectives.
bool setVariableNumber(int number)
set the number of variables.
std::string instanceName
instanceName is the name of the problem instance
double * qVal
qVal is a pointer to the coefficient value of each of the quadratic terms.
double * bl
bl is a pointer to the lower bounds on the constraints
double * obj
obj is a pointer to the objective function coefficients
DefaultSolver * solverType
solverType is the a pointer to the sovler that will be requested
int numQTerms
numQTerms is the number of quadratic terms
std::string sAgentAddress
is the address of the solver service
char * varType
varType is a pointer to the variable type eg C, B, I
double * vl
vl is a pointer to the lower bounds on the varialbes
double * bu
bu is a pointer to the upper bounds on the constraints
SparseMatrix * sparseMat
sparseMat is a pointer to an OS Sprase Matrix data structure
void createOSInstance()
Create an OSInstance.
std::string sSolverName
sSolverName is the name of the solver
std::string osil
is the osil instance that gets created from the MATLAB data structures
~OSMatlab()
the OSMatlab class destructor
int * qRows
qRows is a pointer to the row index of each quadratic term
int * qIndex2
qIndex2 is a pointer to the index of the second variable in each of the quadratic terms
OSMatlab()
the OSMatlab class constructor
int * qIndex1
qIndex1 is a pointer to the index of the first variable in each of the quadratic terms
double * vu
vu is a pointer to the upper bounds on the variables
bool objType
objType indicates whether or not we have a max (1) or a min (0)
OSInstance * osinstance
osinstance is a pointer to an OSInstance object that gets created from the MATLAB data structures
int numVar
numVar is the number of variables in the problem
std::string solve()
Solve the problem instance.
int numCon
numCon is the number of constraints in the problem
Used by a client to invoke a remote solver.
std::string solve(std::string osil, std::string osol)
implement the solve() method which is a virtual function in OShL, this is synchronous
Take an OSInstance object and write a string that validates against the OSiL schema.
std::string writeOSiL(const OSInstance *theosinstance)
create an osil string from an OSInstance object
bool m_bWhiteSpace
m_bWhiteSpace is set to true if we write white space in the file
int * indexes
indexes holds an integer array of rowIdx (or colIdx) elements in coefMatrix (AMatrix).
int valueSize
valueSize is the dimension of the indexes and values arrays
int * starts
starts holds an integer array of start elements in coefMatrix (AMatrix), which points to the start of...
double * values
values holds a double array of value elements in coefMatrix (AMatrix), which contains nonzero element...
int startSize
startSize is the dimension of the starts array
a sparse vector data structure
double * values
values holds a double array of nonzero values.
int * indexes
indexes holds an integer array of indexes whose corresponding values are nonzero.