20#include "OSInstance.h"
23#include "CoinTime.hpp"
24#include "CglPreProcess.hpp"
25#include "CglGomory.hpp"
26#include "CglSimpleRounding.hpp"
27#include "CglMixedIntegerRounding2.hpp"
28#include "CglKnapsackCover.hpp"
29#include "CglFlowCover.hpp"
30#include "CbcBranchActual.hpp"
31#include "CoinMessageHandler.hpp"
32#include "CoinMessage.hpp"
34#include "OsiClpSolverInterface.hpp"
35#include "CoinWarmStartBasis.hpp"
36#include "CbcSolver.hpp"
38#ifdef COIN_HAS_SYMPHONY
39#include "OsiSymSolverInterface.hpp"
43#include "OsiVolSolverInterface.hpp"
47#include "OsiDylpSolverInterface.hpp"
51#include "OsiGlpkSolverInterface.hpp"
55#include "OsiCpxSolverInterface.hpp"
59#include "OsiGrbSolverInterface.hpp"
63#include "OsiMskSolverInterface.hpp"
67#include "OsiSpxSolverInterface.hpp"
71#include "OsiXprSolverInterface.hpp"
75#include "OSParameters.h"
87# error "don't have header file for time"
93using std::ostringstream;
101 m_CoinPackedMatrix(NULL),
148 std::ostringstream outStr;
152 clock_t start, finish;
161 duration = (double) (finish - start) / CLOCKS_PER_SEC;
165 throw ErrorClass(
"Solver cannot handle multiple objectives --- please delete all but one");
178 throw ErrorClass(
"This OSSolverService was built without solver vol");
185 throw ErrorClass(
"This OSSolverService was built without solver cplex");
192 throw ErrorClass(
"This OSSolverService was built without solver gurobi");
199 throw ErrorClass(
"This OSSolverService was built without solver mosek");
203 #ifdef COIN_HAS_SOPLEX
206 throw ErrorClass(
"This OSSolverService was built without solver soplex");
213 throw ErrorClass(
"This OSSolverService was built without solver xpress");
218 osiSolver =
new OsiGlpkSolverInterface();
220 throw ErrorClass(
"This OSSolverService was built without solver glpk");
225 osiSolver =
new OsiDylpSolverInterface();
227 throw ErrorClass(
"This OSSolverService was built without solver dylp");
231 #ifdef COIN_HAS_SYMPHONY
234 throw ErrorClass(
"This OSSolverService was built without solver symphony");
246 throw ErrorClass(
"Solver selected is not supported by this version of OSSolverService");
251 throw ErrorClass(
"This COIN-OR Solver is not configured for nonlinear programming");
257 throw ErrorClass(
"This COIN-OR Solver is not configured for quadratic programming");
263 throw ErrorClass(
"Clp cannot do integer programming");
265 throw ErrorClass(
"Vol cannot do integer programming");
267 throw ErrorClass(
"DyLP cannot do integer programming");
268 if(
sSolverName.find(
"soplex") != std::string::npos)
269 throw ErrorClass(
"SoPlex cannot do integer programming");
274 throw ErrorClass(
"Semi-integer and semi-continuous variables not supported");
305 if (numOfIntVars > 0)
307 int *intIndex = NULL;
311 intIndex =
new int[ numOfIntVars];
315 if( (varType[i] ==
'B') || (varType[i]) ==
'I' )
320 osiSolver->setInteger( intIndex, numOfIntVars);
330 if ( (
sSolverName.find(
"clp") != std::string::npos) )
338 outStr <<
"original arrays:" << std::endl;
339 outStr <<
" var One indexes:";
340 for (
int i=0; i<nq; i++)
343 outStr <<
" var Two indexes:";
344 for (
int i=0; i<nq; i++)
347 outStr <<
" coefficients: ";
348 for (
int i=0; i<nq; i++)
356 int* colStarts =
new int[ncols+1];
357 for (
int i=0; i<=ncols; i++)
361 for (
int i=0; i<nq; i++)
364 throw ErrorClass(
"Clp solver cannot handle quadratic terms in the constraints");
370 for (
int i=0; i<ncols; i++)
371 colStarts[i+1] += colStarts[i];
379 for (
int i=0; i< ncols-1; i++)
381 swapLoc = colStarts[i+1];
382 for (
int j=colStarts[i]; j<colStarts[i+1]; j++)
386 while ( (qterms->
varOneIndexes[swapLoc] != i) && (swapLoc < nq))
402 outStr <<
"swapping locations " << j <<
" and " << swapLoc << std::endl;
404 outStr <<
"after swap:" << std::endl;
405 outStr <<
" var One indexes:";
406 for (
int i=0; i<nq; i++)
409 outStr <<
" var Two indexes:";
410 for (
int i=0; i<nq; i++)
413 outStr <<
" coefficients: ";
414 for (
int i=0; i<nq; i++)
422 throw ErrorClass(
"Sorting of quadratic terms failed in OSCoinSolver");
429 outStr <<
"terminal arrays:" << std::endl;
430 outStr <<
" var One indexes:";
431 for (
int i=0; i<nq; i++)
434 outStr <<
" var Two indexes:";
435 for (
int i=0; i<nq; i++)
438 outStr <<
" coefficients: ";
439 for (
int i=0; i<nq; i++)
447 throw ErrorClass(
"Quadratic terms not implemented yet");
467 std::ostringstream outStr;
475 std::map<std::string, OsiHintParam> hintParamMap;
476 hintParamMap[
"OsiDoPresolveInInitial"] = OsiDoPresolveInInitial;
477 hintParamMap[
"OsiDoDualInInitial"] = OsiDoDualInInitial;
478 hintParamMap[
"OsiDoPresolveInResolve"] = OsiDoPresolveInResolve;
479 hintParamMap[
"OsiDoDualInResolve"] = OsiDoDualInResolve;
480 hintParamMap[
"OsiDoScale"] = OsiDoScale;
481 hintParamMap[
"OsiDoCrash"] = OsiDoCrash;
482 hintParamMap[
"OsiDoReducePrint"] = OsiDoReducePrint;
483 hintParamMap[
"OsiDoInBranchAndCut"] = OsiDoInBranchAndCut;
484 hintParamMap[
"OsiLastHintParam"] = OsiLastHintParam;
487 std::map<std::string, OsiHintStrength> hintStrengthMap;
488 hintStrengthMap[
"OsiHintIgnore"] = OsiHintIgnore;
489 hintStrengthMap[
"OsiHintTry"] = OsiHintTry;
490 hintStrengthMap[
"OsiHintDo"] = OsiHintDo;
491 hintStrengthMap[
"OsiForceDo"] = OsiForceDo;
494 std::map<std::string, OsiStrParam> strParamMap;
495 strParamMap[
"OsiProbName"] = OsiProbName;
496 strParamMap[
"OsiSolverName"] = OsiSolverName;
497 strParamMap[
"OsiLastStrParam"] = OsiLastStrParam;
500 std::map<std::string, OsiDblParam> dblParamMap;
501 dblParamMap[
"OsiDualObjectiveLimit"] = OsiDualObjectiveLimit;
502 dblParamMap[
"OsiPrimalObjectiveLimit"] = OsiPrimalObjectiveLimit;
503 dblParamMap[
"OsiDualTolerance"] = OsiDualTolerance;
504 dblParamMap[
"OsiPrimalTolerance"] = OsiPrimalTolerance;
505 dblParamMap[
"OsiObjOffset"] = OsiObjOffset;
506 dblParamMap[
"OsiLastDblParam"] = OsiLastDblParam;
509 std::map<std::string, OsiIntParam> intParamMap;
510 intParamMap[
"OsiMaxNumIteration"] = OsiMaxNumIteration;
511 intParamMap[
"OsiMaxNumIterationHotStart"] = OsiMaxNumIterationHotStart;
512 intParamMap[
"OsiNameDiscipline"] = OsiNameDiscipline;
513 intParamMap[
"OsiLastIntParam"] = OsiLastIntParam;
520 OsiHintStrength hintStrength = OsiHintTry;
521 osiSolver->setHintParam(OsiDoReducePrint,
true, hintStrength);
527#ifdef COIN_HAS_SYMPHONY
528 if(
sSolverName.find(
"symphony") != std::string::npos)
530 OsiSymSolverInterface * si =
531 dynamic_cast<OsiSymSolverInterface *
>(
osiSolver) ;
532 si->setSymParam(
"verbosity", -2);
563 std::vector<SolverOption*> optionsVector;
567 int num_osi_options = optionsVector.size();
575 for(i = 0; i < num_osi_options; i++)
580 outStr <<
"osi solver option " << optionsVector[ i]->name << std::endl;
581 outStr <<
"osi solver value " << optionsVector[ i]->value << std::endl;
585 if (optionsVector[ i]->type ==
"OsiHintStrength" )
587 if( hintStrengthMap.find( optionsVector[ i]->name ) != hintStrengthMap.end() )
589 hintStrength = hintStrengthMap[ optionsVector[ i]->name] ;
597 for(i = 0; i < num_osi_options; i++)
602 outStr <<
"osi solver option " << optionsVector[ i]->name << std::endl;
603 outStr <<
"osi solver value " << optionsVector[ i]->value << std::endl;
607 if (optionsVector[ i]->type ==
"OsiHintParam" )
609 if( optionsVector[ i]->value ==
"true" )
617 if( hintParamMap.find( optionsVector[ i]->name ) != hintParamMap.end() )
619 osiSolver->setHintParam( hintParamMap[ optionsVector[ i]->name] , yesNo, hintStrength);
622 else if(optionsVector[ i]->type ==
"OsiStrParam" )
624 if( strParamMap.find( optionsVector[ i]->name ) != strParamMap.end() )
626 osiSolver->setStrParam( strParamMap[ optionsVector[ i]->name] , optionsVector[ i]->value);
629 else if(optionsVector[ i]->type ==
"OsiDblParam" )
631 if( dblParamMap.find( optionsVector[ i]->name ) != dblParamMap.end() )
633 osiSolver->setDblParam( dblParamMap[ optionsVector[ i]->name] ,
os_strtod( optionsVector[ i]->value.c_str(), &pEnd ));
637 else if(optionsVector[ i]->type ==
"OsiIntParam" )
639 if( intParamMap.find( optionsVector[ i]->name ) != intParamMap.end() )
641 osiSolver->setIntParam( intParamMap[ optionsVector[ i]->name] , atoi( optionsVector[ i]->value.c_str() ) );
644 else if (optionsVector[ i]->type ==
"bool" )
646 if( optionsVector[ i]->name ==
"primalSimplex" )
648 if (optionsVector[ i]->value !=
"false")
649 osiSolver->enableSimplexInterface((optionsVector[ i]->value !=
"false"));
659 if(optionsVector.size() > 0) optionsVector.clear();
662 int num_cbc_options = optionsVector.size();
664 std::string cbc_option;
670 cstr =
new char [cbc_option.size() + 1];
671 strcpy (cstr, cbc_option.c_str());
674 for(i = 0; i < num_cbc_options; i++)
679 outStr <<
"cbc solver option " << optionsVector[ i]->name << std::endl;
680 outStr <<
"cbc solver value " << optionsVector[ i]->name << std::endl;
685 if(optionsVector[ i]->value.length() > 0 )
687 cbc_option =
"-" + optionsVector[ i]->name +
"="+optionsVector[ i]->value;
691 cbc_option =
"-" + optionsVector[ i]->name ;
693 cstr =
new char [cbc_option.size() + 1];
694 strcpy (cstr, cbc_option.c_str());
699 cbc_option =
"-solve";
700 cstr =
new char [cbc_option.size() + 1];
701 strcpy (cstr, cbc_option.c_str());
705 cbc_option =
"-quit";
706 cstr =
new char [cbc_option.size() + 1];
707 strcpy (cstr, cbc_option.c_str());
714 else if(
sSolverName.find(
"clp") != std::string::npos)
717 if(optionsVector.size() > 0) optionsVector.clear();
720 int num_cbc_options = optionsVector.size();
721 if (num_cbc_options > 0)
724 std::string cbc_option;
730 cstr =
new char [cbc_option.size() + 1];
731 strcpy (cstr, cbc_option.c_str());
734 for(i = 0; i < num_cbc_options; i++)
739 outStr <<
"clp solver option " << optionsVector[ i]->name << std::endl;
740 outStr <<
"clp solver value " << optionsVector[ i]->name << std::endl;
745 if(optionsVector[ i]->value.length() > 0 )
747 cbc_option =
"-" + optionsVector[ i]->name +
"="+optionsVector[ i]->value;
751 cbc_option =
"-" + optionsVector[ i]->name ;
753 cstr =
new char [cbc_option.size() + 1];
754 strcpy (cstr, cbc_option.c_str());
759 cbc_option =
"-solve";
760 cstr =
new char [cbc_option.size() + 1];
761 strcpy (cstr, cbc_option.c_str());
765 cbc_option =
"-quit";
766 cstr =
new char [cbc_option.size() + 1];
767 strcpy (cstr, cbc_option.c_str());
774 else if(
sSolverName.find(
"symphony") != std::string::npos)
776#ifdef COIN_HAS_SYMPHONY
777 if(optionsVector.size() > 0) optionsVector.clear();
779 OsiSymSolverInterface * si =
780 dynamic_cast<OsiSymSolverInterface *
>(
osiSolver) ;
783 int num_sym_options = optionsVector.size();
784 for(i = 0; i < num_sym_options; i++)
789 outStr <<
"symphony solver option " << optionsVector[ i]->name << std::endl;
790 outStr <<
"symphony solver value " << optionsVector[ i]->name << std::endl;
793 if (optionsVector[ i]->type ==
"OsiStrParam" || optionsVector[ i]->type ==
"string")
795 if (!si->setSymParam(optionsVector[ i]->name, optionsVector[ i]->value))
796 throw ErrorClass (
"Failed to set Symphony solver option "+optionsVector[ i]->name);
798 else if (optionsVector[ i]->type ==
"OsiDblParam" || optionsVector[ i]->type ==
"double")
800 if (!si->setSymParam(optionsVector[ i]->name,
os_strtod( optionsVector[ i]->value.c_str(), &pEnd )))
801 throw ErrorClass (
"Failed to set Symphony solver option "+optionsVector[ i]->name);
803 else if (optionsVector[ i]->type ==
"OsiIntParam" || optionsVector[ i]->type ==
"integer")
805 if (!si->setSymParam(optionsVector[ i]->name, atoi( optionsVector[ i]->value.c_str() ) ))
806 throw ErrorClass (
"Failed to set Symphony solver option "+optionsVector[ i]->name);
822 outStr <<
"number of variables initialed: " << m << std::endl;
832 double* denseInitVarVector;
833 denseInitVarVector =
new double[n];
835 initialed =
new bool[n];
837 for(k = 0; k < n; k++)
838 initialed[k] =
false;
846 for(k = 0; k < m; k++)
848 i = initVarVector[k]->
idx;
849 if (initVarVector[k]->idx >= n)
850 throw ErrorClass (
"Illegal index value in variable initialization");
852 initval = initVarVector[k]->
value;
856 throw ErrorClass (
"Initial value outside of bounds");
861 throw ErrorClass (
"Initial value outside of bounds");
867 throw ErrorClass (
"Initial value outside of bounds");
870 denseInitVarVector[initVarVector[k]->
idx] = initval;
871 initialed[initVarVector[k]->idx] =
true;
874 double default_initval;
875 default_initval = 0.0;
877 for(k = 0; k < n; k++)
883 denseInitVarVector[k] = default_initval;
888 denseInitVarVector[k] = default_initval;
893 denseInitVarVector[k] = default_initval;
905 outStr <<
"set initial values: " << std::endl;
906 for (k=0; k < n; k++)
907 outStr <<
" " << k <<
": " << denseInitVarVector[k] << std::endl;
910 osiSolver->setColSolution( denseInitVarVector);
911 delete[] denseInitVarVector;
943 int nsBas,naBas,nsUpp,naUpp,nsLow,naLow,nvar,ncon;
945 CoinWarmStartBasis* warmstart =
new CoinWarmStartBasis();
948 warmstart->setSize(nvar, ncon);
981 tmpBas =
new int[nsBas];
983 for (
int i=0; i<nsBas; i++)
984 warmstart->setStructStatus(tmpBas[i], (CoinWarmStartBasis::Status)0x01);
989 tmpBas =
new int[naBas];
991 for (
int i=0; i<naBas; i++)
992 warmstart->setArtifStatus(tmpBas[i], (CoinWarmStartBasis::Status)0x01);
998 tmpBas =
new int[nsUpp];
1000 for (
int i=0; i<nsUpp; i++)
1001 warmstart->setStructStatus(tmpBas[i], (CoinWarmStartBasis::Status)0x02);
1006 tmpBas =
new int[naUpp];
1008 for (
int i=0; i<naUpp; i++)
1009 warmstart->setArtifStatus(tmpBas[i], (CoinWarmStartBasis::Status)0x02);
1015 tmpBas =
new int[nsLow];
1017 for (
int i=0; i<nsLow; i++)
1018 warmstart->setStructStatus(tmpBas[i], (CoinWarmStartBasis::Status)0x03);
1023 tmpBas =
new int[naLow];
1025 for (
int i=0; i<naLow; i++)
1026 warmstart->setArtifStatus(tmpBas[i], (CoinWarmStartBasis::Status)0x03);
1085 NULL, 0.0, maxGap );
1103 std::ostringstream outStr;
1120 throw ErrorClass(
"OSResult error: SetSolverInvoked");
1122 throw ErrorClass(
"OSResult error: setInstanceName");
1130 throw ErrorClass(
"OSResult error: setVariableNumer");
1132 throw ErrorClass(
"OSResult error: setObjectiveNumber");
1134 throw ErrorClass(
"OSResult error: setConstraintNumber");
1136 throw ErrorClass(
"OSResult error: setSolutionNumer");
1141 double start = CoinCpuTime();
1144 if( (
sSolverName.find(
"cbc") != std::string::npos) ||
1156 std::string cbc_option;
1162 cstr =
new char [cbc_option.size() + 1];
1163 strcpy (cstr, cbc_option.c_str());
1167 cbc_option =
"-log=0";
1168 cstr =
new char [cbc_option.size() + 1];
1169 strcpy (cstr, cbc_option.c_str());
1173 cbc_option =
"-solve";
1174 cstr =
new char [cbc_option.size() + 1];
1175 strcpy (cstr, cbc_option.c_str());
1179 cbc_option =
"-quit";
1180 cstr =
new char [cbc_option.size() + 1];
1181 strcpy (cstr, cbc_option.c_str());
1212 cpuTime = CoinCpuTime() - start;
1215 OsiSolverInterface *solver = model.solver();
1236 cpuTime = CoinCpuTime() - start;
1245 errmsg =
"Coin Solver Error: " + e.message() +
"\n" +
" see method "
1246 + e.methodName() +
" in class " + e.className();
1253 std::string::size_type pos1 = eclass.
errormsg.find(
"<osrl");
1254 if(pos1 == std::string::npos)
1273 if( lcl_osol.find(
"clp") != std::string::npos)
1275 return "coin_solver_glpk";
1279 if( lcl_osol.find(
"cbc") != std::string::npos)
1281 return "coin_solver_cpx";
1285 if( lcl_osol.find(
"cpx") != std::string::npos)
1287 return "coin_solver_clp";
1291 if(lcl_osol.find(
"glpk") != std::string::npos)
1295 else throw ErrorClass(
"a supported solver was not defined");
1336 else cout <<
"problem is a maximization" << endl;
1370 std::vector<int> freeVars;
1371 std::vector<int> basicVars;
1372 std::vector<int> nonBasicLower;
1373 std::vector<int> nonBasicUpper;
1374 std::vector<int>::iterator vit;
1376 basisIdx =
new int*[ 4];
1379 int numberOfVar = solver->getNumCols();
1380 int numberOfCon = solver->getNumRows();
1382 std::string *rcost = NULL;
1383 if ( numberOfVar > 0 ) x =
new double[numberOfVar];
1384 if ( numberOfCon > 0 ) y =
new double[numberOfCon ];
1385 if ( numberOfVar > 0 ) idx =
new int[ numberOfVar];
1386 if ( numberOfVar > 0 ) rcost =
new std::string[numberOfVar];
1390 bool supportsBasis =
false;
1391 if ( (
sSolverName.find(
"clp") != std::string::npos)
1392 || (
sSolverName.find(
"cbc") != std::string::npos)
1393 || (
sSolverName.find(
"cplex") != std::string::npos)
1394 || (
sSolverName.find(
"gurobi") != std::string::npos) )
1396 if (numOfIntVars == 0)
1398 if (numberOfVar > 0) cbasis =
new int[numberOfVar];
1399 if (numberOfCon > 0) rbasis =
new int[numberOfCon];
1400 supportsBasis =
true;
1406 int numberOfOtherVariableResults = 1;
1408 std::string description =
"";
1416 if (solver->isProvenOptimal() ==
true)
1419 if ( supportsBasis )
1421 solver->getBasisStatus( cbasis, rbasis);
1427 if(solver->isProvenPrimalInfeasible() ==
true)
1431 if(solver->isProvenDualInfeasible() ==
true)
1435 if(solver->isPrimalObjectiveLimitReached() ==
true)
1438 if ( supportsBasis )
1440 solver->getBasisStatus( cbasis, rbasis);
1445 if(solver->isDualObjectiveLimitReached() ==
true)
1448 if ( supportsBasis )
1450 solver->getBasisStatus( cbasis, rbasis);
1455 if(solver->isIterationLimitReached() ==
true)
1458 if ( supportsBasis )
1460 solver->getBasisStatus( cbasis, rbasis);
1465 if(solver->isAbandoned() ==
true)
1480 *(z + 0) = solver->getObjValue();
1484 for(i=0; i < numberOfVar; i++)
1486 *(x + i) = solver->getColSolution()[i];
1490 if( (cbasis != NULL) && (solver->isProvenOptimal() ==
true) )
1492 switch (cbasis[ i] )
1497 freeVars.push_back( i);
1504 basicVars.push_back( i);
1511 nonBasicUpper.push_back( i );
1518 nonBasicLower.push_back( i) ;
1522 throw ErrorClass(
"unknown result from Osi getBasisStatus when getting variable basis status");
1531 if(freeVars.size() > 0)
1536 basisIdx[ 0] =
new int[ freeVars.size()];
1538 for(vit = freeVars.begin(); vit < freeVars.end(); vit++)
1540 basisIdx[0][ kount++] = *vit;
1544 delete[] basisIdx[ 0];
1548 if(basicVars.size() > 0)
1552 basisIdx[ 1] =
new int[ basicVars.size()];
1554 for(vit = basicVars.begin(); vit < basicVars.end(); vit++)
1556 basisIdx[1][ kount++] = *vit;
1560 delete[] basisIdx[ 1];
1564 if(nonBasicUpper.size() > 0)
1568 basisIdx[ 2] =
new int[ nonBasicUpper.size()];
1570 for(vit = nonBasicUpper.begin(); vit < nonBasicUpper.end(); vit++)
1572 basisIdx[2][ kount++] = *vit;
1576 delete[] basisIdx[ 2];
1577 nonBasicUpper.clear();
1581 if(nonBasicLower.size() > 0)
1585 basisIdx[ 3] =
new int[ nonBasicLower.size()];
1587 for(vit = nonBasicLower.begin(); vit < nonBasicLower.end(); vit++)
1589 basisIdx[3][ kount++] = *vit;
1593 delete[] basisIdx[ 3];
1594 nonBasicLower.clear();
1602 for(i = 0; i < numberOfCon; i++)
1604 *(y + i) = solver->getRowPrice()[ i];
1607 if((rbasis != NULL) && (solver->isProvenOptimal() ==
true) )
1609 switch (rbasis[ i] )
1614 freeVars.push_back( i);
1621 basicVars.push_back( i);
1628 nonBasicUpper.push_back( i );
1635 nonBasicLower.push_back( i) ;
1639 throw ErrorClass(
"unknown result from Osi getBasisStatus when getting row basis status");
1652 if(freeVars.size() > 0)
1656 basisIdx[ 0] =
new int[ freeVars.size()];
1658 for(vit = freeVars.begin(); vit < freeVars.end(); vit++)
1660 basisIdx[0][ kount++] = *vit;
1664 delete[] basisIdx[ 0];
1668 if(basicVars.size() > 0)
1672 basisIdx[ 1] =
new int[ basicVars.size()];
1674 for(vit = basicVars.begin(); vit < basicVars.end(); vit++)
1676 basisIdx[1][ kount++] = *vit;
1680 delete[] basisIdx[ 1];
1684 if(nonBasicUpper.size() > 0)
1689 basisIdx[ 2] =
new int[ nonBasicUpper.size()];
1691 for(vit = nonBasicUpper.begin(); vit < nonBasicUpper.end(); vit++)
1693 basisIdx[2][ kount++] = *vit;
1697 delete[] basisIdx[ 2];
1698 nonBasicUpper.clear();
1701 if(nonBasicLower.size() > 0)
1705 basisIdx[ 3] =
new int[ nonBasicLower.size()];
1707 for(vit = nonBasicLower.begin(); vit < nonBasicLower.end(); vit++)
1709 basisIdx[3][ kount++] = *vit;
1713 delete[] basisIdx[ 3];
1714 nonBasicLower.clear();
1728 if(numOfIntVars <= 0)
1731 for(i=0; i < numberOfVar; i++)
1735 osresult->
setAnOtherVariableResultSparse(solIdx, otherIdx,
"reduced_costs",
"",
"the variable reduced costs", idx, rcost, solver->getNumCols(),
"",
"double",
"");
1741 temp << solver->getIterationCount();
1743 throw ErrorClass(
"error setting iteration count");
1849 std::string *rcost = NULL;
1851 if( model->getNumCols() > 0 ) x =
new double[model->getNumCols() ];
1852 if( model->getNumRows() > 0 ) y =
new double[model->getNumRows() ];
1853 if( model->getNumCols() > 0 ) idx =
new int[ model->getNumCols() ];
1855 if( model->getNumCols() > 0 ) rcost =
new std::string[ model->getNumCols()];
1857 int numberOfOtherVariableResults = 1;
1859 int numberOfVar = model->getNumCols();
1863 std::string description =
"";
1870 int numberIntegerInfeasibilities = 0;
1871 int numberObjectInfeasibilities = 0;
1872 bool isFeasible =
false;
1873 isFeasible = model->feasibleSolution( numberIntegerInfeasibilities,
1874 numberObjectInfeasibilities);
1875 std::string statusMsg;
1876 if(isFeasible ==
true)
1878 statusMsg =
"feasible";
1882 statusMsg =
"infeasible";
1886 if (model->isProvenOptimal() ==
true )
1892 if(model->isProvenInfeasible() ==
true)
1896 if(model->isProvenDualInfeasible() ==
true)
1900 if(model->isContinuousUnbounded() ==
true)
1904 if(model->isNodeLimitReached() ==
true)
1908 if(model->isSecondsLimitReached() ==
true)
1912 if(model->isSolutionLimitReached() ==
true)
1916 if(model->isAbandoned() ==
true)
1929 if(numOfIntVars > 0) *(z + 0) = model->getObjValue();
1931 for(i=0; i < model->getNumCols(); i++)
1933 *(x + i) = model->getColSolution()[i];
1937 for(i=0; i < model->getNumRows(); i++)
1939 *(y + i) = model->getRowPrice()[ i];
1944 if(numOfIntVars <= 0)
1947 for(i=0; i < numberOfVar; i++)
1956 if(model->getNumCols() > 0)
delete[] x;
1958 if(model->getNumRows() > 0)
delete[] y;
1962 if(model->getNumCols() > 0)
const OSSmartPtr< OSOutput > osoutput
std::string os_dtoa_format(double x)
std::string OSgetVersionInfo()
double os_strtod(const char *s00, char **se)
const char ** cbc_argv
when Cbc is the solver, these are the arguments sent to Cbc Solve
virtual void setSolverOptions()
The implementation of the corresponding virtual function.
virtual void buildSolverInstance()
The implementation of the corresponding virtual function.
int num_cbc_argv
the number of arguments in the argument list to the Cbc Solver
CoinPackedMatrix * m_CoinPackedMatrix
m_CoinPackedMatrix is a Coin Packed Matrix ojbect
std::string getCoinSolverType(std::string osol_)
Get the solver type, e.g. clp or glpk.
OSiLReader * m_osilreader
m_osilreader is an OSiLReader object used to create an osinstance from an osil string if needed
OsiSolverInterface * osiSolver
osiSolver is the osi solver object – in this case clp, glpk, cbc, cplex, symphony or dylp
CoinSolver()
The class constructor.
~CoinSolver()
The class destructor.
OSoLReader * m_osolreader
m_osolreader is an OSoLReader object used to create an osoption from an osol string if needed
void writeResult(OsiSolverInterface *solver)
OSrLWriter * osrlwriter
osrlwriter object used to write osrl from an OSResult object
virtual void solve()
The implementation of the corresponding virtual function.
void dataEchoCheck()
Print out problem parameters.
bool setCoinPackedMatrix()
Create a CoinPackedMatrix.
BasisStatus * initialBasisStatus
initial basis status for the slack variables
std::string sSolverName
sSolverName is the name of the Coin solver used, e.g.
std::string osol
osol holds the options for the solver
bool bSetSolverOptions
bSetSolverOptions is set to true if setSolverOptions has been called, false otherwise
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
bool bCallbuildSolverInstance
bCallbuildSolverInstance is set to true if buildSolverService has been called
std::string osil
osil holds the problem instance as a std::string
OSOption * osoption
osoption holds the solver options in-memory as an OSOption object
OSResult * osresult
osresult holds the solution or result of the model in-memory as an OSResult object
used for throwing exceptions.
std::string errormsg
errormsg is the error that is causing the exception to be thrown
double value
initial value
Variables * variables
variables is a pointer to a Variables object
Objectives * objectives
objectives is a pointer to a Objectives object
double * getConstraintLowerBounds()
Get constraint lower bounds.
int getNumberOfQuadraticTerms()
Get the number of specified (usually nonzero) qTerms in the quadratic coefficients.
double * getVariableUpperBounds()
Get variable upper bounds.
int getNumberOfIntegerVariables()
getNumberOfIntegerVariables
int getNumberOfBinaryVariables()
getNumberOfBinaryVariables
bool getLinearConstraintCoefficientMajor()
Get whether the constraint coefficients is in column major (true) or row major (false).
std::string getInstanceDescription()
Get instance description.
std::string getInstanceSource()
Get instance source.
int getConstraintNumber()
Get number of constraints.
int getNumberOfStringVariables()
getNumberOfStringVariables
int getLinearConstraintCoefficientNumber()
Get number of specified (usually nonzero) linear constraint coefficient values.
int getNumberOfSemiIntegerVariables()
getNumberOfSemiIntegerVariables
SparseMatrix * getLinearConstraintCoefficientsInRowMajor()
Get linear constraint coefficients in row major.
char * getVariableTypes()
Get variable initial values.
SparseMatrix * getLinearConstraintCoefficientsInColumnMajor()
Get linear constraint coefficients in column major.
int getNumberOfSemiContinuousVariables()
getNumberOfSemiContinuousVariables
double ** getDenseObjectiveCoefficients()
getDenseObjectiveCoefficients.
InstanceData * instanceData
A pointer to an InstanceData object.
int getNumberOfNonlinearExpressions()
Get number of nonlinear expressions.
QuadraticTerms * getQuadraticTerms()
Get all the quadratic terms in the instance.
double * getObjectiveConstants()
Get objective constants.
double * getVariableLowerBounds()
Get variable lower bounds.
int getVariableNumber()
Get number of variables.
std::string * getVariableNames()
Get variable names.
std::string getInstanceName()
Get instance name.
std::string * getConstraintNames()
Get constraint names.
std::string * getObjectiveMaxOrMins()
Get objective maxOrMins.
double * getConstraintUpperBounds()
Get constraint upper bounds.
int getObjectiveNumber()
Get number of objectives.
OptimizationOption * optimization
optimizationOption holds the fifth child of the OSOption specified by the OSoL Schema.
InitVarValue ** getInitVarValuesSparse()
Get the initial values associated with the variables in sparse form.
int getNumberOfInitVarValues()
Get the number of initial variable values.
int getNumberOfInitialBasisElements(int type, int status)
Get the number of initial basis elements for a particular variable type and basis status.
std::vector< SolverOption * > getSolverOptions(std::string solver_name)
Get the options associated with a given solver.
int getNumberOfSolverOptions()
Get the number of solver options.
bool getInitialBasisElements(int type, int status, int *elem)
Get the initial basis elements for a particular variable type and basis status.
bool setGeneralMessage(std::string message)
Set the general message.
bool setSolutionNumber(int number)
set the number of solutions.
bool setInstanceName(std::string instanceName)
Set instance name.
bool setObjectiveValuesDense(int solIdx, double *objectiveValues)
Set the [i]th optimization solution's objective values, where i equals the given solution index.
bool setNumberOfOtherVariableResults(int solIdx, int numberOfOtherVariableResults)
Set the [i]th optimization solution's other (non-standard/solver specific) variable-related results,...
bool setGeneralStatusType(std::string type)
Set the general status type, which can be: success, error, warning.
bool setObjectiveNumber(int objectiveNumber)
Set the objective number.
bool setPrimalVariableValuesDense(int solIdx, double *x)
Set the [i]th optimization solution's primal variable values, where i equals the given solution index...
bool setServiceName(std::string serviceName)
Set service name.
bool setSolverInvoked(std::string solverInvoked)
Set solver invoked.
bool setVariableNumber(int variableNumber)
Set the variable number.
bool setTime(double time)
Set time.
bool setDualVariableValuesDense(int solIdx, double *y)
Set the [i]th optimization solution's dual variable values, where i equals the given solution index.
bool setSolutionMessage(int solIdx, std::string msg)
Set the [i]th optimization solution's message, where i equals the given solution index.
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 setAnOtherVariableResultSparse(int solIdx, int otherIdx, std::string name, std::string value, std::string description, int *idx, std::string *s, int n)
Set the [i]th optimization solution's other (non-standard/solver specific)variable-related results,...
bool setConstraintNumber(int constraintNumber)
Set the constraint number.
bool setBasisStatus(int solIdx, int object, int status, int *i, int ni)
Set the basis status of a number of variables/constraints/objectives.
bool setAnOtherSolutionResult(int solIdx, std::string name, std::string value, std::string category, std::string description, int numberOfItems, std::string *item)
Set another solution result of solution [i].
Used to read an OSiL string.
OSInstance * readOSiL(const std::string &osil)
parse the OSiL model instance.
Used to read an OSoL string.
OSOption * readOSoL(const std::string &osol)
parse the OSoL solver options.
Take an OSResult object and write a string that validates against OSrL.
std::string writeOSrL(OSResult *theosresult)
create an osrl string from an OSResult object
int numberOfObjectives
numberOfObjectives is the number of objective functions in the instance
Objective ** obj
coef is pointer to an array of ObjCoef object pointers
VariableOption * variables
the options for the variables
ConstraintOption * constraints
the options for the constraints
a data structure for holding quadratic terms
int * varTwoIndexes
varTwoIndexes holds an integer array of the second variable indexes of all the quadratic terms.
int * rowIndexes
rowIndexes holds an integer array of row indexes of all the quadratic terms.
double * coefficients
coefficients holds a double array all the quadratic term coefficients.
int * varOneIndexes
varOneIndexes holds an integer array of the first variable indexes of all the quadratic terms.
int * indexes
indexes holds an integer array of rowIdx (or colIdx) elements in coefMatrix (AMatrix).
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...
double ub
ub corresponds to the optional attribute that holds the variable upper bound.
double lb
lb corresponds to the optional attribute that holds the variable lower bound.
BasisStatus * initialBasisStatus
initial basis information
Variable ** var
Here we define a pointer to an array of var pointers.
@ ENUM_OUTPUT_LEVEL_detailed_trace
@ ENUM_OUTPUT_LEVEL_debug
@ ENUM_OUTPUT_LEVEL_trace
@ ENUM_OUTPUT_LEVEL_error
@ ENUM_BASIS_STATUS_isFree
@ ENUM_BASIS_STATUS_basic
@ ENUM_BASIS_STATUS_atLower
@ ENUM_BASIS_STATUS_atUpper
@ ENUM_OUTPUT_AREA_OSSolverInterfaces
@ ENUM_PROBLEM_COMPONENT_constraints
@ ENUM_PROBLEM_COMPONENT_variables