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 CPL
10 //-----------------------------------------------------------------------------
11 // Copyright (C) 2002, Tobias Pfender, International Business Machines
12 // Corporation and others. All Rights Reserved.
13 // Last edit: $Id: OsiSpxSolverInterface.hpp 1528 2010-06-13 18:13:22Z stefan $
14 
15 #ifndef OsiSpxSolverInterface_H
16 #define OsiSpxSolverInterface_H
17 
18 #include <string>
19 #include "soplex.h"
20 #include "OsiSolverInterface.hpp"
21 #include "CoinWarmStartBasis.hpp"
22 
28 class OsiSpxSolverInterface : virtual public OsiSolverInterface, public soplex::SoPlex {
29  friend void OsiSpxSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
30 
31 public:
32 
33  //---------------------------------------------------------------------------
36  virtual void initialSolve();
38 
40  virtual void resolve();
41 
43  virtual void branchAndBound();
45 
46  //---------------------------------------------------------------------------
62  // Set an integer parameter
63  bool setIntParam(OsiIntParam key, int value);
64  // Set an double parameter
65  bool setDblParam(OsiDblParam key, double value);
66  // Get an integer parameter
67  bool getIntParam(OsiIntParam key, int& value) const;
68  // Get an double parameter
69  bool getDblParam(OsiDblParam key, double& value) const;
70  // Get a string parameter
71  bool getStrParam(OsiStrParam key, std::string& value) const;
73 
74  //---------------------------------------------------------------------------
76 
77  virtual bool isAbandoned() const;
80  virtual bool isProvenOptimal() const;
82  virtual bool isProvenPrimalInfeasible() const;
84  virtual bool isProvenDualInfeasible() const;
86  virtual bool isPrimalObjectiveLimitReached() const;
88  virtual bool isDualObjectiveLimitReached() const;
90  virtual bool isIterationLimitReached() const;
92 
93  //---------------------------------------------------------------------------
96  inline CoinWarmStart *getEmptyWarmStart () const
98  { return (dynamic_cast<CoinWarmStart *>(new CoinWarmStartBasis())) ; }
100  virtual CoinWarmStart* getWarmStart() const;
103  virtual bool setWarmStart(const CoinWarmStart* warmstart);
105 
106  //---------------------------------------------------------------------------
113  virtual void markHotStart();
116  virtual void solveFromHotStart();
118  virtual void unmarkHotStart();
120 
121  //---------------------------------------------------------------------------
136  virtual int getNumCols() const;
138 
140  virtual int getNumRows() const;
141 
143  virtual int getNumElements() const;
144 
146  virtual const double * getColLower() const;
147 
149  virtual const double * getColUpper() const;
150 
160  virtual const char * getRowSense() const;
161 
170  virtual const double * getRightHandSide() const;
171 
180  virtual const double * getRowRange() const;
181 
183  virtual const double * getRowLower() const;
184 
186  virtual const double * getRowUpper() const;
187 
189  virtual const double * getObjCoefficients() const;
190 
192  virtual double getObjSense() const;
193 
195  virtual bool isContinuous(int colNumber) const;
196 
197 #if 0
198  virtual bool isBinary(int columnNumber) const;
200 
205  virtual bool isInteger(int columnNumber) const;
206 
208  virtual bool isIntegerNonBinary(int columnNumber) const;
209 
211  virtual bool isFreeBinary(int columnNumber) const;
212 #endif
213 
215  virtual const CoinPackedMatrix * getMatrixByRow() const;
216 
218  virtual const CoinPackedMatrix * getMatrixByCol() const;
219 
221  virtual double getInfinity() const;
223 
226  virtual const double * getColSolution() const;
228 
230  virtual const double * getRowPrice() const;
231 
233  virtual const double * getReducedCost() const;
234 
237  virtual const double * getRowActivity() const;
238 
240  virtual double getObjValue() const;
241 
244  virtual int getIterationCount() const;
245 
257  virtual std::vector<double*> getDualRays(int maxNumRays) const;
269  virtual std::vector<double*> getPrimalRays(int maxNumRays) const;
270 
271 #if 0
272 
274  virtual OsiVectorInt getFractionalIndices(const double etol=1.e-05)
275  const;
276 #endif
277 
278 
279 
280  //---------------------------------------------------------------------------
281 
284  //-------------------------------------------------------------------------
288  virtual void setObjCoeff( int elementIndex, double elementValue );
289 
292  virtual void setColLower( int elementIndex, double elementValue );
293 
296  virtual void setColUpper( int elementIndex, double elementValue );
297 
301  virtual void setColBounds( int elementIndex,
302  double lower, double upper );
303 
304 #if 0 // we are using the default implementation of OsiSolverInterface
305 
313  virtual void setColSetBounds(const int* indexFirst,
314  const int* indexLast,
315  const double* boundList);
316 #endif
317 
320  virtual void setRowLower( int elementIndex, double elementValue );
321 
324  virtual void setRowUpper( int elementIndex, double elementValue );
325 
329  virtual void setRowBounds( int elementIndex,
330  double lower, double upper );
331 
333  virtual void setRowType(int index, char sense, double rightHandSide,
334  double range);
335 
336 #if 0 // we are using the default implementation of OsiSolverInterface
337 
344  virtual void setRowSetBounds(const int* indexFirst,
345  const int* indexLast,
346  const double* boundList);
347 
357  virtual void setRowSetTypes(const int* indexFirst,
358  const int* indexLast,
359  const char* senseList,
360  const double* rhsList,
361  const double* rangeList);
362 #endif
363 
364 
365  //-------------------------------------------------------------------------
369  virtual void setContinuous(int index);
371  virtual void setInteger(int index);
372 #if 0 // we are using the default implementation of OsiSolverInterface
373 
375  virtual void setContinuous(const int* indices, int len);
378  virtual void setInteger(const int* indices, int len);
379 #endif
380 
381 
382  //-------------------------------------------------------------------------
384  virtual void setObjSense(double s);
385 
396  virtual void setColSolution(const double * colsol);
397 
408  virtual void setRowPrice(const double * rowprice);
409 
410  //-------------------------------------------------------------------------
416  virtual void addCol(const CoinPackedVectorBase& vec,
417  const double collb, const double colub,
418  const double obj);
419 
420 #if 0 // we are using the default implementation of OsiSolverInterface
421 
422  virtual void addCols(const int numcols,
423  const CoinPackedVectorBase * const * cols,
424  const double* collb, const double* colub,
425  const double* obj);
426 #endif
427 
429  virtual void deleteCols(const int num, const int * colIndices);
430 
432  virtual void addRow(const CoinPackedVectorBase& vec,
433  const double rowlb, const double rowub);
435  virtual void addRow(const CoinPackedVectorBase& vec,
436  const char rowsen, const double rowrhs,
437  const double rowrng);
438 
439 #if 0 // we are using the default implementation of OsiSolverInterface
440 
441  virtual void addRows(const int numrows,
442  const CoinPackedVectorBase * const * rows,
443  const double* rowlb, const double* rowub);
445  virtual void addRows(const int numrows,
446  const CoinPackedVectorBase * const * rows,
447  const char* rowsen, const double* rowrhs,
448  const double* rowrng);
449 #endif
450 
452  virtual void deleteRows(const int num, const int * rowIndices);
453 
454 #if 0 // we are using the default implementation of OsiSolverInterface
455  //-----------------------------------------------------------------------
477  virtual ApplyCutsReturnCode applyCuts(const OsiCuts & cs,
478  double effectivenessLb = 0.0);
479 #endif
480 
481 
482 
483  //---------------------------------------------------------------------------
484 
498  virtual void loadProblem(const CoinPackedMatrix& matrix,
499  const double* collb, const double* colub,
500  const double* obj,
501  const double* rowlb, const double* rowub);
502 
510  virtual void assignProblem(CoinPackedMatrix*& matrix,
511  double*& collb, double*& colub, double*& obj,
512  double*& rowlb, double*& rowub);
513 
526  virtual void loadProblem(const CoinPackedMatrix& matrix,
527  const double* collb, const double* colub,
528  const double* obj,
529  const char* rowsen, const double* rowrhs,
530  const double* rowrng);
531 
539  virtual void assignProblem(CoinPackedMatrix*& matrix,
540  double*& collb, double*& colub, double*& obj,
541  char*& rowsen, double*& rowrhs,
542  double*& rowrng);
543 
546  virtual void loadProblem(const int numcols, const int numrows,
547  const int* start, const int* index,
548  const double* value,
549  const double* collb, const double* colub,
550  const double* obj,
551  const double* rowlb, const double* rowub);
552 
555  virtual void loadProblem(const int numcols, const int numrows,
556  const int* start, const int* index,
557  const double* value,
558  const double* collb, const double* colub,
559  const double* obj,
560  const char* rowsen, const double* rowrhs,
561  const double* rowrng);
562 
564  virtual int readMps(const char *filename,
565  const char *extension = "mps");
566 
571  virtual void writeMps(const char *filename,
572  const char *extension = "mps",
573  double objSense=0.0) const;
575 
576  //---------------------------------------------------------------------------
577 
582 
584  virtual OsiSolverInterface * clone(bool copyData = true) const;
585 
588 
591 
593  virtual ~OsiSpxSolverInterface();
595 
596 protected:
597 
600  virtual void applyRowCut( const OsiRowCut & rc );
602 
606  virtual void applyColCut( const OsiColCut & cc );
608 
611  soplex::SoPlex soplex_;
614 
615 
616 private:
619 
621  void freeCachedColRim();
622 
624  void freeCachedRowRim();
625 
627  void freeCachedResults();
628 
630  void freeCachedMatrix();
631 
633  {
656  };
657 
659  void freeCachedData( int keepCached = KEEPCACHED_NONE );
660 
662  void freeAllMemory();
663 
665  void printBounds();
667 
668 
671  soplex::DIdxSet spxintvars_;
673 
675  soplex::SPxSolver::VarStatus *hotStartCStat_;
677  soplex::SPxSolver::VarStatus *hotStartRStat_;
680 
683  mutable soplex::DVector *obj_;
685 
687  mutable char *rowsense_;
688 
690  mutable double *rhs_;
691 
693  mutable double *rowrange_;
694 
696  mutable soplex::DVector *colsol_;
697 
699  mutable soplex::DVector *rowsol_;
700 
702  mutable soplex::DVector *redcost_;
703 
705  mutable soplex::DVector *rowact_;
706 
708  mutable CoinPackedMatrix *matrixByRow_;
709 
711  mutable CoinPackedMatrix *matrixByCol_;
713 
714 };
715 
716 //#############################################################################
722 void OsiSpxSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
723 
724 #endif