OSCoinSolver.cpp
Go to the documentation of this file.
1 /* $Id: OSCoinSolver.cpp 5012 2015-05-07 04:35:51Z Gassmann $ */
19 #include "OSCoinSolver.h"
20 #include "OSInstance.h"
21 #include "OSFileUtil.h"
22 #include "OSOutput.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" //for CbcSOS
31 #include "CoinMessageHandler.hpp"
32 #include "CoinMessage.hpp"
33 
34 #include "OsiClpSolverInterface.hpp"
35 #include "CoinWarmStartBasis.hpp"
36 
37 #ifdef COIN_HAS_SYMPHONY
38 #include "OsiSymSolverInterface.hpp"
39 #endif
40 
41 #ifdef COIN_HAS_VOL
42 #include "OsiVolSolverInterface.hpp"
43 #endif
44 
45 #ifdef COIN_HAS_DYLP
46 #include "OsiDylpSolverInterface.hpp"
47 #endif
48 
49 #ifdef COIN_HAS_GLPK
50 #include "OsiGlpkSolverInterface.hpp"
51 #endif
52 
53 #ifdef COIN_HAS_CPX
54 #include "OsiCpxSolverInterface.hpp"
55 #endif
56 
57 #ifdef COIN_HAS_GRB
58 #include "OsiGrbSolverInterface.hpp"
59 #endif
60 
61 #ifdef COIN_HAS_MSK
62 #include "OsiMskSolverInterface.hpp"
63 #endif
64 
65 #ifdef COIN_HAS_SOPLEX
66 #include "OsiSpxSolverInterface.hpp"
67 #endif
68 
69 #ifdef COIN_HAS_XPR
70 #include "OsiXprSolverInterface.hpp"
71 #endif
72 
73 #include "OSGeneral.h"
74 #include "OSParameters.h"
75 #include "OSMathUtil.h"
76 
77 #include <map>
78 
79 #include <iostream>
80 #ifdef HAVE_CTIME
81 # include <ctime>
82 #else
83 # ifdef HAVE_TIME_H
84 # include <time.h>
85 # else
86 # error "don't have header file for time"
87 # endif
88 #endif
89 
90 using std::cout;
91 using std::endl;
92 using std::ostringstream;
93 
94 
95 
97  osiSolver(NULL),
98  m_osilreader(NULL),
99  m_osolreader(NULL),
100  m_CoinPackedMatrix(NULL),
101  cbc_argv( NULL),
102  num_cbc_argv( 0),
103  cpuTime( 0)
104 {
105  osrlwriter = new OSrLWriter();
106 }
107 
109 {
110 #ifndef NDEBUG
112  ENUM_OUTPUT_LEVEL_debug, "inside CoinSolver destructor\n");
113 #endif
114  if(m_osilreader != NULL) delete m_osilreader;
115  m_osilreader = NULL;
116  if(m_osolreader != NULL) delete m_osolreader;
117  m_osolreader = NULL;
118  delete m_CoinPackedMatrix;
119  m_CoinPackedMatrix = NULL;
120  delete osiSolver;
121  if(osiSolver != NULL) osiSolver = NULL;
122  delete osrlwriter;
123  osrlwriter = NULL;
124  delete osresult;
125  osresult = NULL;
126  if(num_cbc_argv > 0)
127  {
128 /* -----
129  int i;
130  for(i = 0; i < num_cbc_argv; i++)
131  {
132  delete cbc_argv[ i];
133  }
134  delete[] cbc_argv;
135  ----- */
136  cbc_argv = NULL;
137  }
138 #ifndef NDEBUG
140  ENUM_OUTPUT_LEVEL_trace, "Leaving CoinSolver destructor\n");
141 #endif
142 }
143 
144 
146 {
147  std::ostringstream outStr;
148  try
149  {
150  if(osil.length() == 0 && osinstance == NULL) throw ErrorClass("there is no instance");
151  clock_t start, finish;
152  double duration;
153  start = clock();
154  if(osinstance == NULL)
155  {
156  m_osilreader = new OSiLReader();
158  }
159  finish = clock();
160  duration = (double) (finish - start) / CLOCKS_PER_SEC;
161 
162  // Can't handle multiobjective problems properly --- especially nonlinear ones
163  if (osinstance->getObjectiveNumber() > 1)
164  throw ErrorClass("Solver cannot handle multiple objectives --- please delete all but one");
165 
166  // get the type of solver requested from OSoL string
167  if (sSolverName == "clp")
168  osiSolver = new OsiClpSolverInterface();
169 
170  else if (sSolverName == "cbc")
171  osiSolver = new OsiClpSolverInterface();
172 
173  else if (sSolverName == "vol")
174  #ifdef COIN_HAS_VOL
175  osiSolver = new OsiVolSolverInterface();
176  #else
177  throw ErrorClass("This OSSolverService was built without solver vol");
178  #endif
179 
180  else if (sSolverName == "cplex")
181  #ifdef COIN_HAS_CPX
182  osiSolver = new OsiCpxSolverInterface();
183  #else
184  throw ErrorClass("This OSSolverService was built without solver cplex");
185  #endif
186 
187  else if (sSolverName == "gurobi")
188  #ifdef COIN_HAS_GRB
189  osiSolver = new OsiGrbSolverInterface();
190  #else
191  throw ErrorClass("This OSSolverService was built without solver gurobi");
192  #endif
193 
194  else if (sSolverName == "mosek")
195  #ifdef COIN_HAS_MSK
196  osiSolver = new OsiMskSolverInterface();
197  #else
198  throw ErrorClass("This OSSolverService was built without solver mosek");
199  #endif
200 
201  else if (sSolverName == "soplex")
202  #ifdef COIN_HAS_SOPLEX
203  osiSolver = new OsiSpxSolverInterface();
204  #else
205  throw ErrorClass("This OSSolverService was built without solver soplex");
206  #endif
207 
208  else if (sSolverName == "xpress")
209  #ifdef COIN_HAS_XPR
210  osiSolver = new OsiXprSolverInterface();
211  #else
212  throw ErrorClass("This OSSolverService was built without solver xpress");
213  #endif
214 
215  else if (sSolverName == "glpk")
216  #ifdef COIN_HAS_GLPK
217  osiSolver = new OsiGlpkSolverInterface();
218  #else
219  throw ErrorClass("This OSSolverService was built without solver glpk");
220  #endif
221 
222  else if (sSolverName == "dylp")
223  #ifdef COIN_HAS_DYLP
224  osiSolver = new OsiDylpSolverInterface();
225  #else
226  throw ErrorClass("This OSSolverService was built without solver dylp");
227  #endif
228 
229  else if (sSolverName == "symphony")
230  #ifdef COIN_HAS_SYMPHONY
231  osiSolver = new OsiSymSolverInterface();
232  #else
233  throw ErrorClass("This OSSolverService was built without solver symphony");
234  #endif
235 
236  else if (sSolverName == "")
237  { // default solver is Clp in continuous case,
238  // Cbc for an integer program
240  sSolverName.find( "cbc") != std::string::npos ) sSolverName = "cbc";
241  else sSolverName = "clp";
242  osiSolver = new OsiClpSolverInterface();
243  }
244  else
245  throw ErrorClass("Solver selected is not supported by this version of OSSolverService");
246 
247  // first check the various solvers and see if they support the given problem type
249  {
250  throw ErrorClass( "This COIN-OR Solver is not configured for nonlinear programming");
251  }
252  if ((osinstance->getNumberOfQuadraticTerms() > 0) &&
253  (sSolverName.find( "cbc") == std::string::npos) &&
254  (sSolverName.find( "clp") == std::string::npos))
255  {
256  throw ErrorClass( "This COIN-OR Solver is not configured for quadratic programming");
257  }
258  // throw an exception if we have a solver that cannot do integer programming
260  {
261  if( sSolverName.find("clp") != std::string::npos)
262  throw ErrorClass( "Clp cannot do integer programming");
263  if( sSolverName.find("vol") != std::string::npos)
264  throw ErrorClass( "Vol cannot do integer programming");
265  if( sSolverName.find("dylp") != std::string::npos)
266  throw ErrorClass( "DyLP cannot do integer programming");
267  if( sSolverName.find("soplex") != std::string::npos)
268  throw ErrorClass( "SoPlex cannot do integer programming");
269  }
270  // throw an exception if we have a solver that cannot handle semi-continuous or semi-integer variables
272  {
273  throw ErrorClass( "Semi-integer and semi-continuous variables not supported");
274  //if( sSolverName.find("clp") != std::string::npos) throw ErrorClass( "Clp cannot do semi-integer variables");
275  //if( sSolverName.find("vol") != std::string::npos) throw ErrorClass( "Vol cannot do semi-integer variables");
276  //if( sSolverName.find("dylp") != std::string::npos) throw ErrorClass( "DyLP cannot do semi-integer variables");
277  //if( sSolverName.find("soplex") != std::string::npos) throw ErrorClass( "SoPlex cannot do semi-integer variables");
278  }
279  // check other trivial solver limitations
280  //if(osinstance->getConstraintNumber() <= 0)throw ErrorClass("Coin solver:" + sSolverName +" cannot handle unconstrained problems");
281  //if(osinstance->getVariableNumber() <= 0)throw ErrorClass("Coin solver requires decision variables");
282  if(osinstance->getObjectiveNumber() <= 0)
283  throw ErrorClass("Coin solver: " + sSolverName + " needs an objective function");
285  throw ErrorClass("Coin solver: " + sSolverName + " can only handle numeric variables");
286  if(osinstance->getLinearConstraintCoefficientNumber() <= 0 && sSolverName == "symphony")
287  throw ErrorClass("Coin solver: " + sSolverName + " needs a positive number of constraints");
288 
289  if(!setCoinPackedMatrix() ) throw ErrorClass("Problem generating coin packed matrix");
295  );
296 #ifndef NDEBUG
297  //dataEchoCheck();
298 #endif
299  if( osinstance->getObjectiveMaxOrMins()[0] == "min") osiSolver->setObjSense(1.0);
300  else osiSolver->setObjSense(-1.0);
301  // set the integer variables
302  int numOfIntVars
304  if (numOfIntVars > 0)
305  {
306  int *intIndex = NULL;
307  int i = 0;
308  int k = 0;
309  char *varType;
310  intIndex = new int[ numOfIntVars];
311  varType = osinstance->getVariableTypes();
312  for(i = 0; i < osinstance->getVariableNumber(); i++)
313  {
314  if( (varType[i] == 'B') || (varType[i]) == 'I' )
315  {
316  intIndex[k++] = i;
317  }
318  }
319  osiSolver->setInteger( intIndex, numOfIntVars);
320 
321  delete[] intIndex;
322  intIndex = NULL;
323  }
324 
325  // the clpSolver supports quadratic objectives if present in the input
327  if (nq > 0)
328  {
329  if ( (sSolverName.find("clp") != std::string::npos) )
330  {
331  // get quadratic data, verify objective terms only, convert to sparse matrix format
333 
334 #ifndef NDEBUG
335  outStr.str("");
336  outStr.clear();
337  outStr << "original arrays:" << std::endl;
338  outStr << " var One indexes:";
339  for (int i=0; i<nq; i++)
340  outStr << " " << qterms->varOneIndexes[i];
341  outStr << std::endl;
342  outStr << " var Two indexes:";
343  for (int i=0; i<nq; i++)
344  outStr << " " << qterms->varTwoIndexes[i];
345  outStr << std::endl;
346  outStr << " coefficients: ";
347  for (int i=0; i<nq; i++)
348  outStr << " " << qterms->coefficients[i];
349  outStr << std::endl;
351  ENUM_OUTPUT_LEVEL_trace, outStr.str());
352 #endif
353 
354  int ncols = osinstance->getVariableNumber();
355  int* colStarts = new int[ncols+1];
356  for (int i=0; i<=ncols; i++)
357  colStarts[i] = 0;
358 
359  //get column lengths
360  for (int i=0; i<nq; i++)
361  {
362  if (qterms->rowIndexes[i] != -1)
363  throw ErrorClass("Clp solver cannot handle quadratic terms in the constraints");
364  else
365  colStarts[qterms->varOneIndexes[i]+1] += 1;
366  }
367 
368  // convert column lengths to column starts
369  for (int i=0; i<ncols; i++)
370  colStarts[i+1] += colStarts[i];
371 
372  // sort the varOneIndexes array in ascending order
373  // assumptions: 1. Most likely the quadratic terms are sorted already
374  // 2. The order of varTwoIndexes within varOneIndexes does not matter
375  int swapLoc;
376  int iswap;
377  double dswap;
378  for (int i=0; i< ncols-1; i++)
379  {
380  swapLoc = colStarts[i+1];
381  for (int j=colStarts[i]; j<colStarts[i+1]; j++)
382  {
383  if (qterms->varOneIndexes[j] != i)
384  {
385  while ( (qterms->varOneIndexes[swapLoc] != i) && (swapLoc < nq))
386  swapLoc++;
387  if (swapLoc < nq)
388  {
389  iswap = qterms->varOneIndexes[j];
390  qterms->varOneIndexes[j] = qterms->varOneIndexes[swapLoc];
391  qterms->varOneIndexes[swapLoc] = iswap;
392  iswap = qterms->varTwoIndexes[j];
393  qterms->varTwoIndexes[j] = qterms->varTwoIndexes[swapLoc];
394  qterms->varTwoIndexes[swapLoc] = iswap;
395  dswap = qterms->coefficients[j];
396  qterms->coefficients[j] = qterms->coefficients[swapLoc];
397  qterms->coefficients[swapLoc] = dswap;
398 #ifndef NDEBUG
399  outStr.str("");
400  outStr.clear();
401  outStr << "swapping locations " << j << " and " << swapLoc << std::endl;
402 
403  outStr << "after swap:" << std::endl;
404  outStr << " var One indexes:";
405  for (int i=0; i<nq; i++)
406  outStr << " " << qterms->varOneIndexes[i];
407  outStr << std::endl;
408  outStr << " var Two indexes:";
409  for (int i=0; i<nq; i++)
410  outStr << " " << qterms->varTwoIndexes[i];
411  outStr << std::endl;
412  outStr << " coefficients: ";
413  for (int i=0; i<nq; i++)
414  outStr << " " << qterms->coefficients[i];
415  outStr << std::endl;
417  ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
418 #endif
419  }
420  else
421  throw ErrorClass("Sorting of quadratic terms failed in OSCoinSolver");
422  }
423  }
424  }
425 #ifndef NDEBUG
426  outStr.str("");
427  outStr.clear();
428  outStr << "terminal arrays:" << std::endl;
429  outStr << " var One indexes:";
430  for (int i=0; i<nq; i++)
431  outStr << " " << qterms->varOneIndexes[i];
432  outStr << std::endl;
433  outStr << " var Two indexes:";
434  for (int i=0; i<nq; i++)
435  outStr << " " << qterms->varTwoIndexes[i];
436  outStr << std::endl;
437  outStr << " coefficients: ";
438  for (int i=0; i<nq; i++)
439  outStr << " " << qterms->coefficients[i];
440  outStr << std::endl;
442  ENUM_OUTPUT_LEVEL_trace, outStr.str());
443 #endif
444 
445  //osiSolver->loadQuadraticObjective(ncols, colStarts, qterms->varTwoIndexes, qterms->coefficients);
446  throw ErrorClass("Quadratic terms not implemented yet");
447  }
448  }
449 
451  }
452  catch(const ErrorClass& eclass)
453  {
454  osresult = new OSResult();
456  osresult->setGeneralStatusType( "error");
458  throw ErrorClass( osrl) ;
459  }
460 }//end buildSolverInstance()
461 
462 
463 
465 {
466  std::ostringstream outStr;
467 
468 #ifndef NDEBUG
469  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSSolverInterfaces, ENUM_OUTPUT_LEVEL_debug, "build solver options\n");
470 #endif
471  this->bSetSolverOptions = true;
472  // the osi maps (NOTE: These are the only options supported by generic OsiSolverInterface)
473  // the OsiHintParameter Map
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;
484  //
485  // the OsiHintStrength Map
486  std::map<std::string, OsiHintStrength> hintStrengthMap;
487  hintStrengthMap["OsiHintIgnore"] = OsiHintIgnore;
488  hintStrengthMap["OsiHintTry"] = OsiHintTry;
489  hintStrengthMap["OsiHintDo"] = OsiHintDo;
490  hintStrengthMap["OsiForceDo"] = OsiForceDo;
491  //
492  // the OsiStrParam Map
493  std::map<std::string, OsiStrParam> strParamMap;
494  strParamMap["OsiProbName"] = OsiProbName;
495  strParamMap["OsiSolverName"] = OsiSolverName;
496  strParamMap["OsiLastStrParam"] = OsiLastStrParam;
497  //
498  // the OsiDblParam Map
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;
506  //
507  // the OsiIntParam Map
508  std::map<std::string, OsiIntParam> intParamMap;
509  intParamMap["OsiMaxNumIteration"] = OsiMaxNumIteration;
510  intParamMap["OsiMaxNumIterationHotStart"] = OsiMaxNumIterationHotStart;
511  intParamMap["OsiNameDiscipline"] = OsiNameDiscipline;
512  intParamMap["OsiLastIntParam"] = OsiLastIntParam;
513 
514  /*
515  * start default settings -- these get set
516  * even when the OSOption object is NULL
517  *
518  * */
519  OsiHintStrength hintStrength = OsiHintTry; //don't want too much output
520  osiSolver->setHintParam(OsiDoReducePrint, true, hintStrength);
521  // it looks like the COIN-OR default is to subtract off the constant rather than add it.
522  // this seems true regardless of max or min
523  osiSolver->setDblParam(OsiObjOffset, -osinstance->getObjectiveConstants()[0]);
524 
525  // Set SYMPHONY default print level
526 #ifdef COIN_HAS_SYMPHONY
527  if( sSolverName.find( "symphony") != std::string::npos)
528  {
529  OsiSymSolverInterface * si =
530  dynamic_cast<OsiSymSolverInterface *>(osiSolver) ;
531  si->setSymParam("verbosity", -2);
532  }
533 #endif //symphony end
534  /*
535  * end default settings
536  *
537  */
538 
539  // read option string if necessary
540  try
541  {
542  if(osoption == NULL && osol.length() > 0)
543  {
544  m_osolreader = new OSoLReader();
546  }
547 
548 // Process any options found
549  if(osoption != NULL)
550  {
551  int i;
552 
553 #ifndef NDEBUG
554  outStr.str("");
555  outStr.clear();
556  outStr << "number of solver options " << osoption->getNumberOfSolverOptions() << std::endl;
558 #endif
560  {
561  //this->bSetSolverOptions = true;
562  std::vector<SolverOption*> optionsVector;
563 
564  //get the osi options, which apply to all solvers
565  optionsVector = osoption->getSolverOptions( "osi",true);
566  int num_osi_options = optionsVector.size();
567  char *pEnd;
568  bool yesNo;
569 
574  for(i = 0; i < num_osi_options; i++)
575  {
576 #ifndef NDEBUG
577  outStr.str("");
578  outStr.clear();
579  outStr << "osi solver option " << optionsVector[ i]->name << std::endl;
580  outStr << "osi solver value " << optionsVector[ i]->value << std::endl;
582  ENUM_OUTPUT_LEVEL_trace, outStr.str());
583 #endif
584  if (optionsVector[ i]->type == "OsiHintStrength" )
585  {
586  if( hintStrengthMap.find( optionsVector[ i]->name ) != hintStrengthMap.end() )
587  {
588  hintStrength = hintStrengthMap[ optionsVector[ i]->name] ;
589  }
590  }
591  }
592 
596  for(i = 0; i < num_osi_options; i++)
597  {
598 #ifndef NDEBUG
599  outStr.str("");
600  outStr.clear();
601  outStr << "osi solver option " << optionsVector[ i]->name << std::endl;
602  outStr << "osi solver value " << optionsVector[ i]->value << std::endl;
604  ENUM_OUTPUT_LEVEL_trace, outStr.str());
605 #endif
606  if (optionsVector[ i]->type == "OsiHintParam" )
607  {
608  if( optionsVector[ i]->value == "true" )
609  {
610  yesNo = true;
611  }
612  else
613  {
614  yesNo = false;
615  }
616  if( hintParamMap.find( optionsVector[ i]->name ) != hintParamMap.end() )
617  {
618  osiSolver->setHintParam( hintParamMap[ optionsVector[ i]->name] , yesNo, hintStrength);
619  }
620  }
621  else if(optionsVector[ i]->type == "OsiStrParam" )
622  {
623  if( strParamMap.find( optionsVector[ i]->name ) != strParamMap.end() )
624  {
625  osiSolver->setStrParam( strParamMap[ optionsVector[ i]->name] , optionsVector[ i]->value);
626  }
627  }
628  else if(optionsVector[ i]->type == "OsiDblParam" )
629  {
630  if( dblParamMap.find( optionsVector[ i]->name ) != dblParamMap.end() )
631  {
632  osiSolver->setDblParam( dblParamMap[ optionsVector[ i]->name] , os_strtod( optionsVector[ i]->value.c_str(), &pEnd ));
633  }
634 
635  }
636  else if(optionsVector[ i]->type == "OsiIntParam" )
637  {
638  if( intParamMap.find( optionsVector[ i]->name ) != intParamMap.end() )
639  {
640  osiSolver->setIntParam( intParamMap[ optionsVector[ i]->name] , atoi( optionsVector[ i]->value.c_str() ) );
641  }
642  }
643  else if (optionsVector[ i]->type == "bool" )
644  {
645  if( optionsVector[ i]->name == "primalSimplex" )
646  {
647  if (optionsVector[ i]->value != "false")
648  osiSolver->enableSimplexInterface((optionsVector[ i]->value != "false"));
649  }
650  }
651  }
652 
653  // Next get all options that are specific to one solver
654 
655  if( sSolverName.find( "cbc") != std::string::npos)
656  {
657  // get Cbc options and create a command line for CbcMain1()
658  if(optionsVector.size() > 0) optionsVector.clear();
659  optionsVector = osoption->getSolverOptions( "cbc",true);
660 
661  int num_cbc_options = optionsVector.size();
662  char *cstr;
663  std::string cbc_option;
664  num_cbc_argv = optionsVector.size() + 3;
665  cbc_argv = new const char*[ num_cbc_argv];
666 
667  // the first option
668  cbc_option = "OS";
669  cstr = new char [cbc_option.size() + 1];
670  strcpy (cstr, cbc_option.c_str());
671  cbc_argv[ 0] = cstr;
672 
673  for(i = 0; i < num_cbc_options; i++)
674  {
675 #ifndef NDEBUG
676  outStr.str("");
677  outStr.clear();
678  outStr << "cbc solver option " << optionsVector[ i]->name << std::endl;
679  outStr << "cbc solver value " << optionsVector[ i]->name << std::endl;
681  ENUM_OUTPUT_LEVEL_debug, outStr.str());
682 #endif
683 
684  if(optionsVector[ i]->value.length() > 0 )
685  {
686  cbc_option = "-" + optionsVector[ i]->name +"="+optionsVector[ i]->value;
687  }
688  else
689  {
690  cbc_option = "-" + optionsVector[ i]->name ;
691  }
692  cstr = new char [cbc_option.size() + 1];
693  strcpy (cstr, cbc_option.c_str());
694  cbc_argv[i + 1] = cstr;
695  }
696 
697  // the solve option
698  cbc_option = "-solve";
699  cstr = new char [cbc_option.size() + 1];
700  strcpy (cstr, cbc_option.c_str());
701  cbc_argv[ num_cbc_argv - 2] = cstr;
702 
703  // the quit option
704  cbc_option = "-quit";
705  cstr = new char [cbc_option.size() + 1];
706  strcpy (cstr, cbc_option.c_str());
707  cbc_argv[ num_cbc_argv - 1] = cstr;
708 
709  }//end of cbc if
710 
711  // Here we look for options specific to Clp. Use the Cbc interface if there are any
712 
713  else if( sSolverName.find( "clp") != std::string::npos)
714  {
715  // get Clp options and create a command line for CbcMain1()
716  if(optionsVector.size() > 0) optionsVector.clear();
717  optionsVector = osoption->getSolverOptions( "clp",true);
718 
719  int num_cbc_options = optionsVector.size();
720  if (num_cbc_options > 0)
721  {
722  char *cstr;
723  std::string cbc_option;
724  num_cbc_argv = optionsVector.size() + 3;
725  cbc_argv = new const char*[ num_cbc_argv];
726 
727  // the first option
728  cbc_option = "OS";
729  cstr = new char [cbc_option.size() + 1];
730  strcpy (cstr, cbc_option.c_str());
731  cbc_argv[ 0] = cstr;
732 
733  for(i = 0; i < num_cbc_options; i++)
734  {
735 #ifndef NDEBUG
736  outStr.str("");
737  outStr.clear();
738  outStr << "clp solver option " << optionsVector[ i]->name << std::endl;
739  outStr << "clp solver value " << optionsVector[ i]->name << std::endl;
741  ENUM_OUTPUT_LEVEL_debug, outStr.str());
742 #endif
743 
744  if(optionsVector[ i]->value.length() > 0 )
745  {
746  cbc_option = "-" + optionsVector[ i]->name +"="+optionsVector[ i]->value;
747  }
748  else
749  {
750  cbc_option = "-" + optionsVector[ i]->name ;
751  }
752  cstr = new char [cbc_option.size() + 1];
753  strcpy (cstr, cbc_option.c_str());
754  cbc_argv[i + 1] = cstr;
755  }
756 
757  // the solve option
758  cbc_option = "-solve";
759  cstr = new char [cbc_option.size() + 1];
760  strcpy (cstr, cbc_option.c_str());
761  cbc_argv[ num_cbc_argv - 2] = cstr;
762 
763  // the quit option
764  cbc_option = "-quit";
765  cstr = new char [cbc_option.size() + 1];
766  strcpy (cstr, cbc_option.c_str());
767  cbc_argv[ num_cbc_argv - 1] = cstr;
768  }
769  }
770 
771  // Options for SYMPHONY
772 
773  else if( sSolverName.find( "symphony") != std::string::npos)
774  {
775 #ifdef COIN_HAS_SYMPHONY
776  if(optionsVector.size() > 0) optionsVector.clear();
777  //first the number of processors -- applies only to SYMPHONY
778  OsiSymSolverInterface * si =
779  dynamic_cast<OsiSymSolverInterface *>(osiSolver) ;
780 
781  optionsVector = osoption->getSolverOptions( "symphony",true);
782  int num_sym_options = optionsVector.size();
783  for(i = 0; i < num_sym_options; i++)
784  {
785 #ifndef NDEBUG
786  outStr.str("");
787  outStr.clear();
788  outStr << "symphony solver option " << optionsVector[ i]->name << std::endl;
789  outStr << "symphony solver value " << optionsVector[ i]->name << std::endl;
791 #endif
792  if (optionsVector[ i]->type == "OsiStrParam" || optionsVector[ i]->type == "string")
793  {
794  if (!si->setSymParam(optionsVector[ i]->name, optionsVector[ i]->value))
795  throw ErrorClass ("Failed to set Symphony solver option "+optionsVector[ i]->name);
796  }
797  else if (optionsVector[ i]->type == "OsiDblParam" || optionsVector[ i]->type == "double")
798  {
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);
801  }
802  else if (optionsVector[ i]->type == "OsiIntParam" || optionsVector[ i]->type == "integer")
803  {
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);
806  }
807  }
808 #endif //symphony end
809  }
810  }
811 
812  //now set initial values
813  int n,m,k;
814  if (osoption != NULL)
816  else
817  m = 0;
818 #ifndef NDEBUG
819  outStr.str("");
820  outStr.clear();
821  outStr << "number of variables initialed: " << m << std::endl;
823 #endif
824 
825  if (m > 0)
826  {
827 #ifndef NDEBUG
828  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSSolverInterfaces, ENUM_OUTPUT_LEVEL_debug, "get initial values\n");
829 #endif
831  double* denseInitVarVector;
832  denseInitVarVector = new double[n];
833  bool* initialed;
834  initialed = new bool[n];
835 
836  for(k = 0; k < n; k++)
837  initialed[k] = false;
838 
839  InitVarValue** initVarVector = osoption->getInitVarValuesSparse();
840 #ifndef NDEBUG
842 #endif
843 
844  double initval;
845  for(k = 0; k < m; k++)
846  {
847  i = initVarVector[k]->idx;
848  if (initVarVector[k]->idx >= n)
849  throw ErrorClass ("Illegal index value in variable initialization");
850 
851  initval = initVarVector[k]->value;
853  {
854  if (osinstance->instanceData->variables->var[k]->lb > initval)
855  throw ErrorClass ("Initial value outside of bounds");
856  }
857  else if (osinstance->instanceData->variables->var[k]->lb == -OSDBL_MAX)
858  {
859  if (osinstance->instanceData->variables->var[k]->ub < initval)
860  throw ErrorClass ("Initial value outside of bounds");
861  }
862  else
863  {
864  if ((osinstance->instanceData->variables->var[k]->lb > initval) ||
865  (osinstance->instanceData->variables->var[k]->ub < initval))
866  throw ErrorClass ("Initial value outside of bounds");
867  }
868 
869  denseInitVarVector[initVarVector[k]->idx] = initval;
870  initialed[initVarVector[k]->idx] = true;
871  }
872 
873  double default_initval;
874  default_initval = 0.0;
875 
876  for(k = 0; k < n; k++)
877  {
878  if (!initialed[k])
879  {
881  if (osinstance->instanceData->variables->var[k]->lb <= default_initval)
882  denseInitVarVector[k] = default_initval;
883  else
884  denseInitVarVector[k] = osinstance->instanceData->variables->var[k]->lb;
885  else if (osinstance->instanceData->variables->var[k]->lb == -OSDBL_MAX)
886  if (osinstance->instanceData->variables->var[k]->ub >= default_initval)
887  denseInitVarVector[k] = default_initval;
888  else
889  denseInitVarVector[k] = osinstance->instanceData->variables->var[k]->ub;
890  else if ((osinstance->instanceData->variables->var[k]->lb <= default_initval) &&
891  (osinstance->instanceData->variables->var[k]->ub >= default_initval))
892  denseInitVarVector[k] = default_initval;
893  else if (osinstance->instanceData->variables->var[k]->lb > default_initval)
894  denseInitVarVector[k] = osinstance->instanceData->variables->var[k]->lb;
895  else
896  denseInitVarVector[k] = osinstance->instanceData->variables->var[k]->ub;
897  }
898 // denseInitVarVector[k] = default_initval;
899 // denseInitVarVector[k] = osinstance->instanceData->variables->var[k]->lb;
900  }
901 #ifndef NDEBUG
902  outStr.str("");
903  outStr.clear();
904  outStr << "set initial values: " << std::endl;
905  for (k=0; k < n; k++)
906  outStr << " " << k << ": " << denseInitVarVector[k] << std::endl;
908 #endif
909  osiSolver->setColSolution( denseInitVarVector);
910  delete[] denseInitVarVector;
911  delete[] initialed;
912 #ifndef NDEBUG
914 #endif
915 
916  } // end set initial variable values
917 
918 
919  // add starting basis --- only supported by Clp
920 
921 // if (sSolverName == "clp" || sSolverName == "cbc")
922  {
923  if ( osoption != NULL &&
924  osoption->optimization != NULL &&
925  ((osoption->optimization->variables != NULL &&
927  (osoption->optimization->constraints != NULL &&
929 
930  /* Only the following statuses are recognized:
931  *
932  * enum Status {
933  * isFree = 0x00, ///< Nonbasic free variable
934  * basic = 0x01, ///< Basic variable
935  * atUpperBound = 0x02, ///< Nonbasic at upper bound
936  * atLowerBound = 0x03 ///< Nonbasic at lower bound
937  * }
938  *
939  * Any others, or any missing statuses, are set to isFree; let Clp deal with it.
940  */
941  {
942  int nsBas,naBas,nsUpp,naUpp,nsLow,naLow,nvar,ncon;
943  int* tmpBas = NULL;
944  CoinWarmStartBasis* warmstart = new CoinWarmStartBasis();
945  nvar = osinstance->getVariableNumber();
947  warmstart->setSize(nvar, ncon); // this initials everything to isFree
948 
949  // pull the number of basis elements of each type
950  if ( osoption->optimization->variables != NULL &&
952  {
956  }
957  else
958  {
959  nsBas = 0;
960  nsUpp = 0;
961  nsLow = 0;
962  }
963  if ( osoption->optimization->constraints != NULL &&
965  {
969  }
970  else
971  {
972  naBas = 0;
973  naUpp = 0;
974  naLow = 0;
975  }
976 
977  // get the elements and store them into the Clp warm start object
978  if (nsBas > 0)
979  {
980  tmpBas = new int[nsBas];
982  for (int i=0; i<nsBas; i++)
983  warmstart->setStructStatus(tmpBas[i], (CoinWarmStartBasis::Status)0x01);
984  delete [] tmpBas;
985  }
986  if (naBas > 0)
987  {
988  tmpBas = new int[naBas];
990  for (int i=0; i<naBas; i++)
991  warmstart->setArtifStatus(tmpBas[i], (CoinWarmStartBasis::Status)0x01);
992  delete [] tmpBas;
993  }
994 
995  if (nsUpp > 0)
996  {
997  tmpBas = new int[nsUpp];
999  for (int i=0; i<nsUpp; i++)
1000  warmstart->setStructStatus(tmpBas[i], (CoinWarmStartBasis::Status)0x02);
1001  delete [] tmpBas;
1002  }
1003  if (naUpp > 0)
1004  {
1005  tmpBas = new int[naUpp];
1007  for (int i=0; i<naUpp; i++)
1008  warmstart->setArtifStatus(tmpBas[i], (CoinWarmStartBasis::Status)0x02);
1009  delete [] tmpBas;
1010  }
1011 
1012  if (nsLow > 0)
1013  {
1014  tmpBas = new int[nsLow];
1016  for (int i=0; i<nsLow; i++)
1017  warmstart->setStructStatus(tmpBas[i], (CoinWarmStartBasis::Status)0x03);
1018  delete [] tmpBas;
1019  }
1020  if (naLow > 0)
1021  {
1022  tmpBas = new int[naLow];
1024  for (int i=0; i<naLow; i++)
1025  warmstart->setArtifStatus(tmpBas[i], (CoinWarmStartBasis::Status)0x03);
1026  delete [] tmpBas;
1027  }
1028 
1029  osiSolver->setWarmStart(warmstart);
1030 
1031  } // end if (some basis info available)
1032  } // end if solver = clp
1033 
1034  }// end of osoption if
1035 
1036 #ifndef NDEBUG
1037  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSSolverInterfaces, ENUM_OUTPUT_LEVEL_debug, "solver options set\n");
1038 #endif
1039  }//end of try
1040 
1041  catch(const ErrorClass& eclass)
1042  {
1043  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSSolverInterfaces, ENUM_OUTPUT_LEVEL_error, "THERE IS AN ERROR\n");
1044  osresult = new OSResult();
1046  osresult->setGeneralStatusType( "error");
1048  throw ErrorClass( osrl) ;
1049  }
1050 }//end setSolverOptions()
1051 
1052 
1054 {
1055  bool columnMajor = osinstance->getLinearConstraintCoefficientMajor();
1056  try
1057  {
1058  double maxGap = 0;
1060  {
1061  m_CoinPackedMatrix = new CoinPackedMatrix(
1062  columnMajor, //Column or Row Major
1063  columnMajor? osinstance->getConstraintNumber() : osinstance->getVariableNumber(), //Minor Dimension
1064  columnMajor? osinstance->getVariableNumber() : osinstance->getConstraintNumber(), //Major Dimension
1065  osinstance->getLinearConstraintCoefficientNumber(), //Number of nonzeroes
1067  columnMajor? osinstance->getLinearConstraintCoefficientsInColumnMajor()->indexes : osinstance->getLinearConstraintCoefficientsInRowMajor()->indexes, //Pointer to start of minor dimension indexes -- change to allow for row storage
1069  0, 0, maxGap );
1070  }
1071  else
1072  {
1073  int* start = new int[osinstance->getVariableNumber()+1];
1074  for (int i=0; i <= osinstance->getVariableNumber(); i++)
1075  start[i] = 0;
1076  m_CoinPackedMatrix = new CoinPackedMatrix(
1077  columnMajor, //Column or Row Major
1078  columnMajor? osinstance->getConstraintNumber() : osinstance->getVariableNumber(), //Minor Dimension
1079  columnMajor? osinstance->getVariableNumber() : osinstance->getConstraintNumber(), //Major Dimension
1080  osinstance->getLinearConstraintCoefficientNumber(), //Number of nonzeroes
1081  NULL, //Pointer to matrix nonzeroes
1082  NULL, //Pointer to start of minor dimension indexes -- change to allow for row storage
1083  start, //Pointers to start of columns.
1084  NULL, 0.0, maxGap );
1085  }
1086 
1087 
1088  return true;
1089  }
1090  catch(const ErrorClass& eclass)
1091  {
1092  osresult = new OSResult();
1094  osresult->setGeneralStatusType( "error");
1096  throw ErrorClass( osrl) ;
1097  }
1098 } // end setCoinPackedMatrix
1099 
1101 {
1102  std::ostringstream outStr;
1103  if(osresult != NULL) delete osresult;
1104  osresult = new OSResult();
1105  try
1106  {
1107  // make sure the solver instance exists
1108  if( this->bCallbuildSolverInstance == false) buildSolverInstance();
1109  //set the options
1110  if( this->bSetSolverOptions == false) setSolverOptions();
1111  }
1112  catch(const ErrorClass& eclass)
1113  {
1114  throw ErrorClass( osrl) ;
1115  }
1116 
1117  // resultHeader information
1118  if(osresult->setSolverInvoked("COIN-OR " + sSolverName) != true)
1119  throw ErrorClass("OSResult error: SetSolverInvoked");
1121  throw ErrorClass("OSResult error: setInstanceName");
1122  //if(osresult->setJobID( osresultdata->jobID) != true)
1123  // throw ErrorClass("OSResult error: setJobID");
1124  //if(osresult->setGeneralMessage( osresultdata->message) != true)
1125  // throw ErrorClass("OSResult error: setGeneralMessage");
1126  // set basic problem parameters
1127 
1129  throw ErrorClass("OSResult error: setVariableNumer");
1130  if(osresult->setObjectiveNumber( 1) != true)
1131  throw ErrorClass("OSResult error: setObjectiveNumber");
1133  throw ErrorClass("OSResult error: setConstraintNumber");
1134  if(osresult->setSolutionNumber( 1) != true)
1135  throw ErrorClass("OSResult error: setSolutionNumer");
1136 
1137  //
1138  try
1139  {
1140  double start = CoinCpuTime();
1141  try
1142  {
1143  if( (sSolverName.find( "cbc") != std::string::npos) ||
1144  ((sSolverName.find( "clp") != std::string::npos) && num_cbc_argv > 0) )
1145  {
1146  // just use simple branch and bound for anything but cbc
1147  CbcModel model( *osiSolver);
1148 
1149  CbcMain0( model);
1150 
1151  // make sure we define cbc_argv if not done already when reading options
1152  if(num_cbc_argv <= 0)
1153  {
1154  char *cstr;
1155  std::string cbc_option;
1156  num_cbc_argv = 4;
1157  cbc_argv = new const char*[ num_cbc_argv];
1158 
1159  // the first option
1160  cbc_option = "OS";
1161  cstr = new char [cbc_option.size() + 1];
1162  strcpy (cstr, cbc_option.c_str());
1163  cbc_argv[ 0] = cstr;
1164 
1165  // the log option -- by default minimal printing
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;
1170 
1171  // the solve option
1172  cbc_option = "-solve";
1173  cstr = new char [cbc_option.size() + 1];
1174  strcpy (cstr, cbc_option.c_str());
1175  cbc_argv[ 2] = cstr;
1176 
1177  // the quit option
1178  cbc_option = "-quit";
1179  cstr = new char [cbc_option.size() + 1];
1180  strcpy (cstr, cbc_option.c_str());
1181  cbc_argv[ 3] = cstr;
1182  }
1183  int i;
1184 
1186  ENUM_OUTPUT_LEVEL_info, "CALLING THE CBC SOLVER CBCMAIN1()\n");
1187 #ifndef NDEBUG
1188  outStr.str("");
1189  outStr.clear();
1190  for(i = 0; i < num_cbc_argv; i++)
1191  {
1192  outStr << sSolverName << " option: " << cbc_argv[ i] << std::endl;
1193  }
1195 #endif
1196  CbcMain1( num_cbc_argv, cbc_argv, model);
1197 
1198  //do the garbage collection on cbc_argv
1199  for(i = 0; i < num_cbc_argv; i++)
1200  {
1201  delete[] cbc_argv[ i];
1202  cbc_argv[i] = NULL;
1203  }
1204  if( num_cbc_argv > 0)
1205  {
1206  delete[] cbc_argv;
1207  cbc_argv = NULL;
1208  num_cbc_argv = 0;
1209  }
1210 
1211  cpuTime = CoinCpuTime() - start;
1212 
1213  // create a solver
1214  OsiSolverInterface *solver = model.solver();
1216  {
1217  writeResult( &model);
1218  }
1219  else
1220  {
1221  writeResult( solver);
1222  }
1223  }
1224  else // use other solvers
1225  {
1226  //if an LP just do initial solve
1228  {
1229  osiSolver->branchAndBound();
1230  }
1231  else
1232  {
1233  osiSolver->initialSolve();
1234  }
1235  cpuTime = CoinCpuTime() - start;
1236 
1238  }
1239  }
1240 
1241  catch(CoinError e)
1242  {
1243  std::string errmsg;
1244  errmsg = "Coin Solver Error: " + e.message() + "\n" + " see method "
1245  + e.methodName() + " in class " + e.className();
1246  throw ErrorClass( errmsg );
1247  }
1248  }
1249 
1250  catch(const ErrorClass& eclass)
1251  {
1252  std::string::size_type pos1 = eclass.errormsg.find( "<osrl");
1253  if(pos1 == std::string::npos)
1254  {
1256  osresult->setGeneralStatusType("error");
1258  }
1259  else
1260  {
1261  osrl = eclass.errormsg;
1262  }
1263  throw ErrorClass( osrl);
1264  }
1265 } // end solve
1266 
1267 std::string CoinSolver::getCoinSolverType(std::string lcl_osol)
1268 {
1269 // this is deprecated, but keep it around
1270  try
1271  {
1272  if( lcl_osol.find( "clp") != std::string::npos)
1273  {
1274  return "coin_solver_glpk";
1275  }
1276  else
1277  {
1278  if( lcl_osol.find( "cbc") != std::string::npos)
1279  {
1280  return "coin_solver_cpx";
1281  }
1282  else
1283  {
1284  if( lcl_osol.find( "cpx") != std::string::npos)
1285  {
1286  return "coin_solver_clp";
1287  }
1288  else
1289  {
1290  if(lcl_osol.find( "glpk") != std::string::npos)
1291  {
1292  return "";
1293  }
1294  else throw ErrorClass("a supported solver was not defined");
1295  }
1296  }
1297  }
1298  }
1299  catch(const ErrorClass& eclass)
1300  {
1302  osresult->setGeneralStatusType( "error");
1304  throw ErrorClass( osrl) ;
1305  }
1306 } // end getCoinSolverType
1307 
1308 #ifndef NDEBUG
1310 {
1311  int i;
1312  // print out problem parameters
1313  cout << "This is problem: " << osinstance->getInstanceName() << endl;
1314  cout << "The problem source is: " << osinstance->getInstanceSource() << endl;
1315  cout << "The problem description is: " << osinstance->getInstanceDescription() << endl;
1316  cout << "number of variables = " << osinstance->getVariableNumber() << endl;
1317  cout << "number of Rows = " << osinstance->getConstraintNumber() << endl;
1318 
1319  // print out the variable information
1320  if(osinstance->getVariableNumber() > 0)
1321  {
1322  for(i = 0; i < osinstance->getVariableNumber(); i++)
1323  {
1324  if(osinstance->getVariableNames() != NULL) cout << "variable Names " << osinstance->getVariableNames()[ i] << endl;
1325  if(osinstance->getVariableTypes() != NULL) cout << "variable Types " << osinstance->getVariableTypes()[ i] << endl;
1326  if(osinstance->getVariableLowerBounds() != NULL) cout << "variable Lower Bounds " << osinstance->getVariableLowerBounds()[ i] << endl;
1327  if(osinstance->getVariableUpperBounds() != NULL) cout << "variable Upper Bounds " << osinstance->getVariableUpperBounds()[i] << endl;
1328  }
1329  }
1330 
1331  // print out objective function information
1333  {
1334  if( osinstance->getObjectiveMaxOrMins()[0] == "min") cout << "problem is a minimization" << endl;
1335  else cout << "problem is a maximization" << endl;
1336  for(i = 0; i < osinstance->getVariableNumber(); i++)
1337  {
1338  cout << "OBJ COEFFICIENT = " << osinstance->getDenseObjectiveCoefficients()[0][i] << endl;
1339  }
1340  }
1341  // print out constraint information
1342  if(osinstance->getConstraintNumber() > 0)
1343  {
1344  for(i = 0; i < osinstance->getConstraintNumber(); i++)
1345  {
1346  if(osinstance->getConstraintNames() != NULL) cout << "row name = " << osinstance->getConstraintNames()[i] << endl;
1347  if(osinstance->getConstraintLowerBounds() != NULL) cout << "row lower bound = " << osinstance->getConstraintLowerBounds()[i] << endl;
1348  if(osinstance->getConstraintUpperBounds() != NULL) cout << "row upper bound = " << osinstance->getConstraintUpperBounds()[i] << endl;
1349  }
1350  }
1351 
1352  // print out linear constraint data
1353  if(m_CoinPackedMatrix != NULL) m_CoinPackedMatrix->dumpMatrix();
1354 } // end dataEchoCheck
1355 #endif
1356 
1357 
1358 void CoinSolver::writeResult(OsiSolverInterface *solver)
1359 {
1360  double *x = NULL;
1361  double *y = NULL;
1362  double *z = NULL;
1363  int *cbasis = NULL; //column basis information
1364  int *rbasis = NULL; //row basis information
1365  int *idx = NULL;
1366  int kount;
1367 
1368  //vectors to hold the basis information
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;
1374  int **basisIdx;
1375  basisIdx = new int*[ 4];
1376  //end of vectors
1377 
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];
1386  z = new double[1];
1387 
1388  //allocate basis if solver supports it (Clp, Cbc, Cplex, Gurobi
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) )
1394  {
1395  if (numOfIntVars == 0) // basis information is meaningless for (M)IP
1396  {
1397  if (numberOfVar > 0) cbasis = new int[numberOfVar];
1398  if (numberOfCon > 0) rbasis = new int[numberOfCon];
1399  supportsBasis = true;
1400  }
1401  }
1402 
1403  int solIdx = 0;
1404  int i = 0;
1405  int numberOfOtherVariableResults = 1;
1406  int otherIdx = 0;
1407  std::string description = "";
1408 
1409  try
1410  {
1411  osresult->setGeneralStatusType("normal");
1414  osresult->setSolverInvoked( "COIN-OR " + sSolverName );
1415  if (solver->isProvenOptimal() == true)
1416  {
1417  osresult->setSolutionStatus(solIdx, "optimal", description);
1418  if ( supportsBasis )
1419  {
1420  solver->getBasisStatus( cbasis, rbasis);
1421  }
1422 
1423  }//end if proven optimal
1424  else // some other terminating condition
1425  {
1426  if(solver->isProvenPrimalInfeasible() == true)
1427  osresult->setSolutionStatus(solIdx, "infeasible", "the problem is primal infeasible");
1428  else
1429  {
1430  if(solver->isProvenDualInfeasible() == true)
1431  osresult->setSolutionStatus(solIdx, "unbounded", "the problem is unbounded");
1432  else
1433  {
1434  if(solver->isPrimalObjectiveLimitReached() == true)
1435  {
1436  osresult->setSolutionStatus(solIdx, "other", "primal objective limit reached");
1437  if ( supportsBasis )
1438  {
1439  solver->getBasisStatus( cbasis, rbasis);
1440  }
1441  }
1442  else
1443  {
1444  if(solver->isDualObjectiveLimitReached() == true)
1445  {
1446  osresult->setSolutionStatus(solIdx, "other", "dual objective limit reached");
1447  if ( supportsBasis )
1448  {
1449  solver->getBasisStatus( cbasis, rbasis);
1450  }
1451  }
1452  else
1453  {
1454  if(solver->isIterationLimitReached() == true)
1455  {
1456  osresult->setSolutionStatus(solIdx, "other", "iteration limit reached");
1457  if ( supportsBasis )
1458  {
1459  solver->getBasisStatus( cbasis, rbasis);
1460  }
1461  }
1462  else
1463  {
1464  if(solver->isAbandoned() == true)
1465  osresult->setSolutionStatus(solIdx, "other", "there are numerical difficulties");
1466  else
1467  if( solver->getNumCols() == 0) osresult->setSolutionMessage(solIdx, "Warning: this problem has zero decision variables!");
1468  else
1469  osresult->setSolutionStatus(solIdx, "other", description);
1470  }
1471  }
1472  }
1473  }
1474  }
1475  }
1476 
1477  /* Retrieve the solution */
1478  //
1479  *(z + 0) = solver->getObjValue();
1480 
1481  osresult->setObjectiveValuesDense(solIdx, z);
1482 
1483  for(i=0; i < numberOfVar; i++)
1484  {
1485  *(x + i) = solver->getColSolution()[i];
1486  *(idx + i) = i;
1487 
1488  // sort basis information for variables into four categories
1489  if( (cbasis != NULL) && (solver->isProvenOptimal() == true) )
1490  {
1491  switch (cbasis[ i] )
1492  {
1493  case 0:
1494  {
1495  //a free variable
1496  freeVars.push_back( i);
1497  break;
1498  }
1499 
1500  case 1:
1501  {
1502  //a basic variable
1503  basicVars.push_back( i);
1504  break;
1505  }
1506 
1507  case 2:
1508  {
1509  //nonbasic at upper bound
1510  nonBasicUpper.push_back( i );
1511  break;
1512  }
1513 
1514  case 3:
1515  {
1516  //nonbasic at lower bound
1517  nonBasicLower.push_back( i) ;
1518  break;
1519  }
1520  default:
1521  throw ErrorClass("unknown result from Osi getBasisStatus when getting variable basis status");
1522 
1523  }//end switch
1524 
1525  } //end if on cbasis == NULL
1526 
1527  }// end for on number of variables
1528 
1529  //now store basis information for variables
1530  if(freeVars.size() > 0)
1531  {
1532  kount = 0;
1533 
1534 
1535  basisIdx[ 0] = new int[ freeVars.size()];
1536 
1537  for(vit = freeVars.begin(); vit < freeVars.end(); vit++)
1538  {
1539  basisIdx[0][ kount++] = *vit;
1540  }
1541 
1543  delete[] basisIdx[ 0];
1544  freeVars.clear();
1545  }
1546 
1547  if(basicVars.size() > 0)
1548  {
1549  kount = 0;
1550 
1551  basisIdx[ 1] = new int[ basicVars.size()];
1552 
1553  for(vit = basicVars.begin(); vit < basicVars.end(); vit++)
1554  {
1555  basisIdx[1][ kount++] = *vit;
1556  }
1557 
1559  delete[] basisIdx[ 1];
1560  basicVars.clear();
1561  }
1562 
1563  if(nonBasicUpper.size() > 0)
1564  {
1565  kount = 0;
1566 
1567  basisIdx[ 2] = new int[ nonBasicUpper.size()];
1568 
1569  for(vit = nonBasicUpper.begin(); vit < nonBasicUpper.end(); vit++)
1570  {
1571  basisIdx[2][ kount++] = *vit;
1572  }
1573 
1575  delete[] basisIdx[ 2];
1576  nonBasicUpper.clear();
1577  }
1578 
1579 
1580  if(nonBasicLower.size() > 0)
1581  {
1582  kount = 0;
1583 
1584  basisIdx[ 3] = new int[ nonBasicLower.size()];
1585 
1586  for(vit = nonBasicLower.begin(); vit < nonBasicLower.end(); vit++)
1587  {
1588  basisIdx[3][ kount++] = *vit;
1589  }
1590 
1592  delete[] basisIdx[ 3];
1593  nonBasicLower.clear();
1594  }
1595  //end get basis information for variables
1596 
1598  // Symphony does not get dual prices
1599  if( sSolverName.find( "symphony") == std::string::npos && osinstance->getNumberOfIntegerVariables() == 0 && osinstance->getNumberOfBinaryVariables() == 0)
1600  {
1601  for(i = 0; i < numberOfCon; i++)
1602  {
1603  *(y + i) = solver->getRowPrice()[ i];
1604 
1605  // get basis information
1606  if((rbasis != NULL) && (solver->isProvenOptimal() == true) )
1607  {
1608  switch (rbasis[ i] )
1609  {
1610  case 0:
1611  {
1612  //a free variable
1613  freeVars.push_back( i);
1614  break;
1615  }
1616 
1617  case 1:
1618  {
1619  //a basic variable
1620  basicVars.push_back( i);
1621  break;
1622  }
1623 
1624  case 2:
1625  {
1626  //nonbasic at upper bound
1627  nonBasicUpper.push_back( i );
1628  break;
1629  }
1630 
1631  case 3:
1632  {
1633  //nonbasic at lower bound
1634  nonBasicLower.push_back( i) ;
1635  break;
1636  }
1637  default:
1638  throw ErrorClass("unknown result from Osi getBasisStatus when getting row basis status");
1639 
1640  }//end switch
1641 
1642  } //end if on rbasis == NULL
1643 
1644 
1645  }// end for of loop on constraints
1646 
1648 
1649 
1650  //now set basis information for variables
1651  if(freeVars.size() > 0)
1652  {
1653  kount = 0;
1654 
1655  basisIdx[ 0] = new int[ freeVars.size()];
1656 
1657  for(vit = freeVars.begin(); vit < freeVars.end(); vit++)
1658  {
1659  basisIdx[0][ kount++] = *vit;
1660  }
1661 
1663  delete[] basisIdx[ 0];
1664  freeVars.clear();
1665  }
1666 
1667  if(basicVars.size() > 0)
1668  {
1669  kount = 0;
1670 
1671  basisIdx[ 1] = new int[ basicVars.size()];
1672 
1673  for(vit = basicVars.begin(); vit < basicVars.end(); vit++)
1674  {
1675  basisIdx[1][ kount++] = *vit;
1676  }
1677 
1679  delete[] basisIdx[ 1];
1680  basicVars.clear();
1681  }
1682 
1683  if(nonBasicUpper.size() > 0)
1684  {
1685 
1686  kount = 0;
1687 
1688  basisIdx[ 2] = new int[ nonBasicUpper.size()];
1689 
1690  for(vit = nonBasicUpper.begin(); vit < nonBasicUpper.end(); vit++)
1691  {
1692  basisIdx[2][ kount++] = *vit;
1693  }
1694 
1696  delete[] basisIdx[ 2];
1697  nonBasicUpper.clear();
1698  }
1699 
1700  if(nonBasicLower.size() > 0)
1701  {
1702  kount = 0;
1703 
1704  basisIdx[ 3] = new int[ nonBasicLower.size()];
1705 
1706  for(vit = nonBasicLower.begin(); vit < nonBasicLower.end(); vit++)
1707  {
1708  basisIdx[3][ kount++] = *vit;
1709  }
1710 
1712  delete[] basisIdx[ 3];
1713  nonBasicLower.clear();
1714 
1715  }
1716  //end get basis information for variables
1717 
1718 
1719  }// end of if on integer variables
1720 
1721 
1722  // now put the reduced costs into the osrl
1723  // Symphony does not get reduced costs
1724  if( sSolverName.find( "symphony") == std::string::npos && osinstance->getNumberOfIntegerVariables() == 0 && osinstance->getNumberOfBinaryVariables() == 0)
1725  {
1726  // first set the number of Other Variable Results
1727  if(numOfIntVars <= 0)
1728  {
1729  osresult->setNumberOfOtherVariableResults(solIdx, numberOfOtherVariableResults);
1730  for(i=0; i < numberOfVar; i++)
1731  {
1732  rcost[ i] = os_dtoa_format( solver->getReducedCost()[ i]);
1733  }
1734  osresult->setAnOtherVariableResultSparse(solIdx, otherIdx, "reduced_costs", "", "the variable reduced costs", idx, rcost, solver->getNumCols(), "", "double", "");
1735  // end of setting reduced costs
1736  }
1737  }
1738 
1739  ostringstream temp;
1740  temp << solver->getIterationCount();
1741  if (!osresult->setAnOtherSolutionResult(0,"iterations",temp.str(),"","",0,NULL))
1742  throw ErrorClass("error setting iteration count");
1743 
1745 
1746  if (y != NULL)
1747  {
1748  delete[] y;
1749  y = NULL;
1750  }
1751 
1752  if (rbasis != NULL)
1753  {
1754  delete[] rbasis;
1755  rbasis = NULL;
1756  }
1757 
1758  delete[] z;
1759  z = NULL;
1760 
1761  delete[] basisIdx;
1762  basisIdx = NULL;
1763 
1764  if (x != NULL)
1765  {
1766  delete[] x;
1767  x = NULL;
1768  }
1769 
1770  if (cbasis != NULL)
1771  {
1772  delete[] cbasis;
1773  cbasis = NULL;
1774  }
1775 
1776  if (rcost != NULL)
1777  {
1778  delete[] rcost;
1779  rcost = NULL;
1780  }
1781 
1782  if (idx != NULL)
1783  {
1784  delete[] idx;
1785  idx = NULL;
1786  }
1787  }
1788 
1789  catch(const ErrorClass& eclass)
1790  {
1791  if (y != NULL)
1792  {
1793  delete[] y;
1794  y = NULL;
1795  }
1796 
1797  if (rbasis != NULL)
1798  {
1799  delete[] rbasis;
1800  rbasis = NULL;
1801  }
1802 
1803  delete[] z;
1804  z = NULL;
1805 
1806  delete[] basisIdx;
1807  basisIdx = NULL;
1808 
1809  if (x != NULL)
1810  {
1811  delete[] x;
1812  x = NULL;
1813  }
1814 
1815  if (cbasis != NULL)
1816  {
1817  delete[] cbasis;
1818  cbasis = NULL;
1819  }
1820 
1821  if (rcost != NULL)
1822  {
1823  delete[] rcost;
1824  rcost = NULL;
1825  }
1826 
1827  if (idx != NULL)
1828  {
1829  delete[] idx;
1830  idx = NULL;
1831  }
1832 
1834  osresult->setGeneralStatusType( "error");
1836  throw ErrorClass( osrl) ;
1837  }
1838 }//writeResult(OsiSolverInterface)
1839 
1840 
1841 void CoinSolver::writeResult(CbcModel *model)
1842 {
1843  double *x = NULL;
1844  double *y = NULL;
1845 
1846  double *z = NULL;
1847  int *idx = NULL;
1848  std::string *rcost = NULL;
1849  //if( osinstance->getVariableNumber() > 0 ) x = new double[osinstance->getVariableNumber() ];
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() ];
1853  z = new double[1];
1854  if( model->getNumCols() > 0 ) rcost = new std::string[ model->getNumCols()];
1855 
1856  int numberOfOtherVariableResults = 1;
1857  int otherIdx = 0;
1858  int numberOfVar = model->getNumCols();
1860  int i = 0;
1861  int solIdx = 0;
1862  std::string description = "";
1863  osresult->setGeneralStatusType("normal");
1865 
1867 
1868  //first determine if we are feasible
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)
1876  {
1877  statusMsg = "feasible";
1878  }
1879  else
1880  {
1881  statusMsg = "infeasible";
1882  }
1883 
1884 
1885  if (model->isProvenOptimal() == true )
1886  {
1887  osresult->setSolutionStatus(solIdx, "optimal", description);
1888  }
1889  else
1890  {
1891  if(model->isProvenInfeasible() == true)
1892  osresult->setSolutionStatus(solIdx, "infeasible", "the integer program is infeasible");
1893  else
1894  {
1895  if(model->isProvenDualInfeasible() == true)
1896  osresult->setSolutionStatus(solIdx, "infeasible", "the continuous relaxation is dual infeasible");
1897  else
1898  {
1899  if(model->isContinuousUnbounded() == true)
1900  osresult->setSolutionStatus(solIdx, statusMsg, "the continuous relaxation is unbounded");
1901  else
1902  {
1903  if(model->isNodeLimitReached() == true)
1904  osresult->setSolutionStatus(solIdx, statusMsg, "node limit reached");
1905  else
1906  {
1907  if(model->isSecondsLimitReached() == true)
1908  osresult->setSolutionStatus(solIdx, statusMsg, "time limit reached");
1909  else
1910  {
1911  if(model->isSolutionLimitReached() == true)
1912  osresult->setSolutionStatus(solIdx, statusMsg, "solution limit reached");
1913  else
1914  {
1915  if(model->isAbandoned() == true)
1916  osresult->setSolutionStatus(solIdx, statusMsg, "there are numerical difficulties");
1917  else
1918  osresult->setSolutionStatus(solIdx, statusMsg,"unknown");
1919  }
1920  }
1921  }
1922  }
1923  }
1924  }
1925  }
1926 
1927  /* Retrieve the solution -- of course it may not be optimal */
1928  if(numOfIntVars > 0) *(z + 0) = model->getObjValue();
1929  osresult->setObjectiveValuesDense(solIdx, z);
1930  for(i=0; i < model->getNumCols(); i++)
1931  {
1932  *(x + i) = model->getColSolution()[i];
1933  *(idx + i) = i;
1934  }
1936  for(i=0; i < model->getNumRows(); i++)
1937  {
1938  *(y + i) = model->getRowPrice()[ i];
1939  }
1940  if(numOfIntVars <= 0) osresult->setDualVariableValuesDense(solIdx, y);
1941  // now put the reduced costs into the osrl
1942  // first set the number of Other Variable Results
1943  if(numOfIntVars <= 0)
1944  {
1945  osresult->setNumberOfOtherVariableResults(solIdx, numberOfOtherVariableResults);
1946  for(i=0; i < numberOfVar; i++)
1947  {
1948  rcost[ i] = os_dtoa_format( model->getReducedCost()[ i]);
1949  }
1950  osresult->setAnOtherVariableResultSparse(solIdx, otherIdx, "reduced_costs", "", "the variable reduced costs", idx, rcost, model->getNumCols());
1951  }
1952  // end of setting reduced costs
1954  //garbage collection
1955  if(model->getNumCols() > 0) delete[] x;
1956  x = NULL;
1957  if(model->getNumRows() > 0) delete[] y;
1958  y = NULL;
1959  delete[] z;
1960  z = NULL;
1961  if(model->getNumCols() > 0)
1962  {
1963  delete[] rcost;
1964  rcost = NULL;
1965  delete[] idx;
1966  idx = NULL;
1967  }
1968 }//writeResult( CbcModel)
1969 
1970 
a data structure for holding quadratic terms
Definition: OSGeneral.h:431
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)
Definition: OSdtoa.cpp:2541
int getNumberOfInitVarValues()
Get the number of initial variable values.
Definition: OSOption.cpp:2051
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&#39;s primal variable values, where i equals the given solution index...
Definition: OSResult.cpp:5001
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].
Definition: OSResult.cpp:7344
const OSSmartPtr< OSOutput > osoutput
Definition: OSOutput.cpp:39
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.
Definition: OSResult.cpp:4712
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
Definition: OSErrorClass.h:42
OsiSolverInterface * osiSolver
osiSolver is the osi solver object – in this case clp, glpk, cbc, cplex, symphony or dylp ...
Definition: OSCoinSolver.h:93
int getLinearConstraintCoefficientNumber()
Get number of specified (usually nonzero) linear constraint coefficient values.
the InitVarValue class.
Definition: OSOption.h:1159
std::vector< SolverOption * > getSolverOptions(std::string solver_name)
Get the options associated with a given solver.
Definition: OSOption.cpp:4508
The Result Class.
Definition: OSResult.h:2548
CoinPackedMatrix * m_CoinPackedMatrix
m_CoinPackedMatrix is a Coin Packed Matrix ojbect
Definition: OSCoinSolver.h:126
bool setSolverInvoked(std::string solverInvoked)
Set solver invoked.
Definition: OSResult.cpp:4155
bool bCallbuildSolverInstance
bCallbuildSolverInstance is set to true if buildSolverService has been called
bool setTime(double time)
Set time.
Definition: OSResult.cpp:4482
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&#39;s other (non-standard/solver specific)variable-related results...
Take an OSResult object and write a string that validates against OSrL.
Definition: OSrLWriter.h:30
OSResult * osresult
osresult holds the solution or result of the model in-memory as an OSResult object ...
ConstraintOption * constraints
the options for the constraints
Definition: OSOption.h:3515
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&#39;s dual variable values, where i equals the given solution index...
Definition: OSResult.cpp:6291
int getObjectiveNumber()
Get number of objectives.
bool setObjectiveNumber(int objectiveNumber)
Set the objective number.
Definition: OSResult.cpp:4721
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.
Definition: OSOption.cpp:3115
bool setSolutionMessage(int solIdx, std::string msg)
Set the [i]th optimization solution&#39;s message, where i equals the given solution index.
Definition: OSResult.cpp:4917
OSInstance * readOSiL(const std::string &osil)
parse the OSiL model instance.
Definition: OSiLReader.cpp:53
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
Definition: OSrLWriter.cpp:45
int numberOfObjectives
numberOfObjectives is the number of objective functions in the instance
Definition: OSInstance.h:201
virtual void buildSolverInstance()
The implementation of the corresponding virtual function.
static char * j
Definition: OSdtoa.cpp:3622
int idx
variable index
Definition: OSOption.h:1164
int * indexes
indexes holds an integer array of rowIdx (or colIdx) elements in coefMatrix (AMatrix).
Definition: OSGeneral.h:258
std::string osol
osol holds the options for the solver
int getNumberOfStringVariables()
getNumberOfStringVariables
bool setSolutionNumber(int number)
set the number of solutions.
Definition: OSResult.cpp:4740
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.
Definition: OSResult.cpp:5192
void fint fint fint real fint real real real real real real real real real * e
double cpuTime
Definition: OSCoinSolver.h:140
BasisStatus * initialBasisStatus
initial basis information
Definition: OSOption.h:2110
Used to read an OSiL string.
Definition: OSiLReader.h:37
bool setNumberOfOtherVariableResults(int solIdx, int numberOfOtherVariableResults)
Set the [i]th optimization solution&#39;s other (non-standard/solver specific) variable-related results...
Definition: OSResult.cpp:5236
const char ** cbc_argv
when Cbc is the solver, these are the arguments sent to Cbc Solve
Definition: OSCoinSolver.h:134
void writeResult(OsiSolverInterface *solver)
OSiLReader * m_osilreader
m_osilreader is an OSiLReader object used to create an osinstance from an osil string if needed ...
Definition: OSCoinSolver.h:101
double lb
lb corresponds to the optional attribute that holds the variable lower bound.
Definition: OSInstance.h:56
Variable ** var
Here we define a pointer to an array of var pointers.
Definition: OSInstance.h:97
int num_cbc_argv
the number of arguments in the argument list to the Cbc Solver
Definition: OSCoinSolver.h:138
int * varOneIndexes
varOneIndexes holds an integer array of the first variable indexes of all the quadratic terms...
Definition: OSGeneral.h:445
SparseMatrix * getLinearConstraintCoefficientsInRowMajor()
Get linear constraint coefficients in row major.
double value
initial value
Definition: OSOption.h:1170
OSOption * osoption
osoption holds the solver options in-memory as an OSOption object
void fint fint * k
const double OSDBL_MAX
Definition: OSParameters.h:93
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.
Definition: OSInstance.h:61
Variables * variables
variables is a pointer to a Variables object
Definition: OSInstance.h:2185
OSoLReader * m_osolreader
m_osolreader is an OSoLReader object used to create an osoption from an osol string if needed ...
Definition: OSCoinSolver.h:107
SparseMatrix * getLinearConstraintCoefficientsInColumnMajor()
Get linear constraint coefficients in column major.
OSOption * readOSoL(const std::string &osol)
parse the OSoL solver options.
Definition: OSoLReader.cpp:76
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...
Definition: OSGeneral.h:264
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.
Definition: OSInstance.h:2278
VariableOption * variables
the options for the variables
Definition: OSOption.h:3509
OSrLWriter * osrlwriter
osrlwriter object used to write osrl from an OSResult object
Definition: OSCoinSolver.h:129
int getConstraintNumber()
Get number of constraints.
Objective ** obj
coef is pointer to an array of ObjCoef object pointers
Definition: OSInstance.h:205
bool getLinearConstraintCoefficientMajor()
Get whether the constraint coefficients is in column major (true) or row major (false).
bool setConstraintNumber(int constraintNumber)
Set the constraint number.
Definition: OSResult.cpp:4731
std::string sSolverName
sSolverName is the name of the Coin solver used, e.g.
int getNumberOfSolverOptions()
Get the number of solver options.
Definition: OSOption.cpp:2207
int getNumberOfQuadraticTerms()
Get the number of specified (usually nonzero) qTerms in the quadratic coefficients.
Used to read an OSoL string.
Definition: OSoLReader.h:37
Objectives * objectives
objectives is a pointer to a Objectives object
Definition: OSInstance.h:2188
std::string getInstanceSource()
Get instance source.
InitVarValue ** getInitVarValuesSparse()
Get the initial values associated with the variables in sparse form.
Definition: OSOption.cpp:2719
int * rowIndexes
rowIndexes holds an integer array of row indexes of all the quadratic terms.
Definition: OSGeneral.h:440
std::string os_dtoa_format(double x)
Definition: OSMathUtil.cpp:154
int * starts
starts holds an integer array of start elements in coefMatrix (AMatrix), which points to the start of...
Definition: OSGeneral.h:252
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.
Definition: OSOption.h:3596
bool setObjectiveValuesDense(int solIdx, double *objectiveValues)
Set the [i]th optimization solution&#39;s objective values, where i equals the given solution index...
Definition: OSResult.cpp:5824
for(int i=0;i< nnz;i++)
void fint * m
BasisStatus * initialBasisStatus
initial basis status for the slack variables
Definition: OSOption.h:3277
virtual void solve()
The implementation of the corresponding virtual function.
double * coefficients
coefficients holds a double array all the quadratic term coefficients.
Definition: OSGeneral.h:455
int * varTwoIndexes
varTwoIndexes holds an integer array of the second variable indexes of all the quadratic terms...
Definition: OSGeneral.h:450
std::string * getConstraintNames()
Get constraint names.
used for throwing exceptions.
Definition: OSErrorClass.h:31
void fint * n
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...
Definition: OSOption.cpp:3073
int getNumberOfBinaryVariables()
getNumberOfBinaryVariables
std::string getInstanceDescription()
Get instance description.
void fint fint fint real fint real * x