25 #include "OSInstance.h"
34 #include "CoinFinite.hpp"
36 #include "ClpSimplex.hpp"
37 #include "ClpSolve.hpp"
38 #include "CbcOrClpParam.hpp"
39 #include "ClpInterior.hpp"
40 #include "ClpCholeskyBase.hpp"
41 #include "ClpQuadraticObjective.hpp"
57 int main(
int argC,
char* argV[]){
58 WindowsErrorPopupBlocker();
64 ClpSolve solveOptions;
65 ClpSolve::SolveType method;
66 method = ClpSolve::useBarrier;
68 method = ClpSolve::usePrimal;
69 solveOptions.setSolveType( method);
71 ClpSimplex* qpClpModel;
75 std::cout <<
"Hello World" << std::endl;
80 CbcOrClpParam parameters[CBCMAXPARAMETERS];
81 int numberParameters ;
82 establishParams(numberParameters, parameters) ;
83 std::cout <<
"NUMBER OF PARAMETERS = " << numberParameters<< std::endl;
120 qpClpModel =
new ClpSimplex();
127 qpClpModel->setIntParam(ClpMaxNumIteration, 100) ;
132 std::cout <<
"Parameter number for: CLP_PARAM_INT_SOLVERLOGLEVEL " << whichParam(CLP_PARAM_INT_SOLVERLOGLEVEL, numberParameters, parameters) << std::endl;
133 std::cout <<
"Parameter number for: CLP_PARAM_INT_MAXITERATION " << whichParam(CLP_PARAM_INT_MAXITERATION, numberParameters, parameters) << std::endl;
134 parameters[ whichParam(CLP_PARAM_INT_SOLVERLOGLEVEL, numberParameters, parameters)].setIntParameter(qpClpModel, 0);
135 parameters[ whichParam(CLP_PARAM_INT_MAXITERATION, numberParameters, parameters)].setIntParameter(qpClpModel, 10);
137 std::cout <<
"CLP_PARAM_INT_SOLVERLOGLEVEL = " << parameters[whichParam(CLP_PARAM_INT_SOLVERLOGLEVEL, numberParameters, parameters)].intValue() << std::endl;
144 const char dirsep = CoinFindDirSeparator();
152 std::string osilFileName;
153 dataDir = dirsep ==
'/' ?
"../data/" :
"..\\data\\";
166 std::cout << std::endl << std::endl;
167 std::cout <<
"CLP EXAMPLE" << std::endl;
172 std::string qpFileName;
173 qpFileName = dataDir +
"osilFiles" + dirsep +
"parincQuadratic.osil";
177 osinstance = osilreader->
readOSiL( osil);
193 std::cout << osolwriter-> writeOSoL( osoption);
204 CoinPackedMatrix* matrix;
205 bool columnMajor =
true;
207 matrix =
new CoinPackedMatrix(
217 qpClpModel->setOptimizationDirection( -1);
227 std::map<int, std::map<int, double> > varIndexMap;
228 std::map<int, std::map<int, double> >::iterator mit1;
229 std::map<int, double> tmpMap;
230 std::map<int, double>::iterator mit2;
262 mit1 = varIndexMap.find( i1 );
264 if( mit1 == varIndexMap.end() ){
266 tmpMap.insert( std::pair<int, double>( j1,
270 varIndexMap[ i1 ] = tmpMap;
277 mit2 = mit1->second.find( j1) ;
279 if( mit2 == mit1->second.end() ){
281 mit1->second.insert( std::pair<int, double>( j1,
297 std::cout <<
"numNonz = " << numNonz << std::endl;
304 start =
new int[ varIndexMap.size() + 1];
305 idx =
new int[ numNonz];
306 nonz =
new double[ numNonz];
311 start[ kount++] = numNonz;
313 for( mit1 = varIndexMap.begin(); mit1 != varIndexMap.end(); mit1++){
315 std::cout << std::endl;
316 std::cout <<
"FIRST INDEX = " << mit1->first << std::endl;
317 for( mit2 = mit1->second.begin(); mit2 != mit1->second.end(); mit2++){
318 std::cout <<
"SECOND INDEX = " << mit2->first << std::endl;
319 std::cout <<
"COEFFICIENT = " << mit2->second << std::endl;
320 idx[ numNonz] = mit2->first;
322 nonz[ numNonz++ ] = mit2->second;
324 start[ kount++] = numNonz ;
345 qpClpModel->loadQuadraticObjective( qpClpModel->numberColumns(), start, idx, nonz);
347 qpClpModel->writeMps(
"quad.mps");
352 ClpCholeskyBase * cholesky =
new ClpCholeskyBase();
353 cholesky->setKKT(
true);
357 qpClpModel->initialSolve( solveOptions);
361 primal = qpClpModel->primalColumnSolution();
362 dual = qpClpModel->dualRowSolution();
365 int numberColumns = qpClpModel->numberColumns();
366 int numberRows = qpClpModel->numberRows();
367 for (i = 0; i < numberColumns; i++) {
368 if (fabs(primal[i]) > 1.0
e-8)
369 printf(
"%d primal %g\n", i, primal[i]);
371 for (i = 0; i < numberRows; i++) {
372 if (fabs(dual[i]) > 1.0
e-8)
373 printf(
"%d dual %g\n", i, dual[i]);
420 std::cout << std::endl <<
"Execution terminated normally" << std::endl;
430 std::cout << eclass.
errormsg << std::endl;
a data structure for holding quadratic terms
double * getConstraintLowerBounds()
Get constraint lower bounds.
double * getVariableLowerBounds()
Get variable lower bounds.
double * getConstraintUpperBounds()
Get constraint upper bounds.
int getVariableNumber()
Get number of variables.
std::string printModel()
Print the infix representation of the problem.
bool setAnotherSolverOption(std::string name, std::string value, std::string solver, std::string category, std::string type, std::string description)
std::string errormsg
errormsg is the error that is causing the exception to be thrown
int main(int argc, char *argv[])
int getLinearConstraintCoefficientNumber()
Get number of specified (usually nonzero) linear constraint coefficient values.
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.
int * indexes
indexes holds an integer array of rowIdx (or colIdx) elements in coefMatrix (AMatrix).
double ** getDenseObjectiveCoefficients()
getDenseObjectiveCoefficients.
void fint fint fint real fint real real real real real real real real real * e
Used to read an OSiL string.
int * varOneIndexes
varOneIndexes holds an integer array of the first variable indexes of all the quadratic terms...
SparseMatrix * getLinearConstraintCoefficientsInRowMajor()
Get linear constraint coefficients in row major.
The Default Solver Class.
SparseMatrix * getLinearConstraintCoefficientsInColumnMajor()
Get linear constraint coefficients in column major.
double * values
values holds a double array of value elements in coefMatrix (AMatrix), which contains nonzero element...
int getConstraintNumber()
Get number of constraints.
int getNumberOfQuadraticTerms()
Get the number of specified (usually nonzero) qTerms in the quadratic coefficients.
std::string getFileAsString(const char *fname)
read a file and return contents as a string.
int * rowIndexes
rowIndexes holds an integer array of row indexes of all the quadratic terms.
int * starts
starts holds an integer array of start elements in coefMatrix (AMatrix), which points to the start of...
QuadraticTerms * getQuadraticTerms()
Get all the quadratic terms in the instance.
double * getVariableUpperBounds()
Get variable upper bounds.
The in-memory representation of an OSiL instance..
class used to make it easy to read and write files.
double * coefficients
coefficients holds a double array all the quadratic term coefficients.
int * varTwoIndexes
varTwoIndexes holds an integer array of the second variable indexes of all the quadratic terms...
used for throwing exceptions.