OsiFmpSolverInterface.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 _OsiFmpSolverInterface_hpp_
5 #define _OsiFmpSolverInterface_hpp_
6 
7 #if (defined(__MINGW32__) || defined(__CYGWIN32__)) && !defined(FMPMSDLL)
8 # define FMPMSDLL
9 #endif
10 
11 #include <string>
12 #include <libhd2.h>
13 
14 #include "OsiSolverInterface.hpp"
15 #include "CoinPackedMatrix.hpp"
16 #include "CoinWarmStartBasis.hpp"
17 
18 //#############################################################################
19 
25 class OsiFmpSolverInterface : virtual public OsiSolverInterface {
26  friend void OsiFmpSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
27 
28 public:
29  //---------------------------------------------------------------------------
32 
33  virtual void initialSolve();
34 
36  virtual void resolve();
37 
39  virtual void branchAndBound();
41 
42  //---------------------------------------------------------------------------
58  // Set an integer parameter
59  bool setIntParam(OsiIntParam key, int value);
60  // Set an double parameter
61  bool setDblParam(OsiDblParam key, double value);
62  // Set a string parameter
63  bool setStrParam(OsiStrParam key, const std::string & value);
64  // Get an integer parameter
65  bool getIntParam(OsiIntParam key, int& value) const;
66  // Get an double parameter
67  bool getDblParam(OsiDblParam key, double& value) const;
68  // Get a string parameter
69  bool getStrParam(OsiStrParam key, std::string& value) const;
71 
72  //---------------------------------------------------------------------------
74 
75 
76  virtual bool isAbandoned() const;
78  virtual bool isProvenOptimal() const;
80  virtual bool isProvenPrimalInfeasible() const;
82  virtual bool isProvenDualInfeasible() const;
84  virtual bool isPrimalObjectiveLimitReached() const;
86  virtual bool isDualObjectiveLimitReached() const;
88  virtual bool isIterationLimitReached() const;
90 
91  //---------------------------------------------------------------------------
94 
95  inline CoinWarmStart *getEmptyWarmStart () const
96  { return (dynamic_cast<CoinWarmStart *>(new CoinWarmStartBasis())) ; }
98  virtual CoinWarmStart* getWarmStart() const;
101  virtual bool setWarmStart(const CoinWarmStart* warmstart);
103 
104  //---------------------------------------------------------------------------
111 
112  virtual void markHotStart();
114  virtual void solveFromHotStart();
116  virtual void unmarkHotStart();
118 
119  //---------------------------------------------------------------------------
134 
135  virtual int getNumCols() const;
136 
138  virtual int getNumRows() const;
139 
141  virtual int getNumElements() const;
142 
144  virtual const double * getColLower() const;
145 
147  virtual const double * getColUpper() const;
148 
158  virtual const char * getRowSense() const;
159 
168  virtual const double * getRightHandSide() const;
169 
178  virtual const double * getRowRange() const;
179 
181  virtual const double * getRowLower() const;
182 
184  virtual const double * getRowUpper() const;
185 
187  virtual const double * getObjCoefficients() const;
188 
190  virtual double getObjSense() const;
191 
193  virtual bool isContinuous(int colNumber) const;
194 
195 #if 0
196 
197  virtual bool isBinary(int columnNumber) const;
198 
203  virtual bool isInteger(int columnNumber) const;
204 
206  virtual bool isIntegerNonBinary(int columnNumber) const;
207 
209  virtual bool isFreeBinary(int columnNumber) const;
210 #endif
211 
213  virtual const CoinPackedMatrix * getMatrixByRow() const;
214 
216  virtual const CoinPackedMatrix * getMatrixByCol() const;
217 
219  virtual double getInfinity() const;
221 
224 
225  virtual const double * getColSolution() const;
226 
228  virtual const double * getRowPrice() const;
229 
231  virtual const double * getReducedCost() const;
232 
235  virtual const double * getRowActivity() const;
236 
238  virtual double getObjValue() const;
239 
242  virtual int getIterationCount() const;
243 
255  virtual std::vector<double*> getDualRays(int maxNumRays) const;
267  virtual std::vector<double*> getPrimalRays(int maxNumRays) const;
268 
269 #if 0
270 
272  virtual OsiVectorInt getFractionalIndices(const double etol=1.e-05)
273  const;
274 #endif
275 
276 
277 
278  //---------------------------------------------------------------------------
279 
282  //-------------------------------------------------------------------------
286  virtual void setObjCoeff( int elementIndex, double elementValue );
287 
290  virtual void setColLower( int elementIndex, double elementValue );
291 
294  virtual void setColUpper( int elementIndex, double elementValue );
295 
296 #if 0
297  // The default implementation is OK.
301  virtual void setColBounds( int elementIndex,
302  double lower, double upper ) {
303  setColLower(elementIndex, lower);
304  setColUpper(elementIndex, upper);
305  }
306 #endif
307 
315  virtual void setColSetBounds(const int* indexFirst,
316  const int* indexLast,
317  const double* boundList);
318 
321  virtual void setRowLower( int elementIndex, double elementValue );
322 
325  virtual void setRowUpper( int elementIndex, double elementValue );
326 
330  virtual void setRowBounds( int elementIndex,
331  double lower, double upper );
332 
334  virtual void setRowType(int index, char sense, double rightHandSide,
335  double range);
336 
345  virtual void setRowSetBounds(const int* indexFirst,
346  const int* indexLast,
347  const double* boundList);
348 
359  virtual void setRowSetTypes(const int* indexFirst,
360  const int* indexLast,
361  const char* senseList,
362  const double* rhsList,
363  const double* rangeList);
365 
366  //-------------------------------------------------------------------------
370  virtual void setContinuous(int index);
372  virtual void setInteger(int index);
375  virtual void setContinuous(const int* indices, int len);
378  virtual void setInteger(const int* indices, int len);
380 
381  //-------------------------------------------------------------------------
383  virtual void setObjSense(double s );
384 
395  virtual void setColSolution(const double * colsol);
396 
407  virtual void setRowPrice(const double * rowprice);
408 
409  //-------------------------------------------------------------------------
415  virtual void addCol(const CoinPackedVectorBase& vec,
416  const double collb, const double colub,
417  const double obj);
419  virtual void addCols(const int numcols,
420  const CoinPackedVectorBase * const * cols,
421  const double* collb, const double* colub,
422  const double* obj);
423 #if 0
424 
425  virtual void addCols(const CoinPackedMatrix& matrix,
426  const double* collb, const double* colub,
427  const double* obj);
428 #endif
429 
430  virtual void deleteCols(const int num, const int * colIndices);
431 
433  virtual void addRow(const CoinPackedVectorBase& vec,
434  const double rowlb, const double rowub);
436  virtual void addRow(const CoinPackedVectorBase& vec,
437  const char rowsen, const double rowrhs,
438  const double rowrng);
440  virtual void addRows(const int numrows,
441  const CoinPackedVectorBase * const * rows,
442  const double* rowlb, const double* rowub);
444  virtual void addRows(const int numrows,
445  const CoinPackedVectorBase * const * rows,
446  const char* rowsen, const double* rowrhs,
447  const double* rowrng);
448 #if 0
449 
450  virtual void addRows(const CoinPackedMatrix& matrix,
451  const double* rowlb, const double* rowub);
453  virtual void addRows(const CoinPackedMatrix& matrix,
454  const char* rowsen, const double* rowrhs,
455  const double* rowrng);
456 #endif
457 
458  virtual void deleteRows(const int num, const int * rowIndices);
459 
460  //-----------------------------------------------------------------------
461 #if 0
462 
483  virtual ApplyCutsReturnCode applyCuts(const OsiCuts & cs,
484  double effectivenessLb = 0.0);
485 #endif
486 
487 
488 
489  //---------------------------------------------------------------------------
490 
504  virtual void loadProblem(const CoinPackedMatrix& matrix,
505  const double* collb, const double* colub,
506  const double* obj,
507  const double* rowlb, const double* rowub);
508 
516  virtual void assignProblem(CoinPackedMatrix*& matrix,
517  double*& collb, double*& colub, double*& obj,
518  double*& rowlb, double*& rowub);
519 
532  virtual void loadProblem(const CoinPackedMatrix& matrix,
533  const double* collb, const double* colub,
534  const double* obj,
535  const char* rowsen, const double* rowrhs,
536  const double* rowrng);
537 
545  virtual void assignProblem(CoinPackedMatrix*& matrix,
546  double*& collb, double*& colub, double*& obj,
547  char*& rowsen, double*& rowrhs,
548  double*& rowrng);
549 
552  virtual void loadProblem(const int numcols, const int numrows,
553  const CoinBigIndex * start, const int* index,
554  const double* value,
555  const double* collb, const double* colub,
556  const double* obj,
557  const double* rowlb, const double* rowub);
558 
561  virtual void loadProblem(const int numcols, const int numrows,
562  const CoinBigIndex * start, const int* index,
563  const double* value,
564  const double* collb, const double* colub,
565  const double* obj,
566  const char* rowsen, const double* rowrhs,
567  const double* rowrng);
568 
571  virtual int readMps(const char *filename,
572  const char *extension = "mps");
573 
578  virtual void writeMps(const char *filename,
579  const char *extension = "mps",
580  double objSense=0.0) const;
582 
583  //---------------------------------------------------------------------------
584 
585 
588 
590 
592  virtual OsiSolverInterface * clone(bool copyData = true) const;
593 
596 
599  operator=(const OsiFmpSolverInterface& rhs);
600 
602  virtual ~OsiFmpSolverInterface ();
603 
605  virtual void reset();
607 
608 protected:
609 
610  static int CBIterCountP2(int iter,double obj);
611 
612  void AllocSolutionSpace();
613 
617  virtual void applyRowCut( const OsiRowCut & rc );
618 
620  virtual void applyColCut( const OsiColCut & cc );
622 
623 private:
624 
627 
629  void gutsOfDestructor();
630 
632  void freeCachedResults();
633 
635  void extractSenseRhsRange() const;
637 
643 
644  int nr_;
646  int nc_;
648  int nz_;
650  int ns_;
652  int nq_;
654  int *send_;
655  int *sref_;
656  int *sfun_;
657  int *sbeg_;
659  int *rowin_;
661  int *colin_;
663  double *aij_;
665  int *mitype_;
667  double *upb_;
669  double *lob_;
671  double *cost_;
673  double *rhs_;
675  double *lhs_;
677  int stsl_;
679  int *basis_;
681  double *sol_;
683  double *dsl_;
685  double objconstant_;
687  double obj_;
689  std::string modelname_;
691  bool isMax_;
692 
693 
696 
697  mutable char *rowsense_;
698 
700  mutable double *rowrhs_;
701 
704  mutable double *rowrange_;
705 
707  mutable CoinPackedMatrix *matrixByRow_;
709  mutable CoinPackedMatrix *matrixByColumn_;
710 
713  CoinWarmStartBasis* ws_;
716 
718 
719 
720 };
721 
722 
723 //#############################################################################
731 void
732 OsiFmpSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
733 
734 #endif