OsiCbcSolverInterface.hpp
Go to the documentation of this file.
1 // Copyright (C) 2000, International Business Machines
2 // Corporation and others. All Rights Reserved.
3 
4 #ifndef OsiCbcSolverInterface_H
5 #define OsiCbcSolverInterface_H
6 
7 #include <string>
8 #include <cfloat>
9 #include <map>
10 #include "CbcModel.hpp"
11 #include "CoinPackedMatrix.hpp"
12 #include "OsiSolverInterface.hpp"
13 #include "CbcStrategy.hpp"
14 #include "CoinWarmStartBasis.hpp"
15 
16 class OsiRowCut;
18 #ifndef COIN_DBL_MAX
19 static const double OsiCbcInfinity = DBL_MAX;
20 #else
21 static const double OsiCbcInfinity = COIN_DBL_MAX;
22 #endif
23 
24 //#############################################################################
25 
33  virtual public OsiSolverInterface {
34  friend int OsiCbcSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
35 
36 public:
37  //---------------------------------------------------------------------------
40 
41  virtual void initialSolve();
42 
44  virtual void resolve();
45 
47  virtual void branchAndBound();
49 
50  //---------------------------------------------------------------------------
66  // Set an integer parameter
67  bool setIntParam(OsiIntParam key, int value);
68  // Set an double parameter
69  bool setDblParam(OsiDblParam key, double value);
70  // Set a string parameter
71  bool setStrParam(OsiStrParam key, const std::string & value);
72  // Get an integer parameter
73  bool getIntParam(OsiIntParam key, int& value) const;
74  // Get an double parameter
75  bool getDblParam(OsiDblParam key, double& value) const;
76  // Get a string parameter
77  bool getStrParam(OsiStrParam key, std::string& value) const;
78  // Set a hint parameter - overrides OsiSolverInterface
79  virtual bool setHintParam(OsiHintParam key, bool yesNo=true,
80  OsiHintStrength strength=OsiHintTry,
81  void * otherInformation=NULL);
83  virtual bool getHintParam(OsiHintParam key, bool& yesNo,
84  OsiHintStrength& strength,
85  void *& otherInformation) const;
86 
89  virtual bool getHintParam(OsiHintParam key, bool& yesNo,
90  OsiHintStrength& strength) const;
92 
93  //---------------------------------------------------------------------------
95 
96 
97  virtual bool isAbandoned() const;
99  virtual bool isProvenOptimal() const;
101  virtual bool isProvenPrimalInfeasible() const;
103  virtual bool isProvenDualInfeasible() const;
105  virtual bool isPrimalObjectiveLimitReached() const;
107  virtual bool isDualObjectiveLimitReached() const;
109  virtual bool isIterationLimitReached() const;
111 
112  //---------------------------------------------------------------------------
115 
123  virtual CoinWarmStart *getEmptyWarmStart () const;
124 
126  virtual CoinWarmStart* getWarmStart() const;
129  virtual bool setWarmStart(const CoinWarmStart* warmstart);
131 
132  //---------------------------------------------------------------------------
139 
140  virtual void markHotStart();
142  virtual void solveFromHotStart();
144  virtual void unmarkHotStart();
146 
147  //---------------------------------------------------------------------------
162 
163  virtual int getNumCols() const;
164 
166  virtual int getNumRows() const;
167 
169  virtual int getNumElements() const ;
170 
172  virtual const double * getColLower() const;
173 
175  virtual const double * getColUpper() const;
176 
186  virtual const char * getRowSense() const;
187 
196  virtual const double * getRightHandSide() const ;
197 
206  virtual const double * getRowRange() const ;
207 
209  virtual const double * getRowLower() const ;
210 
212  virtual const double * getRowUpper() const ;
213 
215  virtual const double * getObjCoefficients() const;
216 
218  virtual double getObjSense() const ;
219 
221  virtual bool isContinuous(int colNumber) const;
222 
223 
225  virtual const CoinPackedMatrix * getMatrixByRow() const;
226 
228  virtual const CoinPackedMatrix * getMatrixByCol() const;
229 
231  virtual double getInfinity() const;
233 
236 
237  virtual const double * getColSolution() const;
238 
240  virtual const double * getRowPrice() const;
241 
243  virtual const double * getReducedCost() const;
244 
247  virtual const double * getRowActivity() const;
248 
250  virtual double getObjValue() const;
251 
254  virtual int getIterationCount() const ;
255 
267  virtual std::vector<double*> getDualRays(int maxNumRays) const;
279  virtual std::vector<double*> getPrimalRays(int maxNumRays) const;
280 
282 
291 
294  virtual std::string dfltRowColName(char rc,
295  int ndx, unsigned digits = 7) const ;
296 
299  virtual std::string getObjName (unsigned maxLen = std::string::npos) const ;
300 
303  virtual void setObjName (std::string name) ;
304 
307  virtual std::string getRowName(int rowIndex,
308  unsigned maxLen = std::string::npos) const ;
309 
312  virtual const OsiNameVec &getRowNames() ;
313 
316  virtual void setRowName(int ndx, std::string name) ;
317 
320  virtual void setRowNames(OsiNameVec &srcNames,
321  int srcStart, int len, int tgtStart) ;
322 
325  virtual void deleteRowNames(int tgtStart, int len) ;
326 
329  virtual std::string getColName(int colIndex,
330  unsigned maxLen = std::string::npos) const ;
331 
334  virtual const OsiNameVec &getColNames() ;
335 
338  virtual void setColName(int ndx, std::string name) ;
339 
342  virtual void setColNames(OsiNameVec &srcNames,
343  int srcStart, int len, int tgtStart) ;
344 
346  virtual void deleteColNames(int tgtStart, int len) ;
347 
349 
351 
352  //---------------------------------------------------------------------------
353 
356  //-------------------------------------------------------------------------
360  virtual void setObjCoeff( int elementIndex, double elementValue );
361 
365  virtual void setColLower( int elementIndex, double elementValue );
366 
370  virtual void setColUpper( int elementIndex, double elementValue );
371 
373  virtual void setColBounds( int elementIndex,
374  double lower, double upper );
375 
384  virtual void setColSetBounds(const int* indexFirst,
385  const int* indexLast,
386  const double* boundList);
387 
390  virtual void setRowLower( int elementIndex, double elementValue );
391 
394  virtual void setRowUpper( int elementIndex, double elementValue ) ;
395 
397  virtual void setRowBounds( int elementIndex,
398  double lower, double upper ) ;
399 
401  virtual void setRowType(int index, char sense, double rightHandSide,
402  double range);
403 
412  virtual void setRowSetBounds(const int* indexFirst,
413  const int* indexLast,
414  const double* boundList);
415 
426  virtual void setRowSetTypes(const int* indexFirst,
427  const int* indexLast,
428  const char* senseList,
429  const double* rhsList,
430  const double* rangeList);
432 
433  //-------------------------------------------------------------------------
437  virtual void setContinuous(int index);
439  virtual void setInteger(int index);
442  virtual void setContinuous(const int* indices, int len);
445  virtual void setInteger(const int* indices, int len);
447 
448  //-------------------------------------------------------------------------
450  virtual void setObjSense(double s );
451 
462  virtual void setColSolution(const double * colsol);
463 
474  virtual void setRowPrice(const double * rowprice);
475 
476  //-------------------------------------------------------------------------
483  virtual void addCol(const CoinPackedVectorBase& vec,
484  const double collb, const double colub,
485  const double obj);
487  virtual void addCol(int numberElements, const int * rows, const double * elements,
488  const double collb, const double colub,
489  const double obj) ;
490 
493  virtual void addCols(const int numcols,
494  const CoinPackedVectorBase * const * cols,
495  const double* collb, const double* colub,
496  const double* obj);
498  virtual void deleteCols(const int num, const int * colIndices);
499 
502  virtual void addRow(const CoinPackedVectorBase& vec,
503  const double rowlb, const double rowub);
505  virtual void addRow(const CoinPackedVectorBase& vec,
506  const char rowsen, const double rowrhs,
507  const double rowrng);
508 
511  virtual void addRows(const int numrows,
512  const CoinPackedVectorBase * const * rows,
513  const double* rowlb, const double* rowub);
515  virtual void addRows(const int numrows,
516  const CoinPackedVectorBase * const * rows,
517  const char* rowsen, const double* rowrhs,
518  const double* rowrng);
520  virtual void deleteRows(const int num, const int * rowIndices);
521 
522  //-----------------------------------------------------------------------
526  virtual void applyRowCuts(int numberCuts, const OsiRowCut * cuts);
531  virtual void applyRowCuts(int numberCuts, const OsiRowCut ** cuts);
533 
534 
535  //---------------------------------------------------------------------------
536 
537 public:
538 
552  virtual void loadProblem(const CoinPackedMatrix& matrix,
553  const double* collb, const double* colub,
554  const double* obj,
555  const double* rowlb, const double* rowub);
556 
564  virtual void assignProblem(CoinPackedMatrix*& matrix,
565  double*& collb, double*& colub, double*& obj,
566  double*& rowlb, double*& rowub);
567 
580  virtual void loadProblem(const CoinPackedMatrix& matrix,
581  const double* collb, const double* colub,
582  const double* obj,
583  const char* rowsen, const double* rowrhs,
584  const double* rowrng);
585 
593  virtual void assignProblem(CoinPackedMatrix*& matrix,
594  double*& collb, double*& colub, double*& obj,
595  char*& rowsen, double*& rowrhs,
596  double*& rowrng);
597 
600  virtual void loadProblem(const int numcols, const int numrows,
601  const CoinBigIndex * start, const int* index,
602  const double* value,
603  const double* collb, const double* colub,
604  const double* obj,
605  const double* rowlb, const double* rowub);
606 
609  virtual void loadProblem(const int numcols, const int numrows,
610  const CoinBigIndex * start, const int* index,
611  const double* value,
612  const double* collb, const double* colub,
613  const double* obj,
614  const char* rowsen, const double* rowrhs,
615  const double* rowrng);
616 
620  virtual int readMps(const char *filename,
621  const char *extension = "mps") ;
622 
627  virtual void writeMps(const char *filename,
628  const char *extension = "mps",
629  double objSense=0.0) const;
638  virtual int writeMpsNative(const char *filename,
639  const char ** rowNames, const char ** columnNames,
640  int formatType=0,int numberAcross=2,
641  double objSense=0.0) const ;
643 
648 
649  void newLanguage(CoinMessages::Language language);
650  void setLanguage(CoinMessages::Language language)
651  {newLanguage(language);}
653  //---------------------------------------------------------------------------
654 
657 
658  inline CbcModel * getModelPtr() const
659  { return modelPtr_;}
662  { return modelPtr_->solver();}
664  inline void setCutoff(double value)
665  { modelPtr_->setCutoff(value);}
667  inline double getCutoff() const
668  { return modelPtr_->getCutoff();}
670  inline void setMaximumNodes( int value)
671  { modelPtr_->setMaximumNodes(value);}
673  inline int getMaximumNodes() const
674  { return modelPtr_->getMaximumNodes();}
676  inline void setMaximumSolutions( int value)
677  { modelPtr_->setMaximumSolutions(value);}
679  inline int getMaximumSolutions() const
680  { return modelPtr_->getMaximumSolutions();}
682  inline void setMaximumSeconds( double value)
683  { modelPtr_->setMaximumSeconds(value);}
685  inline double getMaximumSeconds() const
686  { return modelPtr_->getMaximumSeconds();}
688  inline bool isNodeLimitReached() const
689  { return modelPtr_->isNodeLimitReached();}
691  inline bool isSolutionLimitReached() const
692  { return modelPtr_->isSolutionLimitReached();}
694  inline int getNodeCount() const
695  { return modelPtr_->getNodeCount();}
697  inline int status() const
698  { return modelPtr_->status();}
705  virtual void passInMessageHandler(CoinMessageHandler * handler);
707 
708  //---------------------------------------------------------------------------
709 
712 
714  CbcStrategy * strategy=NULL);
715 
717  virtual OsiSolverInterface * clone(bool copyData = true) const;
718 
721 #if 0
722 
723  OsiCbcSolverInterface (CbcModel * rhs, bool reallyOwn=false);
724 
726  void releaseCbc();
727 #endif
728 
730 
732  virtual ~OsiCbcSolverInterface ();
733 
735  //---------------------------------------------------------------------------
736 
737 protected:
739 
740 
741  virtual void applyRowCut(const OsiRowCut& rc);
742 
744  virtual void applyColCut(const OsiColCut& cc);
746 
748 
749  mutable CbcModel * modelPtr_;
751 };
752 // So unit test can find out if NDEBUG set
753 bool OsiCbcHasNDEBUG();
754 
755 //#############################################################################
763 int
764 OsiCbcSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
765 
766 #endif