CYCLUS
OsiCbcSolverInterface_2_9.cpp
Go to the documentation of this file.
1 // $Id: OsiCbcSolverInterface.cpp 2083 2014-09-28 10:31:40Z forrest $
2 // Copyright (C) 2002, International Business Machines
3 // Corporation and others. All Rights Reserved.
4 // This code is licensed under the terms of the Eclipse Public License (EPL).
5 
6 #include <cassert>
7 
8 #include "OsiConfig.h"
9 #include "CoinTime.hpp"
10 
11 #include "CoinHelperFunctions.hpp"
12 #include "CoinIndexedVector.hpp"
13 
14 /*
15  Default solver configuration: In any environment, clp is the default if you
16  do nothing.
17 
18  The necessary definitions will be handled by the configure script (based on
19  the value specified for --with-osicbc-default-solver) in any environment
20  where configure is available. The results can be found in inc/config_osi.h,
21  which is created during configuration from config_osi.h.in and placed
22  in the build directory.
23 
24  In an environment which does not use configure (MS Visual Studio, for example)
25  the preferred method is to edit the definitions in inc/OsiConfig.h. The
26  symbols are left undefined by default because some older environments (e.g.,
27  MS Visual Studio v7 or earlier) will not accept an #include directive which
28  uses a macro to specify the file. In such an environment, if you want to use
29  a solver other than OsiClp, you'll need to make the changes here.
30 */
31 
32 #ifndef OSICBC_DFLT_SOLVER
33 #define OSICBC_DFLT_SOLVER OsiClpSolverInterface
34 #define OSICBC_CLP_DFLT_SOLVER
35 #include "OsiClpSolverInterface.hpp"
36 #else
37 #include OSICBC_DFLT_SOLVER_HPP
38 #endif
39 
41 #include "OsiCuts.hpp"
42 #include "OsiRowCut.hpp"
43 #include "OsiColCut.hpp"
44 #ifdef OSICBC_CLP_DFLT_SOLVER
45 #include "ClpPresolve.hpp"
46 #endif
47 //#############################################################################
48 // Solve methods
49 //#############################################################################
51 {
52  modelPtr_->solver()->initialSolve();
53 }
54 
55 //-----------------------------------------------------------------------------
57 {
58  modelPtr_->solver()->resolve();
59 }
60 //#############################################################################
61 // Parameter related methods
62 //#############################################################################
63 
64 bool
65 OsiCbcSolverInterface::setIntParam(OsiIntParam key, int value)
66 {
67  return modelPtr_->solver()->setIntParam(key,value);;
68 }
69 
70 //-----------------------------------------------------------------------------
71 
72 bool
73 OsiCbcSolverInterface::setDblParam(OsiDblParam key, double value)
74 {
75  return modelPtr_->solver()->setDblParam(key,value);
76 }
77 
78 //-----------------------------------------------------------------------------
79 
80 bool
81 OsiCbcSolverInterface::setStrParam(OsiStrParam key, const std::string & value)
82 {
83  return modelPtr_->solver()->setStrParam(key,value);
84 }
85 
86 
87 //-----------------------------------------------------------------------------
88 
89 bool
90 OsiCbcSolverInterface::getIntParam(OsiIntParam key, int& value) const
91 {
92  return modelPtr_->solver()->getIntParam(key,value);
93 }
94 
95 //-----------------------------------------------------------------------------
96 
97 bool
98 OsiCbcSolverInterface::getDblParam(OsiDblParam key, double& value) const
99 {
100  return modelPtr_->solver()->getDblParam(key,value);
101 }
102 
103 //-----------------------------------------------------------------------------
104 
105 bool
106 OsiCbcSolverInterface::getStrParam(OsiStrParam key, std::string & value) const
107 {
108  if ( key==OsiSolverName ) {
109  std::string value2;
110  modelPtr_->solver()->getStrParam(key,value2);
111  value = "cbc"+value2;
112  return true;
113  }
114  return modelPtr_->solver()->getStrParam(key,value);
115 }
116 
117 
118 //#############################################################################
119 // Methods returning info on how the solution process terminated
120 //#############################################################################
121 
123 {
124  if (modelPtr_->status()!=-1)
125  return modelPtr_->isAbandoned();
126  else
127  return modelPtr_->solver()->isAbandoned();
128 }
129 
131 {
132  if (modelPtr_->status()!=-1)
133  return modelPtr_->isProvenOptimal();
134  else
135  return modelPtr_->solver()->isProvenOptimal();
136 }
137 
139 {
140  if (modelPtr_->status()!=-1)
141  return modelPtr_->isProvenInfeasible();
142  else
143  return modelPtr_->solver()->isProvenPrimalInfeasible();
144 }
145 
147 {
148  if (modelPtr_->status()!=-1)
149  return modelPtr_->isProvenDualInfeasible();
150  else
151  return modelPtr_->solver()->isProvenDualInfeasible();
152 }
154 {
155  return modelPtr_->solver()->isPrimalObjectiveLimitReached();
156 }
157 
159 {
160  return modelPtr_->solver()->isDualObjectiveLimitReached();
161 }
162 
164 {
165  if (modelPtr_->status()!=-1)
166  return modelPtr_->isNodeLimitReached();
167  else
168  return modelPtr_->solver()->isIterationLimitReached();
169 }
170 
171 //#############################################################################
172 // WarmStart related methods
173 //#############################################################################
174 CoinWarmStart *OsiCbcSolverInterface::getEmptyWarmStart () const
175 {
176  return modelPtr_->solver()->getEmptyWarmStart();
177 }
178 
179 CoinWarmStart* OsiCbcSolverInterface::getWarmStart() const
180 {
181  return modelPtr_->solver()->getWarmStart();
182 }
183 
184 //-----------------------------------------------------------------------------
185 
186 bool OsiCbcSolverInterface::setWarmStart(const CoinWarmStart* warmstart)
187 {
188  return modelPtr_->solver()->setWarmStart(warmstart);
189 }
190 
191 //#############################################################################
192 // Hotstart related methods (primarily used in strong branching)
193 //#############################################################################
194 
196 {
197  modelPtr_->solver()->markHotStart();
198 }
199 
201 {
202  modelPtr_->solver()->solveFromHotStart();
203 }
204 
206 {
207  modelPtr_->solver()->unmarkHotStart();
208 }
209 
210 //#############################################################################
211 // Problem information methods (original data)
212 //#############################################################################
213 
214 //------------------------------------------------------------------
215 const char * OsiCbcSolverInterface::getRowSense() const
216 {
217  return modelPtr_->solver()->getRowSense();
218 }
219 //------------------------------------------------------------------
220 const double * OsiCbcSolverInterface::getRightHandSide() const
221 {
222  return modelPtr_->solver()->getRightHandSide();
223 }
224 //------------------------------------------------------------------
225 const double * OsiCbcSolverInterface::getRowRange() const
226 {
227  return modelPtr_->solver()->getRowRange();
228 }
229 //------------------------------------------------------------------
230 // Return information on integrality
231 //------------------------------------------------------------------
232 bool OsiCbcSolverInterface::isContinuous(int colNumber) const
233 {
234  return modelPtr_->solver()->isContinuous(colNumber);
235 }
236 //------------------------------------------------------------------
237 
238 //------------------------------------------------------------------
239 // Row and column copies of the matrix ...
240 //------------------------------------------------------------------
241 const CoinPackedMatrix * OsiCbcSolverInterface::getMatrixByRow() const
242 {
243  return modelPtr_->solver()->getMatrixByRow();
244 }
245 
246 const CoinPackedMatrix * OsiCbcSolverInterface::getMatrixByCol() const
247 {
248  return modelPtr_->solver()->getMatrixByCol();
249 }
250 
251 //------------------------------------------------------------------
252 std::vector<double*> OsiCbcSolverInterface::getDualRays(int maxNumRays,
253  bool fullRay) const
254 {
255  return modelPtr_->solver()->getDualRays(maxNumRays,fullRay);
256 }
257 //------------------------------------------------------------------
258 std::vector<double*> OsiCbcSolverInterface::getPrimalRays(int maxNumRays) const
259 {
260  return modelPtr_->solver()->getPrimalRays(maxNumRays);
261 }
262 //#############################################################################
263 void
265 {
266  modelPtr_->solver()->setContinuous(index);
267 }
268 //-----------------------------------------------------------------------------
269 void
271 {
272  modelPtr_->solver()->setInteger(index);
273 }
274 //-----------------------------------------------------------------------------
275 void
276 OsiCbcSolverInterface::setContinuous(const int* indices, int len)
277 {
278  modelPtr_->solver()->setContinuous(indices,len);
279 }
280 //-----------------------------------------------------------------------------
281 void
282 OsiCbcSolverInterface::setInteger(const int* indices, int len)
283 {
284  modelPtr_->solver()->setInteger(indices,len);
285 }
286 //-----------------------------------------------------------------------------
287 void OsiCbcSolverInterface::setColSolution(const double * cs)
288 {
289  modelPtr_->solver()->setColSolution(cs);
290 }
291 //-----------------------------------------------------------------------------
292 void OsiCbcSolverInterface::setRowPrice(const double * rs)
293 {
294  modelPtr_->solver()->setRowPrice(rs);
295 }
296 
297 //#############################################################################
298 // Problem modifying methods (matrix)
299 //#############################################################################
300 void
301 OsiCbcSolverInterface::addCol(const CoinPackedVectorBase& vec,
302  const double collb, const double colub,
303  const double obj)
304 {
305  modelPtr_->solver()->addCol(vec,collb,colub,obj);
306 }
307 /* Add a column (primal variable) to the problem. */
308 void
309 OsiCbcSolverInterface::addCol(int numberElements, const int * rows, const double * elements,
310  const double collb, const double colub,
311  const double obj)
312 {
313  modelPtr_->solver()->addCol(numberElements, rows, elements,
314  collb,colub,obj);
315 }
316 //-----------------------------------------------------------------------------
317 void
318 OsiCbcSolverInterface::addCols(const int numcols,
319  const CoinPackedVectorBase * const * cols,
320  const double* collb, const double* colub,
321  const double* obj)
322 {
323  modelPtr_->solver()->addCols(numcols,cols,collb,colub,obj);
324 }
325 //-----------------------------------------------------------------------------
326 void
327 OsiCbcSolverInterface::deleteCols(const int num, const int * columnIndices)
328 {
329  modelPtr_->solver()->deleteCols(num,columnIndices);
330 }
331 //-----------------------------------------------------------------------------
332 void
333 OsiCbcSolverInterface::addRow(const CoinPackedVectorBase& vec,
334  const double rowlb, const double rowub)
335 {
336  modelPtr_->solver()->addRow(vec,rowlb,rowub);
337 }
338 //-----------------------------------------------------------------------------
339 void
340 OsiCbcSolverInterface::addRow(const CoinPackedVectorBase& vec,
341  const char rowsen, const double rowrhs,
342  const double rowrng)
343 {
344  modelPtr_->solver()->addRow(vec,rowsen,rowrhs,rowrng);
345 }
346 //-----------------------------------------------------------------------------
347 void
348 OsiCbcSolverInterface::addRows(const int numrows,
349  const CoinPackedVectorBase * const * rows,
350  const double* rowlb, const double* rowub)
351 {
352  modelPtr_->solver()->addRows(numrows,rows,rowlb,rowub);
353 }
354 //-----------------------------------------------------------------------------
355 void
356 OsiCbcSolverInterface::addRows(const int numrows,
357  const CoinPackedVectorBase * const * rows,
358  const char* rowsen, const double* rowrhs,
359  const double* rowrng)
360 {
361  modelPtr_->solver()->addRows(numrows,rows,rowsen,rowrhs,rowrng);
362 }
363 //-----------------------------------------------------------------------------
364 void
365 OsiCbcSolverInterface::deleteRows(const int num, const int * rowIndices)
366 {
367  modelPtr_->solver()->deleteRows(num,rowIndices);
368 }
369 
370 //#############################################################################
371 // Methods to input a problem
372 //#############################################################################
373 
374 void
375 OsiCbcSolverInterface::loadProblem(const CoinPackedMatrix& matrix,
376  const double* collb, const double* colub,
377  const double* obj,
378  const double* rowlb, const double* rowub)
379 {
380  modelPtr_->solver()->loadProblem(matrix,collb,colub,obj,rowlb,rowub);
381 }
382 
383 //-----------------------------------------------------------------------------
384 
385 void
386 OsiCbcSolverInterface::assignProblem(CoinPackedMatrix*& matrix,
387  double*& collb, double*& colub,
388  double*& obj,
389  double*& rowlb, double*& rowub)
390 {
391  modelPtr_->solver()->assignProblem(matrix,collb,colub,obj,rowlb,rowub);
392 }
393 
394 //-----------------------------------------------------------------------------
395 
396 void
397 OsiCbcSolverInterface::loadProblem(const CoinPackedMatrix& matrix,
398  const double* collb, const double* colub,
399  const double* obj,
400  const char* rowsen, const double* rowrhs,
401  const double* rowrng)
402 {
403  modelPtr_->solver()->loadProblem(matrix,collb,colub,obj,rowsen,rowrhs,rowrng);
404 }
405 
406 //-----------------------------------------------------------------------------
407 
408 void
409 OsiCbcSolverInterface::assignProblem(CoinPackedMatrix*& matrix,
410  double*& collb, double*& colub,
411  double*& obj,
412  char*& rowsen, double*& rowrhs,
413  double*& rowrng)
414 {
415  modelPtr_->solver()->assignProblem(matrix,collb,colub,obj,rowsen,rowrhs,rowrng);
416 }
417 
418 //-----------------------------------------------------------------------------
419 
420 void
421 OsiCbcSolverInterface::loadProblem(const int numcols, const int numrows,
422  const CoinBigIndex * start, const int* index,
423  const double* value,
424  const double* collb, const double* colub,
425  const double* obj,
426  const double* rowlb, const double* rowub)
427 {
428  modelPtr_->solver()->loadProblem(numcols,numrows,start,index,value,
429  collb,colub,obj,rowlb,rowub);
430 }
431 //-----------------------------------------------------------------------------
432 
433 void
434 OsiCbcSolverInterface::loadProblem(const int numcols, const int numrows,
435  const CoinBigIndex * start, const int* index,
436  const double* value,
437  const double* collb, const double* colub,
438  const double* obj,
439  const char* rowsen, const double* rowrhs,
440  const double* rowrng)
441 {
442  modelPtr_->solver()->loadProblem(numcols,numrows,start,index,value,
443  collb,colub,obj,rowsen,rowrhs,rowrng);
444 }
445 
446 //-----------------------------------------------------------------------------
447 // Write mps files
448 //-----------------------------------------------------------------------------
449 
450 void OsiCbcSolverInterface::writeMps(const char * filename,
451  const char * extension,
452  double objSense) const
453 {
454  modelPtr_->solver()->writeMps(filename,extension,objSense);
455 }
456 
457 int
458 OsiCbcSolverInterface::writeMpsNative(const char *filename,
459  const char ** rowNames, const char ** columnNames,
460  int formatType,int numberAcross,double objSense) const
461 {
462  return modelPtr_->solver()->writeMpsNative(filename, rowNames, columnNames,
463  formatType, numberAcross,objSense);
464 }
465 
466 //#############################################################################
467 // Constructors, destructors clone and assignment
468 //#############################################################################
469 //-------------------------------------------------------------------
470 // Default Constructor
471 //-------------------------------------------------------------------
472 OsiCbcSolverInterface::OsiCbcSolverInterface (OsiSolverInterface * solver,
473  CbcStrategy * strategy)
474 :
475 OsiSolverInterface()
476 {
477  if (solver) {
478  modelPtr_=new CbcModel(*solver);
479  } else {
480  OSICBC_DFLT_SOLVER solverDflt;
481  modelPtr_=new CbcModel(solverDflt);
482  }
483  if (strategy) {
484  modelPtr_->setStrategy(*strategy);
485  } else {
486  CbcStrategyDefault defaultStrategy;
487  modelPtr_->setStrategy(defaultStrategy);
488  }
489 }
490 
491 //-------------------------------------------------------------------
492 // Clone
493 //-------------------------------------------------------------------
494 OsiSolverInterface * OsiCbcSolverInterface::clone(bool CopyData) const
495 {
496  if (CopyData) {
497  return new OsiCbcSolverInterface(*this);
498  } else {
499  return new OsiCbcSolverInterface();
500  }
501 }
502 
503 
504 //-------------------------------------------------------------------
505 // Copy constructor
506 //-------------------------------------------------------------------
508  const OsiCbcSolverInterface & rhs)
509 :
510 OsiSolverInterface(rhs)
511 {
512  assert (rhs.modelPtr_);
513  modelPtr_ = new CbcModel(*rhs.modelPtr_);
514 }
515 
516 
517 //-------------------------------------------------------------------
518 // Destructor
519 //-------------------------------------------------------------------
521 {
522  delete modelPtr_;
523 }
524 
525 //-------------------------------------------------------------------
526 // Assignment operator
527 //-------------------------------------------------------------------
530 {
531  if (this != &rhs) {
532  OsiSolverInterface::operator=(rhs);
533  delete modelPtr_;
534  modelPtr_=new CbcModel(*rhs.modelPtr_);
535  }
536  return *this;
537 }
538 
539 //#############################################################################
540 // Applying cuts
541 //#############################################################################
542 
543 void OsiCbcSolverInterface::applyRowCut( const OsiRowCut & rowCut )
544 {
545  modelPtr_->solver()->applyRowCuts(1,&rowCut);
546 }
547 /* Apply a collection of row cuts which are all effective.
548  applyCuts seems to do one at a time which seems inefficient.
549 */
550 void
551 OsiCbcSolverInterface::applyRowCuts(int numberCuts, const OsiRowCut * cuts)
552 {
553  modelPtr_->solver()->applyRowCuts(numberCuts,cuts);
554 }
555 /* Apply a collection of row cuts which are all effective.
556  applyCuts seems to do one at a time which seems inefficient.
557 */
558 void
559 OsiCbcSolverInterface::applyRowCuts(int numberCuts, const OsiRowCut ** cuts)
560 {
561  modelPtr_->solver()->applyRowCuts(numberCuts, cuts);
562 }
563 //-----------------------------------------------------------------------------
564 
565 void OsiCbcSolverInterface::applyColCut( const OsiColCut & cc )
566 {
567  const double * lower = modelPtr_->solver()->getColLower();
568  const double * upper = modelPtr_->solver()->getColUpper();
569  const CoinPackedVector & lbs = cc.lbs();
570  const CoinPackedVector & ubs = cc.ubs();
571  int i;
572 
573  for ( i=0; i<lbs.getNumElements(); i++ ) {
574  int iCol = lbs.getIndices()[i];
575  double value = lbs.getElements()[i];
576  if ( value > lower[iCol] )
577  modelPtr_->solver()->setColLower(iCol, value);
578  }
579  for ( i=0; i<ubs.getNumElements(); i++ ) {
580  int iCol = ubs.getIndices()[i];
581  double value = ubs.getElements()[i];
582  if ( value < upper[iCol] )
583  modelPtr_->solver()->setColUpper(iCol, value);
584  }
585 }
586 /* Read an mps file from the given filename (defaults to Osi reader) - returns
587  number of errors (see OsiMpsReader class) */
588 int
589 OsiCbcSolverInterface::readMps(const char *filename,
590  const char *extension )
591 {
592  return modelPtr_->solver()->readMps(filename,extension);
593 }
594 // Get pointer to array[getNumCols()] of primal solution vector
595 const double *
597 {
598  return modelPtr_->solver()->getColSolution();
599 }
600 
601 // Get pointer to array[getNumRows()] of dual prices
602 const double *
604 {
605  return modelPtr_->solver()->getRowPrice();
606 }
607 
608 // Get a pointer to array[getNumCols()] of reduced costs
609 const double *
611 {
612  return modelPtr_->solver()->getReducedCost();
613 }
614 
615 /* Get pointer to array[getNumRows()] of row activity levels (constraint
616  matrix times the solution vector */
617 const double *
619 {
620  return modelPtr_->solver()->getRowActivity();
621 }
622 double
624 {
625  return modelPtr_->solver()->getObjValue();
626 }
627 
628 /* Set an objective function coefficient */
629 void
630 OsiCbcSolverInterface::setObjCoeff( int elementIndex, double elementValue )
631 {
632  modelPtr_->solver()->setObjCoeff(elementIndex,elementValue);
633 }
634 
635 /* Set a single column lower bound<br>
636  Use -DBL_MAX for -infinity. */
637 void
638 OsiCbcSolverInterface::setColLower( int elementIndex, double elementValue )
639 {
640  modelPtr_->solver()->setColLower(elementIndex,elementValue);
641 }
642 
643 /* Set a single column upper bound<br>
644  Use DBL_MAX for infinity. */
645 void
646 OsiCbcSolverInterface::setColUpper( int elementIndex, double elementValue )
647 {
648  modelPtr_->solver()->setColUpper(elementIndex,elementValue);
649 }
650 
651 /* Set a single column lower and upper bound */
652 void
653 OsiCbcSolverInterface::setColBounds( int elementIndex,
654  double lower, double upper )
655 {
656  modelPtr_->solver()->setColBounds(elementIndex,lower,upper);
657 }
658 void OsiCbcSolverInterface::setColSetBounds(const int* indexFirst,
659  const int* indexLast,
660  const double* boundList)
661 {
662  modelPtr_->solver()->setColSetBounds(indexFirst,indexLast,boundList);
663 }
664 //------------------------------------------------------------------
665 /* Set a single row lower bound<br>
666  Use -DBL_MAX for -infinity. */
667 void
668 OsiCbcSolverInterface::setRowLower( int elementIndex, double elementValue ) {
669  modelPtr_->solver()->setRowLower(elementIndex,elementValue);
670 }
671 
672 /* Set a single row upper bound<br>
673  Use DBL_MAX for infinity. */
674 void
675 OsiCbcSolverInterface::setRowUpper( int elementIndex, double elementValue ) {
676  modelPtr_->solver()->setRowUpper(elementIndex,elementValue);
677 }
678 
679 /* Set a single row lower and upper bound */
680 void
681 OsiCbcSolverInterface::setRowBounds( int elementIndex,
682  double lower, double upper ) {
683  modelPtr_->solver()->setRowBounds(elementIndex,lower,upper);
684 }
685 //-----------------------------------------------------------------------------
686 void
687 OsiCbcSolverInterface::setRowType(int i, char sense, double rightHandSide,
688  double range)
689 {
690  modelPtr_->solver()->setRowType(i,sense,rightHandSide,range);
691 }
692 //-----------------------------------------------------------------------------
693 void OsiCbcSolverInterface::setRowSetBounds(const int* indexFirst,
694  const int* indexLast,
695  const double* boundList)
696 {
697  modelPtr_->solver()->setRowSetBounds(indexFirst,indexLast,boundList);
698 }
699 //-----------------------------------------------------------------------------
700 void
701 OsiCbcSolverInterface::setRowSetTypes(const int* indexFirst,
702  const int* indexLast,
703  const char* senseList,
704  const double* rhsList,
705  const double* rangeList)
706 {
707  modelPtr_->solver()->setRowSetTypes(indexFirst,indexLast,senseList,rhsList,rangeList);
708 }
709 // Set a hint parameter
710 bool
711 OsiCbcSolverInterface::setHintParam(OsiHintParam key, bool yesNo,
712  OsiHintStrength strength,
713  void * otherInformation)
714 {
715  return modelPtr_->solver()->setHintParam(key,yesNo, strength, otherInformation);
716 }
717 
718 // Get a hint parameter
719 bool
720 OsiCbcSolverInterface::getHintParam(OsiHintParam key, bool & yesNo,
721  OsiHintStrength & strength,
722  void *& otherInformation) const
723 {
724  return modelPtr_->solver()->getHintParam(key,yesNo, strength, otherInformation);
725 }
726 
727 // Get a hint parameter
728 bool
729 OsiCbcSolverInterface::getHintParam(OsiHintParam key, bool & yesNo,
730  OsiHintStrength & strength) const
731 {
732  return modelPtr_->solver()->getHintParam(key,yesNo, strength);
733 }
734 
735 
736 int
738 {
739  return modelPtr_->solver()->getNumCols();
740 }
741 int
743 {
744  return modelPtr_->solver()->getNumRows();
745 }
746 int
748 {
749  return modelPtr_->solver()->getNumElements();
750 }
751 const double *
753 {
754  return modelPtr_->solver()->getColLower();
755 }
756 const double *
758 {
759  return modelPtr_->solver()->getColUpper();
760 }
761 const double *
763 {
764  return modelPtr_->solver()->getRowLower();
765 }
766 const double *
768 {
769  return modelPtr_->solver()->getRowUpper();
770 }
771 const double *
773 {
774  return modelPtr_->solver()->getObjCoefficients();
775 }
776 double
778 {
779  return modelPtr_->solver()->getObjSense();
780 }
781 double
783 {
784  return modelPtr_->solver()->getInfinity();
785 }
786 int
788 {
789  return modelPtr_->solver()->getIterationCount();
790 }
791 void
793 {
794  modelPtr_->setObjSense(s);
795 }
796 // Invoke solver's built-in enumeration algorithm
797 void
799 {
800  *messageHandler() << "Warning: Use of OsiCbc is deprecated." << CoinMessageEol;
801  *messageHandler() << "To enjoy the full performance of Cbc, use the CbcSolver interface." << CoinMessageEol;
802  modelPtr_->branchAndBound();
803 }
804 
805 /*
806  Name discipline support -- lh, 070328 --
807 
808  For safety, there's really nothing to it but to pass each call of an impure
809  virtual method on to the underlying solver. Otherwise we just can't know if
810  it's been overridden or not.
811 */
812 
813 std::string
814 OsiCbcSolverInterface::dfltRowColName (char rc, int ndx, unsigned digits) const
815 {
816  return (modelPtr_->solver()->dfltRowColName(rc,ndx,digits)) ;
817 }
818 
819 std::string OsiCbcSolverInterface::getObjName (unsigned maxLen) const
820 {
821  return (modelPtr_->solver()->getObjName(maxLen)) ;
822 }
823 
824 std::string OsiCbcSolverInterface::getRowName (int ndx, unsigned maxLen) const
825 {
826  return (modelPtr_->solver()->getRowName(ndx,maxLen)) ;
827 }
828 
829 const OsiSolverInterface::OsiNameVec &OsiCbcSolverInterface::getRowNames ()
830 {
831  return (modelPtr_->solver()->getRowNames()) ;
832 }
833 
834 std::string OsiCbcSolverInterface::getColName (int ndx, unsigned maxLen) const
835 {
836  return (modelPtr_->solver()->getColName(ndx,maxLen)) ;
837 }
838 
839 const OsiSolverInterface::OsiNameVec &OsiCbcSolverInterface::getColNames ()
840 {
841  return (modelPtr_->solver()->getColNames()) ;
842 }
843 
844 void OsiCbcSolverInterface::setRowNames (OsiNameVec &srcNames,
845  int srcStart, int len, int tgtStart)
846 {
847  modelPtr_->solver()->setRowNames(srcNames,srcStart,len,tgtStart) ;
848 }
849 
850 void OsiCbcSolverInterface::deleteRowNames (int tgtStart, int len)
851 {
852  modelPtr_->solver()->deleteRowNames(tgtStart,len) ;
853 }
854 
855 void OsiCbcSolverInterface::setColNames (OsiNameVec &srcNames,
856  int srcStart, int len, int tgtStart)
857 {
858  modelPtr_->solver()->setColNames(srcNames,srcStart,len,tgtStart) ;
859 }
860 
861 void OsiCbcSolverInterface::deleteColNames (int tgtStart, int len)
862 {
863  modelPtr_->solver()->deleteColNames(tgtStart,len) ;
864 }
865 
866 /*
867  These last three are the only functions that would normally be overridden.
868 */
869 
870 /*
871  Set objective function name.
872 */
873 void OsiCbcSolverInterface::setObjName (std::string name)
874 {
875  modelPtr_->solver()->setObjName(name) ;
876 }
877 
878 /*
879  Set a row name, to make sure both the solver and OSI see the same name.
880 */
881 void OsiCbcSolverInterface::setRowName (int ndx, std::string name)
882 
883 {
884  modelPtr_->solver()->setRowName(ndx,name) ;
885 }
886 
887 /*
888  Set a column name, to make sure both the solver and OSI see the same name.
889 */
890 void OsiCbcSolverInterface::setColName (int ndx, std::string name)
891 
892 {
893  modelPtr_->solver()->setColName(ndx,name) ;
894 }
895 // Pass in Message handler (not deleted at end)
896 void
897 OsiCbcSolverInterface::passInMessageHandler(CoinMessageHandler * handler)
898 {
899  OsiSolverInterface::passInMessageHandler(handler);
900  if (modelPtr_)
901  modelPtr_->passInMessageHandler(handler);
902 }
903 // So unit test can find out if NDEBUG set
905 {
906 #ifdef NDEBUG
907  return true;
908 #else
909  return false;
910 #endif
911 }
bool getIntParam(OsiIntParam key, int &value) const
virtual void setObjName(std::string name)
Set the name of the objective function.
virtual void applyRowCuts(int numberCuts, const OsiRowCut *cuts)
Apply a collection of row cuts which are all effective.
virtual CoinWarmStart * getWarmStart() const
Get warmstarting information.
virtual double getObjSense() const
Get objective function sense (1 for min (default), -1 for max)
virtual void setColUpper(int elementIndex, double elementValue)
Set a single column upper bound Use DBL_MAX for infinity.
virtual const double * getRightHandSide() const
Get pointer to array[getNumRows()] of rows right-hand sides.
virtual void resolve()
Resolve an LP relaxation after problem modification.
virtual bool isPrimalObjectiveLimitReached() const
Is the given primal objective limit reached?
virtual void writeMps(const char *filename, const char *extension="mps", double objSense=0.0) const
Write the problem into an mps file of the given filename.
#define OSICBC_DFLT_SOLVER
virtual double getInfinity() const
Get solver&#39;s value for infinity.
virtual int getNumCols() const
Get number of columns.
virtual void setRowLower(int elementIndex, double elementValue)
Set a single row lower bound Use -DBL_MAX for -infinity.
CbcModel * modelPtr_
Cbc model represented by this class instance.
virtual int readMps(const char *filename, const char *extension="mps")
Read an mps file from the given filename (defaults to Osi reader) - returns number of errors (see Osi...
virtual bool isContinuous(int colNumber) const
Return true if column is continuous.
virtual bool isAbandoned() const
Are there a numerical difficulties?
virtual void addRows(const int numrows, const CoinPackedVectorBase *const *rows, const double *rowlb, const double *rowub)
virtual std::vector< double * > getDualRays(int maxNumRays) const
Get as many dual rays as the solver can provide.
virtual const double * getObjCoefficients() const
Get pointer to array[getNumCols()] of objective function coefficients.
virtual void addCol(const CoinPackedVectorBase &vec, const double collb, const double colub, const double obj)
virtual void deleteCols(const int num, const int *colIndices)
virtual bool isProvenDualInfeasible() const
Is dual infeasiblity proven?
virtual std::string getColName(int colIndex, unsigned maxLen=std::string::npos) const
Return the name of the column.
virtual void markHotStart()
Create a hotstart point of the optimization process.
virtual const double * getRowLower() const
Get pointer to array[getNumRows()] of row lower bounds.
virtual bool setHintParam(OsiHintParam key, bool yesNo=true, OsiHintStrength strength=OsiHintTry, void *otherInformation=NULL)
virtual void initialSolve()
Solve initial LP relaxation.
virtual void setColBounds(int elementIndex, double lower, double upper)
Set a single column lower and upper bound.
virtual bool isIterationLimitReached() const
Iteration limit reached?
virtual void passInMessageHandler(CoinMessageHandler *handler)
Pass in a message handler.
virtual void setRowPrice(const double *rowprice)
Set dual solution vector.
virtual std::string getObjName(unsigned maxLen=std::string::npos) const
Return the name of the objective function.
virtual const double * getRowActivity() const
Get pointer to array[getNumRows()] of row activity levels (constraint matrix times the solution vecto...
virtual void setRowType(int index, char sense, double rightHandSide, double range)
Set the type of a single row
virtual std::vector< double * > getPrimalRays(int maxNumRays) const
Get as many primal rays as the solver can provide.
std::string name(int nuc)
Definition: pyne.cc:2940
virtual const double * getRowPrice() const
Get pointer to array[getNumRows()] of dual prices.
virtual bool getHintParam(OsiHintParam key, bool &yesNo, OsiHintStrength &strength, void *&otherInformation) const
Get a hint parameter.
virtual void setObjSense(double s)
Set objective function sense (1 for min (default), -1 for max,)
virtual void addRow(const CoinPackedVectorBase &vec, const double rowlb, const double rowub)
virtual CoinWarmStart * getEmptyWarmStart() const
Get an empty warm start object.
virtual const char * getRowSense() const
Get pointer to array[getNumRows()] of row constraint senses.
virtual const double * getReducedCost() const
Get a pointer to array[getNumCols()] of reduced costs.
virtual const OsiNameVec & getRowNames()
Return a pointer to a vector of row names.
virtual int getNumRows() const
Get number of rows.
virtual void deleteRowNames(int tgtStart, int len)
Delete len row names starting at index tgtStart.
virtual int getNumElements() const
Get number of nonzero elements.
virtual void setColSetBounds(const int *indexFirst, const int *indexLast, const double *boundList)
Set the bounds on a number of columns simultaneously The default implementation just invokes setColL...
virtual bool isProvenPrimalInfeasible() const
Is primal infeasiblity proven?
virtual std::string getRowName(int rowIndex, unsigned maxLen=std::string::npos) const
Return the name of the row.
virtual void applyRowCut(const OsiRowCut &rc)
Apply a row cut (append to constraint matrix).
virtual void setRowSetTypes(const int *indexFirst, const int *indexLast, const char *senseList, const double *rhsList, const double *rangeList)
Set the type of a number of rows simultaneously The default implementation just invokes setRowType()...
virtual void setColNames(OsiNameVec &srcNames, int srcStart, int len, int tgtStart)
Set multiple column names.
bool OsiCbcHasNDEBUG()
virtual void applyColCut(const OsiColCut &cc)
Apply a column cut (adjust one or more bounds).
virtual const double * getColSolution() const
Get pointer to array[getNumCols()] of primal solution vector.
virtual const CoinPackedMatrix * getMatrixByCol() const
Get pointer to column-wise copy of matrix.
virtual double getObjValue() const
Get objective function value.
virtual ~OsiCbcSolverInterface()
Destructor.
bool setStrParam(OsiStrParam key, const std::string &value)
virtual void solveFromHotStart()
Optimize starting from the hotstart.
virtual const double * getColLower() const
Get pointer to array[getNumCols()] of column lower bounds.
virtual void deleteColNames(int tgtStart, int len)
Delete len column names starting at index tgtStart.
virtual bool isDualObjectiveLimitReached() const
Is the given dual objective limit reached?
virtual void assignProblem(CoinPackedMatrix *&matrix, double *&collb, double *&colub, double *&obj, double *&rowlb, double *&rowub)
Load in an problem by assuming ownership of the arguments (the constraints on the rows are given by l...
bool getStrParam(OsiStrParam key, std::string &value) const
OsiCbcSolverInterface(OsiSolverInterface *solver=NULL, CbcStrategy *strategy=NULL)
Default Constructor.
virtual bool setWarmStart(const CoinWarmStart *warmstart)
Set warmstarting information.
virtual void branchAndBound()
Invoke solver&#39;s built-in enumeration algorithm.
virtual void setColSolution(const double *colsol)
Set the primal solution column values.
static std::string digits
string of digit characters
Definition: pyne.h:124
virtual const OsiNameVec & getColNames()
Return a pointer to a vector of column names.
virtual OsiSolverInterface * clone(bool copyData=true) const
Clone.
virtual void setColLower(int elementIndex, double elementValue)
Set a single column lower bound Use -DBL_MAX for -infinity.
virtual void setRowSetBounds(const int *indexFirst, const int *indexLast, const double *boundList)
Set the bounds on a number of rows simultaneously The default implementation just invokes setRowLowe...
virtual void setRowBounds(int elementIndex, double lower, double upper)
Set a single row lower and upper bound.
virtual void deleteRows(const int num, const int *rowIndices)
virtual void addCols(const int numcols, const CoinPackedVectorBase *const *cols, const double *collb, const double *colub, const double *obj)
virtual void loadProblem(const CoinPackedMatrix &matrix, const double *collb, const double *colub, const double *obj, const double *rowlb, const double *rowub)
Load in an problem by copying the arguments (the constraints on the rows are given by lower and upper...
virtual const double * getColUpper() const
Get pointer to array[getNumCols()] of column upper bounds.
virtual void setRowNames(OsiNameVec &srcNames, int srcStart, int len, int tgtStart)
Set multiple row names.
virtual void setRowName(int ndx, std::string name)
Set a row name.
virtual void setRowUpper(int elementIndex, double elementValue)
Set a single row upper bound Use DBL_MAX for infinity.
virtual std::string dfltRowColName(char rc, int ndx, unsigned digits=7) const
Generate a standard name of the form Rnnnnnnn or Cnnnnnnn.
bool setIntParam(OsiIntParam key, int value)
virtual bool isProvenOptimal() const
Is optimality proven?
virtual void unmarkHotStart()
Delete the snapshot.
virtual void setObjCoeff(int elementIndex, double elementValue)
Set an objective function coefficient.
virtual int writeMpsNative(const char *filename, const char **rowNames, const char **columnNames, int formatType=0, int numberAcross=2, double objSense=0.0) const
Write the problem into an mps file of the given filename, names may be null.
virtual void setColName(int ndx, std::string name)
Set a column name.
virtual void setInteger(int index)
Set the index-th variable to be an integer variable.
virtual const double * getRowRange() const
Get pointer to array[getNumRows()] of row ranges.
bool getDblParam(OsiDblParam key, double &value) const
virtual int getIterationCount() const
Get how many iterations it took to solve the problem (whatever "iteration" mean to the solver...
virtual const CoinPackedMatrix * getMatrixByRow() const
Get pointer to row-wise copy of matrix.
OsiCbcSolverInterface & operator=(const OsiCbcSolverInterface &rhs)
Assignment operator.
bool setDblParam(OsiDblParam key, double value)
virtual void setContinuous(int index)
Set the index-th variable to be a continuous variable.
virtual const double * getRowUpper() const
Get pointer to array[getNumRows()] of row upper bounds.