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"
37 #ifdef COIN_HAS_SYMPHONY
38 #include "OsiSymSolverInterface.hpp"
42 #include "OsiVolSolverInterface.hpp"
46 #include "OsiDylpSolverInterface.hpp"
50 #include "OsiGlpkSolverInterface.hpp"
54 #include "OsiCpxSolverInterface.hpp"
58 #include "OsiGrbSolverInterface.hpp"
62 #include "OsiMskSolverInterface.hpp"
65 #ifdef COIN_HAS_SOPLEX
66 #include "OsiSpxSolverInterface.hpp"
70 #include "OsiXprSolverInterface.hpp"
74 #include "OSParameters.h"
86 # error "don't have header file for time"
92 using std::ostringstream;
100 m_CoinPackedMatrix(NULL),
147 std::ostringstream outStr;
150 if(
osil.length() == 0 &&
osinstance == NULL)
throw ErrorClass(
"there is no instance");
151 clock_t start, finish;
160 duration = (double) (finish - start) / CLOCKS_PER_SEC;
164 throw ErrorClass(
"Solver cannot handle multiple objectives --- please delete all but one");
177 throw ErrorClass(
"This OSSolverService was built without solver vol");
184 throw ErrorClass(
"This OSSolverService was built without solver cplex");
191 throw ErrorClass(
"This OSSolverService was built without solver gurobi");
198 throw ErrorClass(
"This OSSolverService was built without solver mosek");
202 #ifdef COIN_HAS_SOPLEX
205 throw ErrorClass(
"This OSSolverService was built without solver soplex");
212 throw ErrorClass(
"This OSSolverService was built without solver xpress");
217 osiSolver =
new OsiGlpkSolverInterface();
219 throw ErrorClass(
"This OSSolverService was built without solver glpk");
224 osiSolver =
new OsiDylpSolverInterface();
226 throw ErrorClass(
"This OSSolverService was built without solver dylp");
230 #ifdef COIN_HAS_SYMPHONY
233 throw ErrorClass(
"This OSSolverService was built without solver symphony");
245 throw ErrorClass(
"Solver selected is not supported by this version of OSSolverService");
250 throw ErrorClass(
"This COIN-OR Solver is not configured for nonlinear programming");
256 throw ErrorClass(
"This COIN-OR Solver is not configured for quadratic programming");
262 throw ErrorClass(
"Clp cannot do integer programming");
264 throw ErrorClass(
"Vol cannot do integer programming");
266 throw ErrorClass(
"DyLP cannot do integer programming");
267 if(
sSolverName.find(
"soplex") != std::string::npos)
268 throw ErrorClass(
"SoPlex cannot do integer programming");
273 throw ErrorClass(
"Semi-integer and semi-continuous variables not supported");
283 throw ErrorClass(
"Coin solver: " +
sSolverName +
" needs an objective function");
285 throw ErrorClass(
"Coin solver: " +
sSolverName +
" can only handle numeric variables");
287 throw ErrorClass(
"Coin solver: " +
sSolverName +
" needs a positive number of constraints");
304 if (numOfIntVars > 0)
306 int *intIndex = NULL;
310 intIndex =
new int[ numOfIntVars];
314 if( (varType[i] ==
'B') || (varType[i]) ==
'I' )
319 osiSolver->setInteger( intIndex, numOfIntVars);
329 if ( (
sSolverName.find(
"clp") != std::string::npos) )
337 outStr <<
"original arrays:" << std::endl;
338 outStr <<
" var One indexes:";
339 for (
int i=0; i<nq; i++)
342 outStr <<
" var Two indexes:";
343 for (
int i=0; i<nq; i++)
346 outStr <<
" coefficients: ";
347 for (
int i=0; i<nq; i++)
355 int* colStarts =
new int[ncols+1];
356 for (
int i=0; i<=ncols; i++)
360 for (
int i=0; i<nq; i++)
363 throw ErrorClass(
"Clp solver cannot handle quadratic terms in the constraints");
369 for (
int i=0; i<ncols; i++)
370 colStarts[i+1] += colStarts[i];
378 for (
int i=0; i< ncols-1; i++)
380 swapLoc = colStarts[i+1];
381 for (
int j=colStarts[i];
j<colStarts[i+1];
j++)
385 while ( (qterms->
varOneIndexes[swapLoc] != i) && (swapLoc < nq))
401 outStr <<
"swapping locations " <<
j <<
" and " << swapLoc << std::endl;
403 outStr <<
"after swap:" << std::endl;
404 outStr <<
" var One indexes:";
405 for (
int i=0; i<nq; i++)
408 outStr <<
" var Two indexes:";
409 for (
int i=0; i<nq; i++)
412 outStr <<
" coefficients: ";
413 for (
int i=0; i<nq; i++)
421 throw ErrorClass(
"Sorting of quadratic terms failed in OSCoinSolver");
428 outStr <<
"terminal arrays:" << std::endl;
429 outStr <<
" var One indexes:";
430 for (
int i=0; i<nq; i++)
433 outStr <<
" var Two indexes:";
434 for (
int i=0; i<nq; i++)
437 outStr <<
" coefficients: ";
438 for (
int i=0; i<nq; i++)
446 throw ErrorClass(
"Quadratic terms not implemented yet");
452 catch(
const ErrorClass& eclass)
458 throw ErrorClass(
osrl) ;
466 std::ostringstream outStr;
474 std::map<std::string, OsiHintParam> hintParamMap;
475 hintParamMap[
"OsiDoPresolveInInitial"] = OsiDoPresolveInInitial;
476 hintParamMap[
"OsiDoDualInInitial"] = OsiDoDualInInitial;
477 hintParamMap[
"OsiDoPresolveInResolve"] = OsiDoPresolveInResolve;
478 hintParamMap[
"OsiDoDualInResolve"] = OsiDoDualInResolve;
479 hintParamMap[
"OsiDoScale"] = OsiDoScale;
480 hintParamMap[
"OsiDoCrash"] = OsiDoCrash;
481 hintParamMap[
"OsiDoReducePrint"] = OsiDoReducePrint;
482 hintParamMap[
"OsiDoInBranchAndCut"] = OsiDoInBranchAndCut;
483 hintParamMap[
"OsiLastHintParam"] = OsiLastHintParam;
486 std::map<std::string, OsiHintStrength> hintStrengthMap;
487 hintStrengthMap[
"OsiHintIgnore"] = OsiHintIgnore;
488 hintStrengthMap[
"OsiHintTry"] = OsiHintTry;
489 hintStrengthMap[
"OsiHintDo"] = OsiHintDo;
490 hintStrengthMap[
"OsiForceDo"] = OsiForceDo;
493 std::map<std::string, OsiStrParam> strParamMap;
494 strParamMap[
"OsiProbName"] = OsiProbName;
495 strParamMap[
"OsiSolverName"] = OsiSolverName;
496 strParamMap[
"OsiLastStrParam"] = OsiLastStrParam;
499 std::map<std::string, OsiDblParam> dblParamMap;
500 dblParamMap[
"OsiDualObjectiveLimit"] = OsiDualObjectiveLimit;
501 dblParamMap[
"OsiPrimalObjectiveLimit"] = OsiPrimalObjectiveLimit;
502 dblParamMap[
"OsiDualTolerance"] = OsiDualTolerance;
503 dblParamMap[
"OsiPrimalTolerance"] = OsiPrimalTolerance;
504 dblParamMap[
"OsiObjOffset"] = OsiObjOffset;
505 dblParamMap[
"OsiLastDblParam"] = OsiLastDblParam;
508 std::map<std::string, OsiIntParam> intParamMap;
509 intParamMap[
"OsiMaxNumIteration"] = OsiMaxNumIteration;
510 intParamMap[
"OsiMaxNumIterationHotStart"] = OsiMaxNumIterationHotStart;
511 intParamMap[
"OsiNameDiscipline"] = OsiNameDiscipline;
512 intParamMap[
"OsiLastIntParam"] = OsiLastIntParam;
519 OsiHintStrength hintStrength = OsiHintTry;
520 osiSolver->setHintParam(OsiDoReducePrint,
true, hintStrength);
526 #ifdef COIN_HAS_SYMPHONY
527 if(
sSolverName.find(
"symphony") != std::string::npos)
529 OsiSymSolverInterface * si =
530 dynamic_cast<OsiSymSolverInterface *
>(
osiSolver) ;
531 si->setSymParam(
"verbosity", -2);
533 #endif //symphony end
562 std::vector<SolverOption*> optionsVector;
566 int num_osi_options = optionsVector.size();
574 for(i = 0; i < num_osi_options; i++)
579 outStr <<
"osi solver option " << optionsVector[ i]->name << std::endl;
580 outStr <<
"osi solver value " << optionsVector[ i]->value << std::endl;
584 if (optionsVector[ i]->type ==
"OsiHintStrength" )
586 if( hintStrengthMap.find( optionsVector[ i]->name ) != hintStrengthMap.end() )
588 hintStrength = hintStrengthMap[ optionsVector[ i]->name] ;
596 for(i = 0; i < num_osi_options; i++)
601 outStr <<
"osi solver option " << optionsVector[ i]->name << std::endl;
602 outStr <<
"osi solver value " << optionsVector[ i]->value << std::endl;
606 if (optionsVector[ i]->type ==
"OsiHintParam" )
608 if( optionsVector[ i]->value ==
"true" )
616 if( hintParamMap.find( optionsVector[ i]->name ) != hintParamMap.end() )
618 osiSolver->setHintParam( hintParamMap[ optionsVector[ i]->name] , yesNo, hintStrength);
621 else if(optionsVector[ i]->type ==
"OsiStrParam" )
623 if( strParamMap.find( optionsVector[ i]->name ) != strParamMap.end() )
625 osiSolver->setStrParam( strParamMap[ optionsVector[ i]->name] , optionsVector[ i]->value);
628 else if(optionsVector[ i]->type ==
"OsiDblParam" )
630 if( dblParamMap.find( optionsVector[ i]->name ) != dblParamMap.end() )
632 osiSolver->setDblParam( dblParamMap[ optionsVector[ i]->name] ,
os_strtod( optionsVector[ i]->value.c_str(), &pEnd ));
636 else if(optionsVector[ i]->type ==
"OsiIntParam" )
638 if( intParamMap.find( optionsVector[ i]->name ) != intParamMap.end() )
640 osiSolver->setIntParam( intParamMap[ optionsVector[ i]->name] , atoi( optionsVector[ i]->value.c_str() ) );
643 else if (optionsVector[ i]->type ==
"bool" )
645 if( optionsVector[ i]->name ==
"primalSimplex" )
647 if (optionsVector[ i]->value !=
"false")
648 osiSolver->enableSimplexInterface((optionsVector[ i]->value !=
"false"));
658 if(optionsVector.size() > 0) optionsVector.clear();
661 int num_cbc_options = optionsVector.size();
663 std::string cbc_option;
669 cstr =
new char [cbc_option.size() + 1];
670 strcpy (cstr, cbc_option.c_str());
673 for(i = 0; i < num_cbc_options; i++)
678 outStr <<
"cbc solver option " << optionsVector[ i]->name << std::endl;
679 outStr <<
"cbc solver value " << optionsVector[ i]->name << std::endl;
684 if(optionsVector[ i]->value.length() > 0 )
686 cbc_option =
"-" + optionsVector[ i]->name +
"="+optionsVector[ i]->value;
690 cbc_option =
"-" + optionsVector[ i]->name ;
692 cstr =
new char [cbc_option.size() + 1];
693 strcpy (cstr, cbc_option.c_str());
694 cbc_argv[i + 1] = cstr;
698 cbc_option =
"-solve";
699 cstr =
new char [cbc_option.size() + 1];
700 strcpy (cstr, cbc_option.c_str());
704 cbc_option =
"-quit";
705 cstr =
new char [cbc_option.size() + 1];
706 strcpy (cstr, cbc_option.c_str());
713 else if(
sSolverName.find(
"clp") != std::string::npos)
716 if(optionsVector.size() > 0) optionsVector.clear();
719 int num_cbc_options = optionsVector.size();
720 if (num_cbc_options > 0)
723 std::string cbc_option;
729 cstr =
new char [cbc_option.size() + 1];
730 strcpy (cstr, cbc_option.c_str());
733 for(i = 0; i < num_cbc_options; i++)
738 outStr <<
"clp solver option " << optionsVector[ i]->name << std::endl;
739 outStr <<
"clp solver value " << optionsVector[ i]->name << std::endl;
744 if(optionsVector[ i]->value.length() > 0 )
746 cbc_option =
"-" + optionsVector[ i]->name +
"="+optionsVector[ i]->value;
750 cbc_option =
"-" + optionsVector[ i]->name ;
752 cstr =
new char [cbc_option.size() + 1];
753 strcpy (cstr, cbc_option.c_str());
754 cbc_argv[i + 1] = cstr;
758 cbc_option =
"-solve";
759 cstr =
new char [cbc_option.size() + 1];
760 strcpy (cstr, cbc_option.c_str());
764 cbc_option =
"-quit";
765 cstr =
new char [cbc_option.size() + 1];
766 strcpy (cstr, cbc_option.c_str());
773 else if(
sSolverName.find(
"symphony") != std::string::npos)
775 #ifdef COIN_HAS_SYMPHONY
776 if(optionsVector.size() > 0) optionsVector.clear();
778 OsiSymSolverInterface * si =
779 dynamic_cast<OsiSymSolverInterface *
>(
osiSolver) ;
782 int num_sym_options = optionsVector.size();
783 for(i = 0; i < num_sym_options; i++)
788 outStr <<
"symphony solver option " << optionsVector[ i]->name << std::endl;
789 outStr <<
"symphony solver value " << optionsVector[ i]->name << std::endl;
792 if (optionsVector[ i]->type ==
"OsiStrParam" || optionsVector[ i]->type ==
"string")
794 if (!si->setSymParam(optionsVector[ i]->name, optionsVector[ i]->value))
795 throw ErrorClass (
"Failed to set Symphony solver option "+optionsVector[ i]->name);
797 else if (optionsVector[ i]->type ==
"OsiDblParam" || optionsVector[ i]->type ==
"double")
799 if (!si->setSymParam(optionsVector[ i]->name,
os_strtod( optionsVector[ i]->value.c_str(), &pEnd )))
800 throw ErrorClass (
"Failed to set Symphony solver option "+optionsVector[ i]->name);
802 else if (optionsVector[ i]->type ==
"OsiIntParam" || optionsVector[ i]->type ==
"integer")
804 if (!si->setSymParam(optionsVector[ i]->name, atoi( optionsVector[ i]->value.c_str() ) ))
805 throw ErrorClass (
"Failed to set Symphony solver option "+optionsVector[ i]->name);
808 #endif //symphony end
821 outStr <<
"number of variables initialed: " << m << std::endl;
831 double* denseInitVarVector;
832 denseInitVarVector =
new double[
n];
834 initialed =
new bool[
n];
836 for(k = 0; k <
n; k++)
837 initialed[k] =
false;
845 for(k = 0; k <
m; k++)
847 i = initVarVector[
k]->
idx;
848 if (initVarVector[k]->idx >= n)
849 throw ErrorClass (
"Illegal index value in variable initialization");
851 initval = initVarVector[
k]->
value;
855 throw ErrorClass (
"Initial value outside of bounds");
860 throw ErrorClass (
"Initial value outside of bounds");
866 throw ErrorClass (
"Initial value outside of bounds");
869 denseInitVarVector[initVarVector[
k]->
idx] = initval;
870 initialed[initVarVector[
k]->idx] =
true;
873 double default_initval;
874 default_initval = 0.0;
876 for(k = 0; k <
n; k++)
882 denseInitVarVector[
k] = default_initval;
887 denseInitVarVector[
k] = default_initval;
892 denseInitVarVector[
k] = default_initval;
904 outStr <<
"set initial values: " << std::endl;
905 for (k=0; k <
n; k++)
906 outStr <<
" " << k <<
": " << denseInitVarVector[k] << std::endl;
909 osiSolver->setColSolution( denseInitVarVector);
910 delete[] denseInitVarVector;
942 int nsBas,naBas,nsUpp,naUpp,nsLow,naLow,nvar,ncon;
944 CoinWarmStartBasis* warmstart =
new CoinWarmStartBasis();
947 warmstart->setSize(nvar, ncon);
980 tmpBas =
new int[nsBas];
982 for (
int i=0; i<nsBas; i++)
983 warmstart->setStructStatus(tmpBas[i], (CoinWarmStartBasis::Status)0x01);
988 tmpBas =
new int[naBas];
990 for (
int i=0; i<naBas; i++)
991 warmstart->setArtifStatus(tmpBas[i], (CoinWarmStartBasis::Status)0x01);
997 tmpBas =
new int[nsUpp];
999 for (
int i=0; i<nsUpp; i++)
1000 warmstart->setStructStatus(tmpBas[i], (CoinWarmStartBasis::Status)0x02);
1005 tmpBas =
new int[naUpp];
1007 for (
int i=0; i<naUpp; i++)
1008 warmstart->setArtifStatus(tmpBas[i], (CoinWarmStartBasis::Status)0x02);
1014 tmpBas =
new int[nsLow];
1016 for (
int i=0; i<nsLow; i++)
1017 warmstart->setStructStatus(tmpBas[i], (CoinWarmStartBasis::Status)0x03);
1022 tmpBas =
new int[naLow];
1024 for (
int i=0; i<naLow; i++)
1025 warmstart->setArtifStatus(tmpBas[i], (CoinWarmStartBasis::Status)0x03);
1041 catch(
const ErrorClass& eclass)
1048 throw ErrorClass(
osrl) ;
1084 NULL, 0.0, maxGap );
1102 std::ostringstream outStr;
1112 catch(
const ErrorClass& eclass)
1114 throw ErrorClass(
osrl) ;
1119 throw ErrorClass(
"OSResult error: SetSolverInvoked");
1121 throw ErrorClass(
"OSResult error: setInstanceName");
1129 throw ErrorClass(
"OSResult error: setVariableNumer");
1131 throw ErrorClass(
"OSResult error: setObjectiveNumber");
1133 throw ErrorClass(
"OSResult error: setConstraintNumber");
1135 throw ErrorClass(
"OSResult error: setSolutionNumer");
1140 double start = CoinCpuTime();
1143 if( (
sSolverName.find(
"cbc") != std::string::npos) ||
1155 std::string cbc_option;
1161 cstr =
new char [cbc_option.size() + 1];
1162 strcpy (cstr, cbc_option.c_str());
1166 cbc_option =
"-log=0";
1167 cstr =
new char [cbc_option.size() + 1];
1168 strcpy (cstr, cbc_option.c_str());
1169 cbc_argv[ 1] = cstr;
1172 cbc_option =
"-solve";
1173 cstr =
new char [cbc_option.size() + 1];
1174 strcpy (cstr, cbc_option.c_str());
1175 cbc_argv[ 2] = cstr;
1178 cbc_option =
"-quit";
1179 cstr =
new char [cbc_option.size() + 1];
1180 strcpy (cstr, cbc_option.c_str());
1181 cbc_argv[ 3] = cstr;
1196 CbcMain1( num_cbc_argv,
cbc_argv, model);
1204 if( num_cbc_argv > 0)
1211 cpuTime = CoinCpuTime() - start;
1214 OsiSolverInterface *solver = model.solver();
1235 cpuTime = CoinCpuTime() - start;
1244 errmsg =
"Coin Solver Error: " + e.message() +
"\n" +
" see method "
1245 + e.methodName() +
" in class " + e.className();
1246 throw ErrorClass( errmsg );
1250 catch(
const ErrorClass& eclass)
1252 std::string::size_type pos1 = eclass.
errormsg.find(
"<osrl");
1253 if(pos1 == std::string::npos)
1263 throw ErrorClass(
osrl);
1272 if( lcl_osol.find(
"clp") != std::string::npos)
1274 return "coin_solver_glpk";
1278 if( lcl_osol.find(
"cbc") != std::string::npos)
1280 return "coin_solver_cpx";
1284 if( lcl_osol.find(
"cpx") != std::string::npos)
1286 return "coin_solver_clp";
1290 if(lcl_osol.find(
"glpk") != std::string::npos)
1294 else throw ErrorClass(
"a supported solver was not defined");
1335 else cout <<
"problem is a maximization" << endl;
1369 std::vector<int> freeVars;
1370 std::vector<int> basicVars;
1371 std::vector<int> nonBasicLower;
1372 std::vector<int> nonBasicUpper;
1373 std::vector<int>::iterator vit;
1375 basisIdx =
new int*[ 4];
1378 int numberOfVar = solver->getNumCols();
1379 int numberOfCon = solver->getNumRows();
1381 std::string *rcost = NULL;
1382 if ( numberOfVar > 0 ) x =
new double[numberOfVar];
1383 if ( numberOfCon > 0 ) y =
new double[numberOfCon ];
1384 if ( numberOfVar > 0 ) idx =
new int[ numberOfVar];
1385 if ( numberOfVar > 0 ) rcost =
new std::string[numberOfVar];
1389 bool supportsBasis =
false;
1390 if ( (
sSolverName.find(
"clp") != std::string::npos)
1391 || (
sSolverName.find(
"cbc") != std::string::npos)
1392 || (
sSolverName.find(
"cplex") != std::string::npos)
1393 || (
sSolverName.find(
"gurobi") != std::string::npos) )
1395 if (numOfIntVars == 0)
1397 if (numberOfVar > 0) cbasis =
new int[numberOfVar];
1398 if (numberOfCon > 0) rbasis =
new int[numberOfCon];
1399 supportsBasis =
true;
1405 int numberOfOtherVariableResults = 1;
1407 std::string description =
"";
1415 if (solver->isProvenOptimal() ==
true)
1418 if ( supportsBasis )
1420 solver->getBasisStatus( cbasis, rbasis);
1426 if(solver->isProvenPrimalInfeasible() ==
true)
1430 if(solver->isProvenDualInfeasible() ==
true)
1434 if(solver->isPrimalObjectiveLimitReached() ==
true)
1437 if ( supportsBasis )
1439 solver->getBasisStatus( cbasis, rbasis);
1444 if(solver->isDualObjectiveLimitReached() ==
true)
1447 if ( supportsBasis )
1449 solver->getBasisStatus( cbasis, rbasis);
1454 if(solver->isIterationLimitReached() ==
true)
1457 if ( supportsBasis )
1459 solver->getBasisStatus( cbasis, rbasis);
1464 if(solver->isAbandoned() ==
true)
1479 *(z + 0) = solver->getObjValue();
1483 for(i=0; i < numberOfVar; i++)
1485 *(x + i) = solver->getColSolution()[i];
1489 if( (cbasis != NULL) && (solver->isProvenOptimal() ==
true) )
1491 switch (cbasis[ i] )
1496 freeVars.push_back( i);
1503 basicVars.push_back( i);
1510 nonBasicUpper.push_back( i );
1517 nonBasicLower.push_back( i) ;
1521 throw ErrorClass(
"unknown result from Osi getBasisStatus when getting variable basis status");
1530 if(freeVars.size() > 0)
1535 basisIdx[ 0] =
new int[ freeVars.size()];
1537 for(vit = freeVars.begin(); vit < freeVars.end(); vit++)
1539 basisIdx[0][ kount++] = *vit;
1543 delete[] basisIdx[ 0];
1547 if(basicVars.size() > 0)
1551 basisIdx[ 1] =
new int[ basicVars.size()];
1553 for(vit = basicVars.begin(); vit < basicVars.end(); vit++)
1555 basisIdx[1][ kount++] = *vit;
1559 delete[] basisIdx[ 1];
1563 if(nonBasicUpper.size() > 0)
1567 basisIdx[ 2] =
new int[ nonBasicUpper.size()];
1569 for(vit = nonBasicUpper.begin(); vit < nonBasicUpper.end(); vit++)
1571 basisIdx[2][ kount++] = *vit;
1575 delete[] basisIdx[ 2];
1576 nonBasicUpper.clear();
1580 if(nonBasicLower.size() > 0)
1584 basisIdx[ 3] =
new int[ nonBasicLower.size()];
1586 for(vit = nonBasicLower.begin(); vit < nonBasicLower.end(); vit++)
1588 basisIdx[3][ kount++] = *vit;
1592 delete[] basisIdx[ 3];
1593 nonBasicLower.clear();
1601 for(i = 0; i < numberOfCon; i++)
1603 *(y + i) = solver->getRowPrice()[ i];
1606 if((rbasis != NULL) && (solver->isProvenOptimal() ==
true) )
1608 switch (rbasis[ i] )
1613 freeVars.push_back( i);
1620 basicVars.push_back( i);
1627 nonBasicUpper.push_back( i );
1634 nonBasicLower.push_back( i) ;
1638 throw ErrorClass(
"unknown result from Osi getBasisStatus when getting row basis status");
1651 if(freeVars.size() > 0)
1655 basisIdx[ 0] =
new int[ freeVars.size()];
1657 for(vit = freeVars.begin(); vit < freeVars.end(); vit++)
1659 basisIdx[0][ kount++] = *vit;
1663 delete[] basisIdx[ 0];
1667 if(basicVars.size() > 0)
1671 basisIdx[ 1] =
new int[ basicVars.size()];
1673 for(vit = basicVars.begin(); vit < basicVars.end(); vit++)
1675 basisIdx[1][ kount++] = *vit;
1679 delete[] basisIdx[ 1];
1683 if(nonBasicUpper.size() > 0)
1688 basisIdx[ 2] =
new int[ nonBasicUpper.size()];
1690 for(vit = nonBasicUpper.begin(); vit < nonBasicUpper.end(); vit++)
1692 basisIdx[2][ kount++] = *vit;
1696 delete[] basisIdx[ 2];
1697 nonBasicUpper.clear();
1700 if(nonBasicLower.size() > 0)
1704 basisIdx[ 3] =
new int[ nonBasicLower.size()];
1706 for(vit = nonBasicLower.begin(); vit < nonBasicLower.end(); vit++)
1708 basisIdx[3][ kount++] = *vit;
1712 delete[] basisIdx[ 3];
1713 nonBasicLower.clear();
1727 if(numOfIntVars <= 0)
1730 for(i=0; i < numberOfVar; i++)
1734 osresult->
setAnOtherVariableResultSparse(solIdx, otherIdx,
"reduced_costs",
"",
"the variable reduced costs", idx, rcost, solver->getNumCols(),
"",
"double",
"");
1740 temp << solver->getIterationCount();
1742 throw ErrorClass(
"error setting iteration count");
1848 std::string *rcost = NULL;
1850 if( model->getNumCols() > 0 ) x =
new double[model->getNumCols() ];
1851 if( model->getNumRows() > 0 ) y =
new double[model->getNumRows() ];
1852 if( model->getNumCols() > 0 ) idx =
new int[ model->getNumCols() ];
1854 if( model->getNumCols() > 0 ) rcost =
new std::string[ model->getNumCols()];
1856 int numberOfOtherVariableResults = 1;
1858 int numberOfVar = model->getNumCols();
1862 std::string description =
"";
1869 int numberIntegerInfeasibilities = 0;
1870 int numberObjectInfeasibilities = 0;
1871 bool isFeasible =
false;
1872 isFeasible = model->feasibleSolution( numberIntegerInfeasibilities,
1873 numberObjectInfeasibilities);
1874 std::string statusMsg;
1875 if(isFeasible ==
true)
1877 statusMsg =
"feasible";
1881 statusMsg =
"infeasible";
1885 if (model->isProvenOptimal() == true )
1891 if(model->isProvenInfeasible() ==
true)
1895 if(model->isProvenDualInfeasible() ==
true)
1899 if(model->isContinuousUnbounded() ==
true)
1903 if(model->isNodeLimitReached() ==
true)
1907 if(model->isSecondsLimitReached() ==
true)
1911 if(model->isSolutionLimitReached() ==
true)
1915 if(model->isAbandoned() ==
true)
1928 if(numOfIntVars > 0) *(z + 0) = model->getObjValue();
1930 for(i=0; i < model->getNumCols(); i++)
1932 *(x + i) = model->getColSolution()[i];
1936 for(i=0; i < model->getNumRows(); i++)
1938 *(y + i) = model->getRowPrice()[ i];
1943 if(numOfIntVars <= 0)
1946 for(i=0; i < numberOfVar; i++)
1955 if(model->getNumCols() > 0)
delete[] x;
1957 if(model->getNumRows() > 0)
delete[] y;
1961 if(model->getNumCols() > 0)
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.
std::string OSgetVersionInfo()
double os_strtod(const char *s00, char **se)
int getNumberOfInitVarValues()
Get the number of initial variable values.
int getNumberOfIntegerVariables()
getNumberOfIntegerVariables
char * getVariableTypes()
Get variable initial values.
~CoinSolver()
The class destructor.
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...
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].
const OSSmartPtr< OSOutput > osoutput
int getVariableNumber()
Get number of variables.
std::string osrl
osrl holds the solution or result of the model
bool setServiceName(std::string serviceName)
Set service name.
int getNumberOfSemiContinuousVariables()
getNumberOfSemiContinuousVariables
bool setVariableNumber(int variableNumber)
Set the variable number.
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
OsiSolverInterface * osiSolver
osiSolver is the osi solver object – in this case clp, glpk, cbc, cplex, symphony or dylp ...
int getLinearConstraintCoefficientNumber()
Get number of specified (usually nonzero) linear constraint coefficient values.
std::vector< SolverOption * > getSolverOptions(std::string solver_name)
Get the options associated with a given solver.
CoinPackedMatrix * m_CoinPackedMatrix
m_CoinPackedMatrix is a Coin Packed Matrix ojbect
bool setSolverInvoked(std::string solverInvoked)
Set solver invoked.
bool bCallbuildSolverInstance
bCallbuildSolverInstance is set to true if buildSolverService has been called
bool setTime(double time)
Set time.
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...
Take an OSResult object and write a string that validates against OSrL.
OSResult * osresult
osresult holds the solution or result of the model in-memory as an OSResult object ...
ConstraintOption * constraints
the options for the constraints
bool bSetSolverOptions
bSetSolverOptions is set to true if setSolverOptions has been called, false otherwise ...
bool setDualVariableValuesDense(int solIdx, double *y)
Set the [i]th optimization solution's dual variable values, where i equals the given solution index...
int getObjectiveNumber()
Get number of objectives.
bool setObjectiveNumber(int objectiveNumber)
Set the objective number.
bool setInstanceName(std::string instanceName)
Set instance name.
bool getInitialBasisElements(int type, int status, int *elem)
Get the initial basis elements for a particular variable type and basis status.
bool setSolutionMessage(int solIdx, std::string msg)
Set the [i]th optimization solution's message, where i equals the given solution index.
OSInstance * readOSiL(const std::string &osil)
parse the OSiL model instance.
std::string * getVariableNames()
Get variable names.
CoinSolver()
The class constructor.
int getNumberOfNonlinearExpressions()
Get number of nonlinear expressions.
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
virtual void buildSolverInstance()
The implementation of the corresponding virtual function.
int * indexes
indexes holds an integer array of rowIdx (or colIdx) elements in coefMatrix (AMatrix).
std::string osol
osol holds the options for the solver
int getNumberOfStringVariables()
getNumberOfStringVariables
bool setSolutionNumber(int number)
set the number of solutions.
std::string getCoinSolverType(std::string osol_)
Get the solver type, e.g. clp or glpk.
double ** getDenseObjectiveCoefficients()
getDenseObjectiveCoefficients.
bool setBasisStatus(int solIdx, int object, int status, int *i, int ni)
Set the basis status of a number of variables/constraints/objectives.
void fint fint fint real fint real real real real real real real real real * e
BasisStatus * initialBasisStatus
initial basis information
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...
const char ** cbc_argv
when Cbc is the solver, these are the arguments sent to Cbc Solve
void writeResult(OsiSolverInterface *solver)
OSiLReader * m_osilreader
m_osilreader is an OSiLReader object used to create an osinstance from an osil string if needed ...
double lb
lb corresponds to the optional attribute that holds the variable lower bound.
Variable ** var
Here we define a pointer to an array of var pointers.
int num_cbc_argv
the number of arguments in the argument list to the Cbc Solver
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.
double value
initial value
OSOption * osoption
osoption holds the solver options in-memory as an OSOption object
std::string * getObjectiveMaxOrMins()
Get objective maxOrMins.
bool setCoinPackedMatrix()
Create a CoinPackedMatrix.
double ub
ub corresponds to the optional attribute that holds the variable upper bound.
Variables * variables
variables is a pointer to a Variables object
OSoLReader * m_osolreader
m_osolreader is an OSoLReader object used to create an osoption from an osol string if needed ...
SparseMatrix * getLinearConstraintCoefficientsInColumnMajor()
Get linear constraint coefficients in column major.
OSOption * readOSoL(const std::string &osol)
parse the OSoL solver options.
bool setGeneralMessage(std::string message)
Set the general message.
double * values
values holds a double array of value elements in coefMatrix (AMatrix), which contains nonzero element...
OSInstance * osinstance
osinstance holds the problem instance in-memory as an OSInstance object
double * getObjectiveConstants()
Get objective constants.
bool setGeneralStatusType(std::string type)
Set the general status type, which can be: success, error, warning.
std::string getInstanceName()
Get instance name.
InstanceData * instanceData
A pointer to an InstanceData object.
VariableOption * variables
the options for the variables
OSrLWriter * osrlwriter
osrlwriter object used to write osrl from an OSResult object
int getConstraintNumber()
Get number of constraints.
Objective ** obj
coef is pointer to an array of ObjCoef object pointers
bool getLinearConstraintCoefficientMajor()
Get whether the constraint coefficients is in column major (true) or row major (false).
bool setConstraintNumber(int constraintNumber)
Set the constraint number.
std::string sSolverName
sSolverName is the name of the Coin solver used, e.g.
int getNumberOfSolverOptions()
Get the number of solver options.
int getNumberOfQuadraticTerms()
Get the number of specified (usually nonzero) qTerms in the quadratic coefficients.
Used to read an OSoL string.
Objectives * objectives
objectives is a pointer to a Objectives object
std::string getInstanceSource()
Get instance source.
InitVarValue ** getInitVarValuesSparse()
Get the initial values associated with the variables in sparse form.
int * rowIndexes
rowIndexes holds an integer array of row indexes of all the quadratic terms.
std::string os_dtoa_format(double x)
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.
void dataEchoCheck()
Print out problem parameters.
OptimizationOption * optimization
optimizationOption holds the fifth child of the OSOption specified by the OSoL Schema.
bool setObjectiveValuesDense(int solIdx, double *objectiveValues)
Set the [i]th optimization solution's objective values, where i equals the given solution index...
BasisStatus * initialBasisStatus
initial basis status for the slack variables
virtual void solve()
The implementation of the corresponding virtual function.
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...
std::string * getConstraintNames()
Get constraint names.
used for throwing exceptions.
int getNumberOfSemiIntegerVariables()
getNumberOfSemiIntegerVariables
virtual void setSolverOptions()
The implementation of the corresponding virtual function.
int getNumberOfInitialBasisElements(int type, int status)
Get the number of initial basis elements for a particular variable type and basis status...
int getNumberOfBinaryVariables()
getNumberOfBinaryVariables
std::string getInstanceDescription()
Get instance description.
void fint fint fint real fint real * x