Dip  0.92.4
OsiSymSolverInterface.hpp
Go to the documentation of this file.
1 /*===========================================================================*/
2 /* */
3 /* This file is part of the SYMPHONY Branch, Cut, and Price Callable */
4 /* Library. */
5 /* */
6 /* SYMPHONY was jointly developed by Ted Ralphs (tkralphs@lehigh.edu) and */
7 /* Laci Ladanyi (ladanyi@us.ibm.com). */
8 /* */
9 /* (c) Copyright 2004-2006 Ted Ralphs and Lehigh University. */
10 /* All Rights Reserved. */
11 /* */
12 /* The authors of this file are Menal Guzelsoy and Ted Ralphs */
13 /* */
14 /* This software is licensed under the Eclipse Public License. Please see */
15 /* accompanying file for terms. */
16 /* */
17 /*===========================================================================*/
18 
19 #ifndef OsiSymSolverInterface_hpp
20 #define OsiSymSolverInterface_hpp
21 
22 #include "OsiSolverInterface.hpp"
24 #include "SymWarmStart.hpp"
25 
26 #include <string>
27 
29 
30 //#############################################################################
31 
53 class OsiSymSolverInterface : virtual public OsiSolverInterface {
54  friend void OsiSymSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
55 
56 public:
58 
59  virtual void initialSolve();
61 
63  virtual void resolve();
64 
66  virtual void branchAndBound();
67 
69  virtual void multiCriteriaBranchAndBound();
70 
72  virtual double getLbForNewRhs(int cnt, int *index,
73  double * value);
75  virtual double getUbForNewRhs(int cnt, int *index,
76  double * value);
77 #if 0
78  virtual double getLbForNewObj(int cnt, int *index,
80  double * value);
82 #endif
83  virtual double getUbForNewObj(int cnt, int *index,
84  double * value);
85 
87 
88  //---------------------------------------------------------------------------
105  // Set an integer parameter
106  virtual bool setIntParam(OsiIntParam key, int value);
107 
108  // Set SYMPHONY int parameter
109  virtual bool setSymParam(OsiSymIntParam key, int value);
110 
111  // Set SYMPHONY int parameter directly by the C interface parameter name
112  virtual bool setSymParam(const std::string key, int value);
113 
114 
115  // Set an double parameter
116  virtual bool setDblParam(OsiDblParam key, double value);
117 
118  // Set SYMPHONY double parameter
119  virtual bool setSymParam(OsiSymDblParam key, double value);
120 
121  // Set SYMPHONY double parameter directly by the C interface parameter name
122  virtual bool setSymParam(const std::string key, double value);
123 
124 
125 
126  // Set a string parameter
127  virtual bool setStrParam(OsiStrParam key, const std::string & value);
128 
129  // Set SYMPHONY string parameter
130  virtual bool setSymParam(OsiSymStrParam key, const std::string & value);
131 
132  // Set SYMPHONY string parameter directly by the C interface parameter name
133  virtual bool setSymParam(const std::string key, const std::string value);
134 
135 
136 
137  // Get an integer parameter
138  virtual bool getIntParam(OsiIntParam key, int& value) const;
139 
140  // Get SYMPHONY int parameter
141  virtual bool getSymParam(OsiSymIntParam key, int& value) const;
142 
143  // Get SYMPHONY int parameter directly by the C interface parameter name
144  virtual bool getSymParam(const std::string key, int& value) const;
145 
146 
147  // Get an double parameter
148  virtual bool getDblParam(OsiDblParam key, double& value) const;
149 
150  // Get SYMPHONY double parameter
151  virtual bool getSymParam(OsiSymDblParam key, double& value) const;
152 
153  // Get SYMPHONY double parameter directly by the C interface parameter name
154  virtual bool getSymParam(const std::string key, double& value) const;
155 
156 
157 
158  // Get a string parameter
159  virtual bool getStrParam(OsiStrParam key, std::string& value) const;
160 
161  // Get SYMPHONY string parameter
162  virtual bool getSymParam(OsiSymStrParam key, std::string& value) const;
163 
164  // Get SYMPHONY string parameter directly by the C interface parameter name
165  virtual bool getSymParam(const std::string key, std::string& value) const;
166 
168 
169  //---------------------------------------------------------------------------
171 
172  virtual bool isAbandoned() const;
174 
176  virtual bool isProvenOptimal() const;
177 
179  virtual bool isProvenPrimalInfeasible() const;
180 
182  virtual bool isProvenDualInfeasible() const {
183  throw CoinError("Error: Function not implemented",
184  "isProvenDualInfeasible", "OsiSymSolverInterface");
185  }
187  //virtual bool isPrimalObjectiveLimitReached() const;
188 
190  //virtual bool isDualObjectiveLimitReached() const{
191  // throw CoinError("Error: Function not implemented",
192  // "isDualObjectiveLimitReached", "OsiSymSolverInterface");
193  //}
195  virtual bool isIterationLimitReached() const;
196 
198  virtual bool isTimeLimitReached() const;
199 
201  virtual bool isTargetGapReached() const;
202 
204 
205  //---------------------------------------------------------------------------
215  virtual CoinWarmStart *getEmptyWarmStart () const{
216  throw CoinError("Error: Function not implemented",
217  "getEmptyWarmStart", "OsiSymSolverInterface");
218  }
219 
226  /*
227  virtual CoinWarmStart* getWarmStart(bool keepTreeInSymEnv = false) const;
228  */
229 
230  virtual CoinWarmStart* getWarmStart() const;
231 
236  virtual bool setWarmStart(const CoinWarmStart* warmstart);
238 
239  //---------------------------------------------------------------------------
250  sym_environment *getSymphonyEnvironment() const {return env_;}
252 
254  virtual int getNumCols() const;
255 
257  virtual int getNumRows() const;
258 
260  virtual int getNumElements() const;
261 
263  virtual const double * getColLower() const;
264 
266  virtual const double * getColUpper() const;
267 
277  virtual const char * getRowSense() const;
278 
291  virtual const double * getRightHandSide() const;
292 
301  virtual const double * getRowRange() const;
302 
304  virtual const double * getRowLower() const;
305 
307  virtual const double * getRowUpper() const;
308 
310  virtual const double * getObjCoefficients() const;
311 
315  virtual const double * getObj2Coefficients() const;
316 
318  virtual double getObjSense() const;
319 
321  virtual bool isContinuous(int colIndex) const;
322 
324  virtual bool isBinary(int colIndex) const;
325 
330  virtual bool isInteger(int colIndex) const;
331 
333  virtual bool isIntegerNonBinary(int colIndex) const;
334 
336  virtual bool isFreeBinary(int colIndex) const;
337 
339  virtual const CoinPackedMatrix * getMatrixByRow() const;
340 
342  virtual const CoinPackedMatrix * getMatrixByCol() const;
343 
345  virtual double getInfinity() const;
346 
348 
351  virtual const double * getColSolution() const;
353 
355  virtual const double * getRowPrice() const;
356 
358  virtual const double * getReducedCost() const;
359 
362  virtual const double * getRowActivity() const;
363 
365  virtual double getObjValue() const;
366 
368  virtual double getPrimalBound() const;
369 
372  virtual int getIterationCount() const;
373 
387  virtual std::vector<double*> getDualRays(int maxNumRays,
388  bool fullRay = false) const{
389  throw CoinError("Error: Function not implemented",
390  "getDualRays", "OsiSymSolverInterface");
391  }
403  virtual std::vector<double*> getPrimalRays(int maxNumRays) const{
404  throw CoinError("Error: Function not implemented",
405  "getPrimalRays", "OsiSymSolverInterface");
406  }
407 
409 
410  //-------------------------------------------------------------------------
423  virtual void setObjCoeff( int elementIndex, double elementValue );
424 
426  virtual void setObj2Coeff( int elementIndex, double elementValue );
427 
431  virtual void setColLower( int elementIndex, double elementValue );
432 
436  virtual void setColUpper( int elementIndex, double elementValue );
437 
440  virtual void setRowLower( int elementIndex, double elementValue );
441 
444  virtual void setRowUpper( int elementIndex, double elementValue );
445 
447  virtual void setRowType(int index, char sense, double rightHandSide,
448  double range);
449 
452  virtual void setObjSense(double s);
453 
463  virtual void setColSolution(const double *colsol);
464 
467  virtual void setPrimalBound(const double bound);
468 
479  virtual void setRowPrice(const double * rowprice);
480 
482 
483  //-------------------------------------------------------------------------
486 
489  virtual void setContinuous(int index);
490 
493  virtual void setInteger(int index);
494 
495 
497  virtual void setColName(char **colname);
498 
500  //-------------------------------------------------------------------------
501 
502  //-------------------------------------------------------------------------
509 
512  virtual void addCol(const CoinPackedVectorBase& vec,
513  const double collb, const double colub,
514  const double obj);
515 
517  virtual void deleteCols(const int num, const int * colIndices);
518 
521  virtual void addRow(const CoinPackedVectorBase& vec,
522  const double rowlb, const double rowub);
524  virtual void addRow(const CoinPackedVectorBase& vec,
525  const char rowsen, const double rowrhs,
526  const double rowrng);
527 
529  virtual void deleteRows(const int num, const int * rowIndices);
530 
532 
533  //---------------------------------------------------------------------------
534 
537 
538  virtual void loadProblem();
539 
551  virtual void loadProblem(const CoinPackedMatrix& matrix,
552  const double* collb, const double* colub,
553  const double* obj,
554  const double* rowlb, const double* rowub);
555 
565  virtual void assignProblem(CoinPackedMatrix*& matrix,
566  double*& collb, double*& colub, double*& obj,
567  double*& rowlb, double*& rowub);
568 
581  virtual void loadProblem(const CoinPackedMatrix& matrix,
582  const double* collb, const double* colub,
583  const double* obj,
584  const char* rowsen, const double* rowrhs,
585  const double* rowrng);
586 
596  virtual void assignProblem(CoinPackedMatrix*& matrix,
597  double*& collb, double*& colub, double*& obj,
598  char*& rowsen, double*& rowrhs,
599  double*& rowrng);
600 
603  virtual void loadProblem(const int numcols, const int numrows,
604  const CoinBigIndex * start, const int* index,
605  const double* value,
606  const double* collb, const double* colub,
607  const double* obj,
608  const double* rowlb, const double* rowub);
609 
612  virtual void loadProblem(const int numcols, const int numrows,
613  const CoinBigIndex * start, const int* index,
614  const double* value,
615  const double* collb, const double* colub,
616  const double* obj,
617  const char* rowsen, const double* rowrhs,
618  const double* rowrng);
619 
626  virtual void writeMps(const char *filename,
627  const char *extension = "mps",
628  double objSense=0.0) const;
629 
630  void parseCommandLine(int argc, char **argv);
631 
633  virtual int readMps(const char * infile, const char *extension = "mps");
634 
635  virtual int readGMPL(const char * modelFile, const char * dataFile=NULL);
636 
637  void findInitialBounds();
638 
640 
642 
643  //---------------------------------------------------------------------------
644 
668  };
669 
671 
674 
680  virtual OsiSolverInterface * clone(bool copyData = true) const;
681 
684 
687 
689  virtual ~OsiSymSolverInterface ();
690 
697  virtual void reset();
699 
700  //---------------------------------------------------------------------------
701 
702 protected:
704 
705 
706  virtual void applyRowCut( const OsiRowCut & rc );
707 
709  virtual void applyColCut( const OsiColCut & cc );
710 
718  void setInitialData();
720 
721 private:
722 
724  void gutsOfConstructor();
725 
727  void gutsOfDestructor();
728 
730  void freeCachedColRim();
731 
733  void freeCachedRowRim();
734 
736  void freeCachedResults();
737 
739  void freeCachedMatrix();
740 
742  void freeCachedData( int keepCached = KEEPCACHED_NONE );
743 
745  void freeAllMemory();
746 
752 
754  mutable double *obj_;
755 
757  mutable double *obj2_;
758 
760  mutable double *collower_;
761 
763  mutable double *colupper_;
764 
766  mutable double *colredcost_;
767 
769  mutable char *rowsense_;
770 
772  mutable double *rhs_;
773 
777  mutable double *rowrange_;
778 
780  mutable double *rowlower_;
781 
783  mutable double *rowupper_;
784 
786  mutable double *rowprice_;
787 
789  mutable double *colsol_;
790 
792  mutable double *rowact_;
793 
796 
799 
800 };
801 
802 //#############################################################################
804 void OsiSymSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
805 
806 #endif
virtual void deleteCols(const int num, const int *colIndices)
Remove a set of columns (primal variables) from the problem.
keep all cached data (similar to getMutableLpPtr())
int CoinBigIndex
void freeCachedData(int keepCached=KEEPCACHED_NONE)
free all cached data (except specified entries, see getLpPtr())
virtual void setColLower(int elementIndex, double elementValue)=0
Set a single column lower bound.
virtual int readGMPL(const char *modelFile, const char *dataFile=NULL)
Load in an problem by copying the arguments (the constraints on the rows are given by lower and upper...
double * obj2_
Pointer to second objective vector to be used in bicriteria solver.
virtual const double * getColLower() const
Get pointer to array[getNumCols()] of column lower bounds.
virtual CoinWarmStart * getWarmStart() const
Get warm start information.
virtual bool isAbandoned() const
Are there numerical difficulties?
virtual void loadProblem()
Load in an problem by copying the arguments (the constraints on the rows are given by lower and upper...
virtual double getObjSense() const
Get objective function sense (1 for min (default), -1 for max)
virtual const double * getObj2Coefficients() const
Get pointer to array[getNumCols()] of second objective function coefficients if loaded before...
virtual bool isInteger(int colIndex) const
Return true if column is integer.
virtual void applyRowCut(const OsiRowCut &rc)
Apply a row cut (append to the constraint matrix).
virtual void setContinuous(int index)
Set the index-th variable to be a continuous variable.
virtual bool getSymParam(OsiSymIntParam key, int &value) const
virtual bool isProvenDualInfeasible() const
Is dual infeasiblity proven?
double * rowupper_
Pointer to dense vector of row upper bounds.
void freeAllMemory()
free all allocated memory
virtual const double * getColSolution() const
Get pointer to array[getNumCols()] of primal variable values.
OSI Solver Interface for SYMPHONY.
Column Cut Class.
Definition: OsiColCut.hpp:23
virtual const CoinPackedMatrix * getMatrixByRow() const
Get pointer to row-wise copy of matrix.
virtual bool getIntParam(OsiIntParam key, int &value) const
Get an integer parameter.
OsiSymSolverInterface & operator=(const OsiSymSolverInterface &rhs)
Assignment operator.
virtual void branchAndBound()
Invoke solver&#39;s built-in enumeration algorithm.
virtual int getNumRows() const
Get number of rows.
virtual void addRow(const CoinPackedVectorBase &vec, const double rowlb, const double rowub)
Add a row (constraint) to the problem.
virtual void addCol(const CoinPackedVectorBase &vec, const double collb, const double colub, const double obj)=0
Add a column (primal variable) to the problem.
virtual void setContinuous(int index)=0
Set the index-th variable to be a continuous variable.
Row Cut Class.
Definition: OsiRowCut.hpp:29
virtual void setColName(int ndx, std::string name)
Set a column name.
virtual const double * getRowActivity() const
Get pointer to array[getNumRows()] of row activity levels (constraint matrix times the solution ve...
virtual void setRowType(int index, char sense, double rightHandSide, double range)
Set the type of a single row.
virtual bool isProvenPrimalInfeasible() const
Is primal infeasiblity proven?
virtual bool setIntParam(OsiIntParam key, int value)
Set an integer parameter.
virtual ~OsiSymSolverInterface()
Destructor.
void gutsOfDestructor()
The real work of the destructor.
char * rowsense_
Pointer to dense vector of row sense indicators.
virtual void reset()
Reset the solver interface.
virtual void initialSolve()
Solve initial LP relaxation.
virtual std::vector< double * > getDualRays(int maxNumRays, bool fullRay=false) const
Get as many dual rays as the solver can provide.
virtual double getLbForNewRhs(int cnt, int *index, double *value)
Get a lower bound for the new rhs problem using the warm start tree.
virtual void multiCriteriaBranchAndBound()
Invoke solver&#39;s multi-criteria enumeration algorithm.
virtual CoinWarmStart * getEmptyWarmStart() const
Get an empty warm start object.
virtual bool setDblParam(OsiDblParam key, double value)
Set a double parameter.
free only cached LP solution information
Sparse Matrix Base Class.
problem matrix: matrix ordered by column and by row
virtual double getUbForNewRhs(int cnt, int *index, double *value)
Get an upper bound for the new rhs problem using the warm start tree.
virtual const double * getReducedCost() const
Get a pointer to array[getNumCols()] of reduced costs.
free only cached matrix and LP solution information
double * rowrange_
Pointer to dense vector of slack upper bounds for range constraints (undefined for non-range rows) ...
virtual void deleteRows(const int num, const int *rowIndices)
Delete a set of rows (constraints) from the problem.
void freeCachedResults()
free cached result vectors
virtual int readMps(const char *filename, const char *extension="mps")
Read a problem in MPS format from the given filename.
double * rowlower_
Pointer to dense vector of row lower bounds.
virtual std::vector< double * > getPrimalRays(int maxNumRays) const
Get as many primal rays as the solver can provide.
virtual void setColUpper(int elementIndex, double elementValue)=0
Set a single column upper bound.
virtual bool isTimeLimitReached() const
Time limit reached?
virtual bool isContinuous(int colIndex) const
Return true if variable is continuous.
void findInitialBounds()
Load in an problem by copying the arguments (the constraints on the rows are given by lower and upper...
virtual void addCol(const CoinPackedVectorBase &vec, const double collb, const double colub, const double obj)
Add a column (primal variable) to the problem.
row information: right hand sides, ranges and senses, lower and upper bounds for row ...
Abstract base class for various sparse vectors.
virtual bool isIntegerNonBinary(int colIndex) const
Return true if variable is general integer.
virtual bool setStrParam(OsiStrParam key, const std::string &value)
Set a string parameter.
virtual double getInfinity() const
Get solver&#39;s value for infinity.
virtual int readMps(const char *infile, const char *extension="mps")
Load in an problem by copying the arguments (the constraints on the rows are given by lower and upper...
virtual double getUbForNewObj(int cnt, int *index, double *value)
Solve initial LP relaxation.
int createPermanentCutPools()
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 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...
virtual void setObjSense(double s)
Set the objective function sense.
sym_environment * getSymphonyEnvironment() const
Get pointer to SYMPHONY environment (eventually we won&#39;t need this)
virtual bool isTargetGapReached() const
Target gap achieved?
void freeCachedColRim()
free cached column rim vectors
free only cached column and LP solution information
virtual void applyColCut(const OsiColCut &cc)
Apply a column cut (adjust the bounds of one or more variables).
sym_environment * env_
The pointer to the SYMPHONY problem environment.
virtual bool getStrParam(OsiStrParam key, std::string &value) const
Get a string parameter.
virtual int getNumElements() const
Get number of nonzero elements.
virtual OsiSolverInterface * clone(bool copyData=true) const
Clone.
column information: objective values, lower and upper bounds, variable types
double * colredcost_
Pointer to dense vector of variable lower bounds.
virtual const double * getRowPrice() const
Get pointer to array[getNumRows()] of dual variable values.
free only cached row and LP solution information
virtual void setRowUpper(int elementIndex, double elementValue)
Set a single row upper bound.
virtual void setInteger(int index)=0
Set the index-th variable to be an integer variable.
double * collower_
Pointer to dense vector of variable lower bounds.
double * rowprice_
Pointer to dense vector of row prices.
virtual double getObjValue() const
Get objective function value.
double * obj_
Pointer to objective vector.
LP solution: primal and dual solution, reduced costs, row activities.
virtual void setColSolution(const double *colsol)
Set the primal solution variable values.
friend void OsiSymSolverInterfaceUnitTest(const std::string &mpsDir, const std::string &netlibDir)
A function that tests the methods in the OsiSymSolverInterface class.
virtual bool isBinary(int colIndex) const
Return true if variable is binary.
double * colsol_
Pointer to primal solution vector.
Abstract Base Class for describing an interface to a solver.
virtual void setPrimalBound(const double bound)
Set the a priori upper/lower bound.
virtual const double * getObjCoefficients() const
Get pointer to array[getNumCols()] of objective function coefficients.
virtual int getIterationCount() const
Get the number of iterations it took to solve the problem (whatever ``iteration&#39;&#39; means to the solve...
virtual const double * getRowLower() const
Get pointer to array[getNumRows()] of row lower bounds.
discard all cached data (default)
virtual bool isIterationLimitReached() const
Is the given primal objective limit reached?
void gutsOfConstructor()
The real work of the constructor.
virtual void addRow(const CoinPackedVectorBase &vec, const double rowlb, const double rowub)=0
Add a row (constraint) to the problem.
Abstract base class for warm start information.
virtual const double * getRowUpper() const
Get pointer to array[getNumRows()] of row upper bounds.
virtual void setRowPrice(const double *rowprice)
Set dual solution variable values.
Error Class thrown by an exception.
Definition: CoinError.hpp:42
void parseCommandLine(int argc, char **argv)
Load in an problem by copying the arguments (the constraints on the rows are given by lower and upper...
virtual void setRowLower(int elementIndex, double elementValue)
Set a single row lower bound.
virtual bool isFreeBinary(int colIndex) const
Return true if variable is binary and not fixed at either bound.
virtual const CoinPackedMatrix * getMatrixByCol() const
Get pointer to column-wise copy of matrix.
virtual const double * getRightHandSide() const
Get pointer to array[getNumRows()] of row right-hand sides.
void OsiSymSolverInterfaceUnitTest(const std::string &mpsDir, const std::string &netlibDir)
A function that tests the methods in the OsiSymSolverInterface class.
double * rowact_
Pointer to row activity (slack) vector.
virtual const double * getRowRange() const
Get pointer to array[getNumRows()] of row ranges.
void freeCachedMatrix()
free cached matrices
virtual bool setSymParam(OsiSymIntParam key, int value)
virtual bool setWarmStart(const CoinWarmStart *warmstart)
Set warm start information.
virtual bool isProvenOptimal() const
Is optimality proven?
virtual void setColName(char **colname)
Set the index-th variable to be a continuous variable.
double * rhs_
Pointer to dense vector of row right-hand side values.
virtual const char * getRowSense() const
Get pointer to array[getNumRows()] of row constraint senses.
virtual void setColUpper(int elementIndex, double elementValue)
Set a single column upper bound.
CoinPackedMatrix * matrixByRow_
Pointer to row-wise copy of problem matrix coefficients.
virtual void writeMps(const char *filename, const char *extension="mps", double objSense=0.0) const
Write the problem in MPS format to the specified file.
virtual bool getDblParam(OsiDblParam key, double &value) const
Get a double parameter.
OsiSymSolverInterface()
Default Constructor.
CoinPackedMatrix * matrixByCol_
Pointer to row-wise copy of problem matrix coefficients.
virtual int getNumCols() const
Get number of columns.
double * colupper_
Pointer to dense vector of variable lower bounds.
virtual void setObj2Coeff(int elementIndex, double elementValue)
Set an objective function coefficient for the second objective.
virtual void resolve()
Resolve an IP problem modification.
void setInitialData()
Set OsiSolverInterface object state for default constructor.
void freeCachedRowRim()
free cached row rim vectors
virtual void setColLower(int elementIndex, double elementValue)
Set a single column lower bound.
virtual void setObjCoeff(int elementIndex, double elementValue)
Set an objective function coefficient.
virtual void setInteger(int index)
Set the index-th variable to be an integer variable.
virtual double getPrimalBound() const
Get the current upper/lower bound.