Osi  0.106.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
OsiSpxSolverInterface.hpp
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 // name: OSI Interface for SoPlex >= 1.4.2c
3 // authors: Tobias Pfender
4 // Ambros Gleixner
5 // Wei Huang
6 // Konrad-Zuse-Zentrum Berlin (Germany)
7 // email: pfender@zib.de
8 // date: 01/16/2002
9 // license: this file may be freely distributed under the terms of the EPL
10 //-----------------------------------------------------------------------------
11 // Copyright (C) 2002, Tobias Pfender, International Business Machines
12 // Corporation and others. All Rights Reserved.
13 // Last edit: $Id: OsiSpxSolverInterface.hpp 1762 2011-06-25 17:56:55Z stefan $
14 
15 #ifndef OsiSpxSolverInterface_H
16 #define OsiSpxSolverInterface_H
17 
18 #include <string>
19 #include "OsiSolverInterface.hpp"
20 #include "CoinWarmStartBasis.hpp"
21 
22 /* forward declarations so the header can be compiled without having to include soplex.h */
23 namespace soplex {
24  class DIdxSet;
25  class DVector;
26  class SoPlex;
27 }
28 
32 class OsiSpxSolverInterface : virtual public OsiSolverInterface {
33  friend void OsiSpxSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
34 
35 public:
36 
37  //---------------------------------------------------------------------------
40  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  // Get an integer parameter
71  bool getIntParam(OsiIntParam key, int& value) const;
72  // Get an double parameter
73  bool getDblParam(OsiDblParam key, double& value) const;
74  // Get a string parameter
75  bool getStrParam(OsiStrParam key, std::string& value) const;
76  // Set timelimit
77  void setTimeLimit(double value);
78  // Get timelimit
79  double getTimeLimit() const;
81 
82  //---------------------------------------------------------------------------
84 
85  virtual bool isAbandoned() const;
88  virtual bool isProvenOptimal() const;
90  virtual bool isProvenPrimalInfeasible() const;
92  virtual bool isProvenDualInfeasible() const;
93  // Is the given primal objective limit reached? - use implementation from OsiSolverInterface
95  virtual bool isDualObjectiveLimitReached() const;
97  virtual bool isIterationLimitReached() const;
99  virtual bool isTimeLimitReached() const;
101 
102  //---------------------------------------------------------------------------
105  inline CoinWarmStart *getEmptyWarmStart () const
107  { return (dynamic_cast<CoinWarmStart *>(new CoinWarmStartBasis())) ; }
109  virtual CoinWarmStart* getWarmStart() const;
112  virtual bool setWarmStart(const CoinWarmStart* warmstart);
114 
115  //---------------------------------------------------------------------------
122  virtual void markHotStart();
125  virtual void solveFromHotStart();
127  virtual void unmarkHotStart();
129 
130  //---------------------------------------------------------------------------
145  virtual int getNumCols() const;
147 
149  virtual int getNumRows() const;
150 
152  virtual int getNumElements() const;
153 
155  virtual const double * getColLower() const;
156 
158  virtual const double * getColUpper() const;
159 
169  virtual const char * getRowSense() const;
170 
179  virtual const double * getRightHandSide() const;
180 
189  virtual const double * getRowRange() const;
190 
192  virtual const double * getRowLower() const;
193 
195  virtual const double * getRowUpper() const;
196 
198  virtual const double * getObjCoefficients() const;
199 
201  virtual double getObjSense() const;
202 
204  virtual bool isContinuous(int colNumber) const;
205 
206 #if 0
207  virtual bool isBinary(int columnNumber) const;
209 
214  virtual bool isInteger(int columnNumber) const;
215 
217  virtual bool isIntegerNonBinary(int columnNumber) const;
218 
220  virtual bool isFreeBinary(int columnNumber) const;
221 #endif
222 
224  virtual const CoinPackedMatrix * getMatrixByRow() const;
225 
227  virtual const CoinPackedMatrix * getMatrixByCol() const;
228 
230  virtual double getInfinity() const;
232 
235  virtual const double * getColSolution() const;
237 
239  virtual const double * getRowPrice() const;
240 
242  virtual const double * getReducedCost() const;
243 
246  virtual const double * getRowActivity() const;
247 
249  virtual double getObjValue() const;
250 
253  virtual int getIterationCount() const;
254 
272  virtual std::vector<double*> getDualRays(int maxNumRays,
273  bool fullRay=false) const;
285  virtual std::vector<double*> getPrimalRays(int maxNumRays) const;
286 
287 #if 0
288 
290  virtual OsiVectorInt getFractionalIndices(const double etol=1.e-05)
291  const;
292 #endif
293 
294 
295 
296  //---------------------------------------------------------------------------
297 
300  //-------------------------------------------------------------------------
304  virtual void setObjCoeff( int elementIndex, double elementValue );
305 
308  virtual void setColLower( int elementIndex, double elementValue );
309 
312  virtual void setColUpper( int elementIndex, double elementValue );
313 
317  virtual void setColBounds( int elementIndex,
318  double lower, double upper );
319 
320 #if 0 // we are using the default implementation of OsiSolverInterface
321 
329  virtual void setColSetBounds(const int* indexFirst,
330  const int* indexLast,
331  const double* boundList);
332 #endif
333 
336  virtual void setRowLower( int elementIndex, double elementValue );
337 
340  virtual void setRowUpper( int elementIndex, double elementValue );
341 
345  virtual void setRowBounds( int elementIndex,
346  double lower, double upper );
347 
349  virtual void setRowType(int index, char sense, double rightHandSide,
350  double range);
351 
352 #if 0 // we are using the default implementation of OsiSolverInterface
353 
360  virtual void setRowSetBounds(const int* indexFirst,
361  const int* indexLast,
362  const double* boundList);
363 
373  virtual void setRowSetTypes(const int* indexFirst,
374  const int* indexLast,
375  const char* senseList,
376  const double* rhsList,
377  const double* rangeList);
378 #endif
379 
380 
381  //-------------------------------------------------------------------------
385  virtual void setContinuous(int index);
387  virtual void setInteger(int index);
388 #if 0 // we are using the default implementation of OsiSolverInterface
389 
391  virtual void setContinuous(const int* indices, int len);
394  virtual void setInteger(const int* indices, int len);
395 #endif
396 
397 
398  //-------------------------------------------------------------------------
400  virtual void setObjSense(double s);
401 
412  virtual void setColSolution(const double * colsol);
413 
424  virtual void setRowPrice(const double * rowprice);
425 
426  //-------------------------------------------------------------------------
432  virtual void addCol(const CoinPackedVectorBase& vec,
433  const double collb, const double colub,
434  const double obj);
435 
436 #if 0 // we are using the default implementation of OsiSolverInterface
437 
438  virtual void addCols(const int numcols,
439  const CoinPackedVectorBase * const * cols,
440  const double* collb, const double* colub,
441  const double* obj);
442 #endif
443 
445  virtual void deleteCols(const int num, const int * colIndices);
446 
448  virtual void addRow(const CoinPackedVectorBase& vec,
449  const double rowlb, const double rowub);
451  virtual void addRow(const CoinPackedVectorBase& vec,
452  const char rowsen, const double rowrhs,
453  const double rowrng);
454 
455 #if 0 // we are using the default implementation of OsiSolverInterface
456 
457  virtual void addRows(const int numrows,
458  const CoinPackedVectorBase * const * rows,
459  const double* rowlb, const double* rowub);
461  virtual void addRows(const int numrows,
462  const CoinPackedVectorBase * const * rows,
463  const char* rowsen, const double* rowrhs,
464  const double* rowrng);
465 #endif
466 
468  virtual void deleteRows(const int num, const int * rowIndices);
469 
470 #if 0 // we are using the default implementation of OsiSolverInterface
471  //-----------------------------------------------------------------------
493  virtual ApplyCutsReturnCode applyCuts(const OsiCuts & cs,
494  double effectivenessLb = 0.0);
495 #endif
496 
497 
498 
499  //---------------------------------------------------------------------------
500 
514  virtual void loadProblem(const CoinPackedMatrix& matrix,
515  const double* collb, const double* colub,
516  const double* obj,
517  const double* rowlb, const double* rowub);
518 
526  virtual void assignProblem(CoinPackedMatrix*& matrix,
527  double*& collb, double*& colub, double*& obj,
528  double*& rowlb, double*& rowub);
529 
542  virtual void loadProblem(const CoinPackedMatrix& matrix,
543  const double* collb, const double* colub,
544  const double* obj,
545  const char* rowsen, const double* rowrhs,
546  const double* rowrng);
547 
555  virtual void assignProblem(CoinPackedMatrix*& matrix,
556  double*& collb, double*& colub, double*& obj,
557  char*& rowsen, double*& rowrhs,
558  double*& rowrng);
559 
562  virtual void loadProblem(const int numcols, const int numrows,
563  const int* start, const int* index,
564  const double* value,
565  const double* collb, const double* colub,
566  const double* obj,
567  const double* rowlb, const double* rowub);
568 
571  virtual void loadProblem(const int numcols, const int numrows,
572  const int* start, const int* index,
573  const double* value,
574  const double* collb, const double* colub,
575  const double* obj,
576  const char* rowsen, const double* rowrhs,
577  const double* rowrng);
578 
580  virtual int readMps(const char *filename,
581  const char *extension = "mps");
582 
587  virtual void writeMps(const char *filename,
588  const char *extension = "mps",
589  double objSense=0.0) const;
591 
592  //---------------------------------------------------------------------------
593 
598 
600  virtual OsiSolverInterface * clone(bool copyData = true) const;
601 
604 
607 
609  virtual ~OsiSpxSolverInterface();
611 
612 protected:
613 
616  virtual void applyRowCut( const OsiRowCut & rc );
618 
622  virtual void applyColCut( const OsiColCut & cc );
624 
627  soplex::SoPlex* soplex_;
630 
631 
632 private:
635 
637  void freeCachedColRim();
638 
640  void freeCachedRowRim();
641 
643  void freeCachedResults();
644 
646  void freeCachedMatrix();
647 
649  {
672  };
673 
675  void freeCachedData( int keepCached = KEEPCACHED_NONE );
676 
678  void freeAllMemory();
680 
681 
684  soplex::DIdxSet* spxintvars_;
686 
693 
696  mutable soplex::DVector *obj_;
698 
700  mutable char *rowsense_;
701 
703  mutable double *rhs_;
704 
706  mutable double *rowrange_;
707 
709  mutable soplex::DVector *colsol_;
710 
712  mutable soplex::DVector *rowsol_;
713 
715  mutable soplex::DVector *redcost_;
716 
718  mutable soplex::DVector *rowact_;
719 
721  mutable CoinPackedMatrix *matrixByRow_;
722 
724  mutable CoinPackedMatrix *matrixByCol_;
726 
727 };
728 
729 //#############################################################################
731 void OsiSpxSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
732 
733 #endif
virtual void setRowSetTypes(const int *indexFirst, const int *indexLast, const char *senseList, const double *rhsList, const double *rangeList)
Set the type of a set of rows.
virtual const double * getRowRange() const
Get pointer to array[getNumRows()] of row ranges.
SoPlex Solver Interface Instantiation of OsiSpxSolverInterface for SoPlex.
virtual void applyRowCut(const OsiRowCut &rc)
Apply a row cut. Return true if cut was applied.
char * rowsense_
Pointer to dense vector of row sense indicators.
column information: objective values, lower and upper bounds, variable types
virtual void setColLower(int elementIndex, double elementValue)
Set a single column lower bound Use -COIN_DBL_MAX for -infinity.
virtual OsiSolverInterface * clone(bool copyData=true) const
Clone.
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 bool isAbandoned() const
Are there a numerical difficulties?
virtual bool isIntegerNonBinary(int colIndex) const
Return true if the variable is general integer.
virtual bool isContinuous(int colNumber) const
Return true if column is continuous.
virtual void unmarkHotStart()
Delete the snapshot.
CoinPackedMatrix * matrixByRow_
Pointer to row-wise copy of problem matrix coefficients.
virtual const double * getColSolution() const
Get pointer to array[getNumCols()] of primal solution vector.
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.
virtual void setColSetBounds(const int *indexFirst, const int *indexLast, const double *boundList)
Set the upper and lower bounds of a set of columns.
virtual double getInfinity() const
Get solver's value for infinity.
soplex::DVector * rowsol_
Pointer to dual solution vector.
double * rowrange_
Pointer to dense vector of slack upper bounds for range constraints (undefined for non-range rows) ...
Collections of row cuts and column cuts.
Definition: OsiCuts.hpp:19
Column Cut Class.
Definition: OsiColCut.hpp:23
virtual double getObjValue() const
Get objective function value.
virtual const double * getObjCoefficients() const
Get pointer to array[getNumCols()] of objective function coefficients.
virtual int readMps(const char *filename, const char *extension="mps")
Read an mps file from the given filename.
virtual void markHotStart()
Create a hotstart point of the optimization process.
virtual void setRowType(int index, char sense, double rightHandSide, double range)
Set the type of a single row
virtual void setRowLower(int elementIndex, double elementValue)
Set a single row lower bound Use -COIN_DBL_MAX for -infinity.
CoinPackedMatrix * matrixByCol_
Pointer to row-wise copy of problem matrix coefficients.
virtual bool isProvenDualInfeasible() const
Is dual infeasiblity proven?
virtual void addRow(const CoinPackedVectorBase &vec, const double rowlb, const double rowub)
Add a row (constraint) to the problem.
free only cached row and LP solution information
void freeCachedMatrix()
free cached matrices
virtual bool isInteger(int colIndex) const
Return true if the variable is integer.
virtual const double * getReducedCost() const
Get a pointer to array[getNumCols()] of reduced costs.
virtual bool isProvenOptimal() const
Is optimality proven?
problem matrix: matrix ordered by column and by row
virtual const CoinPackedMatrix * getMatrixByRow() const
Get pointer to row-wise copy of matrix.
Abstract Base Class for describing an interface to a solver.
virtual const CoinPackedMatrix * getMatrixByCol() const
Get pointer to column-wise copy of matrix.
virtual bool setWarmStart(const CoinWarmStart *warmstart)
Set warmstarting information.
virtual bool isTimeLimitReached() const
Time limit reached?
void freeAllMemory()
free all allocated memory
void * hotStartCStat_
Hotstart information.
virtual int getIterationCount() const
Get how many iterations it took to solve the problem (whatever "iteration" mean to the solver...
OsiSpxSolverInterface()
Default Constructor.
virtual OsiVectorInt getFractionalIndices(const double etol=1.e-05) const
Get vector of indices of primal variables which are integer variables but have fractional values in t...
virtual void deleteCols(const int num, const int *colIndices)
Remove a set of columns (primal variables) from the problem.
virtual const double * getRowUpper() const
Get pointer to array[getNumRows()] of row upper bounds.
virtual const double * getRightHandSide() const
Get pointer to array[getNumRows()] of rows right-hand sides.
virtual bool isIterationLimitReached() const
Iteration limit reached?
discard all cached data (default)
virtual void setColUpper(int elementIndex, double elementValue)
Set a single column upper bound Use COIN_DBL_MAX for infinity.
virtual void setColSolution(const double *colsol)
Set the primal solution column values.
void freeCachedColRim()
free cached column rim vectors
virtual CoinWarmStart * getWarmStart() const
Get warmstarting information.
std::vector< int > OsiVectorInt
Vector of int.
virtual void setContinuous(int index)
Set the index-th variable to be a continuous variable.
virtual void addRows(const int numrows, const CoinPackedVectorBase *const *rows, const double *rowlb, const double *rowub)
Add a set of rows (constraints) to the problem.
virtual void addCol(const CoinPackedVectorBase &vec, const double collb, const double colub, const double obj)
Add a column (primal variable) to the problem.
virtual const double * getRowLower() const
Get pointer to array[getNumRows()] of row lower bounds.
virtual int getNumRows() const
Get number of rows.
soplex::DVector * obj_
Pointer to objective Vector.
virtual void branchAndBound()
Invoke solver's built-in enumeration algorithm.
virtual int getNumCols() const
Get number of columns.
bool setIntParam(OsiIntParam key, int value)
Set an integer parameter.
virtual void addCols(const int numcols, const CoinPackedVectorBase *const *cols, const double *collb, const double *colub, const double *obj)
Add a set of columns (primal variables) to the problem.
soplex::DVector * colsol_
Pointer to primal solution vector.
virtual bool isBinary(int colIndex) const
Return true if the variable is binary.
row information: right hand sides, ranges and senses, lower and upper bounds for row ...
void setTimeLimit(double value)
virtual void initialSolve()
Solve initial LP relaxation.
keep all cached data (similar to getMutableLpPtr())
void freeCachedRowRim()
free cached row rim vectors
void freeCachedData(int keepCached=KEEPCACHED_NONE)
free all cached data (except specified entries, see getLpPtr())
double getTimeLimit() const
free only cached LP solution information
Row Cut Class.
Definition: OsiRowCut.hpp:29
bool getStrParam(OsiStrParam key, std::string &value) const
Get a string parameter.
virtual void setObjSense(double s)
Set objective function sense (1 for min (default), -1 for max,)
void freeCachedResults()
free cached result vectors
virtual ApplyCutsReturnCode applyCuts(const OsiCuts &cs, double effectivenessLb=0.0)
Apply a collection of cuts.
virtual void solveFromHotStart()
Optimize starting from the hotstart.
virtual void resolve()
Resolve an LP relaxation after problem modification.
free only cached matrix and LP solution information
virtual void setRowSetBounds(const int *indexFirst, const int *indexLast, const double *boundList)
Set the bounds on a set of rows.
virtual void setInteger(int index)
Set the index-th variable to be an integer variable.
double * rhs_
Pointer to dense vector of row right-hand side values.
soplex::DIdxSet * spxintvars_
indices of integer variables
virtual bool isDualObjectiveLimitReached() const
Is the given dual objective limit reached?
virtual int getNumElements() const
Get number of nonzero elements.
soplex::DVector * rowact_
Pointer to row activity (slack) vector.
virtual bool isFreeBinary(int colIndex) const
Return true if the variable is binary and not fixed.
virtual ~OsiSpxSolverInterface()
Destructor.
virtual void setObjCoeff(int elementIndex, double elementValue)
Set an objective function coefficient.
free only cached column and LP solution information
virtual void setRowUpper(int elementIndex, double elementValue)
Set a single row upper bound Use COIN_DBL_MAX for infinity.
virtual void setRowPrice(const double *rowprice)
Set dual solution vector.
virtual std::vector< double * > getPrimalRays(int maxNumRays) const
Get as many primal rays as the solver can provide.
virtual void setRowBounds(int elementIndex, double lower, double upper)
Set a single row lower and upper bound The default implementation just invokes setRowUower and setRo...
virtual void applyColCut(const OsiColCut &cc)
Apply a column cut (bound adjustment).
virtual void deleteRows(const int num, const int *rowIndices)
Delete a set of rows (constraints) from the problem.
virtual const double * getColUpper() const
Get pointer to array[getNumCols()] of column upper bounds.
CoinWarmStart * getEmptyWarmStart() const
Get empty warm start object.
soplex::DVector * redcost_
Pointer to reduced cost vector.
virtual void setColBounds(int elementIndex, double lower, double upper)
Set a single column lower and upper bound The default implementation just invokes setColLower and se...
soplex::SoPlex * soplex_
SoPlex solver object.
virtual bool isProvenPrimalInfeasible() const
Is primal infeasiblity proven?
virtual const char * getRowSense() const
Get pointer to array[getNumRows()] of row constraint senses.
void OsiSpxSolverInterfaceUnitTest(const std::string &mpsDir, const std::string &netlibDir)
A function that tests the methods in the OsiSpxSolverInterface class.
virtual const double * getRowActivity() const
Get pointer to array[getNumRows()] of row activity levels (constraint matrix times the solution vecto...
bool getDblParam(OsiDblParam key, double &value) const
Get a double parameter.
virtual std::vector< double * > getDualRays(int maxNumRays, bool fullRay=false) const
Get as many dual rays as the solver can provide.
Internal class for obtaining status from the applyCuts method.
LP solution: primal and dual solution, reduced costs, row activities.
friend void OsiSpxSolverInterfaceUnitTest(const std::string &mpsDir, const std::string &netlibDir)
A function that tests the methods in the OsiSpxSolverInterface class.
virtual const double * getColLower() const
Get pointer to array[getNumCols()] of column lower bounds.
bool setDblParam(OsiDblParam key, double value)
Set a double parameter.
virtual double getObjSense() const
Get objective function sense (1 for min (default), -1 for max)
virtual const double * getRowPrice() const
Get pointer to array[getNumRows()] of dual prices.
bool getIntParam(OsiIntParam key, int &value) const
Get an integer parameter.
OsiSpxSolverInterface & operator=(const OsiSpxSolverInterface &rhs)
Assignment operator.
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...