OsiXprSolverInterface.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 OsiXprSolverInterface_H
5 #define OsiXprSolverInterface_H
6 
7 #include <string>
8 #include <cstdio>
9 
10 #include "OsiSolverInterface.hpp"
11 
12 typedef struct xo_prob_struct* XPRSprob;
13 
14 //#############################################################################
15 
20 class OsiXprSolverInterface : virtual public OsiSolverInterface {
21  friend void OsiXprSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
22 public:
25 
26  virtual void initialSolve();
27 
29  virtual void resolve();
30 
32  virtual void branchAndBound();
34 
50  // Set an integer parameter
51  bool setIntParam(OsiIntParam key, int value);
52  // Set an double parameter
53  bool setDblParam(OsiDblParam key, double value);
54  // Set a string parameter
55  bool setStrParam(OsiStrParam key, const std::string & value);
56  // Get an integer parameter
57  bool getIntParam(OsiIntParam key, int& value) const;
58  // Get an double parameter
59  bool getDblParam(OsiDblParam key, double& value) const;
60  // Get a string parameter
61  bool getStrParam(OsiStrParam key, std::string& value) const;
63 
64  //---------------------------------------------------------------------------
66 
67 
68  virtual bool isAbandoned() const;
70  virtual bool isProvenOptimal() const;
72  virtual bool isProvenPrimalInfeasible() const;
74  virtual bool isProvenDualInfeasible() const;
76  virtual bool isPrimalObjectiveLimitReached() const;
78  virtual bool isDualObjectiveLimitReached() const;
80  virtual bool isIterationLimitReached() const;
82 
83  //---------------------------------------------------------------------------
86 
87  CoinWarmStart *getEmptyWarmStart () const;
89  virtual CoinWarmStart* getWarmStart() const;
92  virtual bool setWarmStart(const CoinWarmStart* warmstart);
94 
95  //---------------------------------------------------------------------------
102 
103  virtual void markHotStart();
105  virtual void solveFromHotStart();
107  virtual void unmarkHotStart();
109 
110  //---------------------------------------------------------------------------
125 
126  virtual int getNumCols() const;
127 
129  virtual int getNumRows() const;
130 
132  virtual int getNumElements() const;
133 
135  virtual const double * getColLower() const;
136 
138  virtual const double * getColUpper() const;
139 
149  virtual const char * getRowSense() const;
150 
159  virtual const double * getRightHandSide() const;
160 
169  virtual const double * getRowRange() const;
170 
172  virtual const double * getRowLower() const;
173 
175  virtual const double * getRowUpper() const;
176 
178  virtual const double * getObjCoefficients() const;
179 
181  virtual double getObjSense() const;
182 
184  virtual bool isContinuous(int colIndex) const;
185 
186 #if 0
187 
188  virtual bool isBinary(int colIndex) const;
189 
194  virtual bool isInteger(int colIndex) const;
195 
197  virtual bool isIntegerNonBinary(int colIndex) const;
198 
200  virtual bool isFreeBinary(int colIndex) const;
201 #endif
202 
203  virtual const CoinPackedMatrix * getMatrixByRow() const;
204 
206  virtual const CoinPackedMatrix * getMatrixByCol() const;
207 
209  virtual double getInfinity() const;
211 
214 
215  virtual const double * getColSolution() const;
216 
218  virtual const double * getRowPrice() const;
219 
221  virtual const double * getReducedCost() const;
222 
225  virtual const double * getRowActivity() const;
226 
228  virtual double getObjValue() const;
229 
232  virtual int getIterationCount() const;
233 
245  virtual std::vector<double*> getDualRays(int maxNumRays) const;
257  virtual std::vector<double*> getPrimalRays(int maxNumRays) const;
258 
259 #if 0
260 
262  virtual OsiVectorInt getFractionalIndices(const double etol=1.e-05)
263  const;
264 #endif
265 
266 
267 
268  //---------------------------------------------------------------------------
269 
272  //-------------------------------------------------------------------------
276  virtual void setObjCoeff( int elementIndex, double elementValue );
277 
280  virtual void setColLower( int elementIndex, double elementValue );
281 
284  virtual void setColUpper( int elementIndex, double elementValue );
285 
289  virtual void setColBounds( int elementIndex,
290  double lower, double upper );
291 
300  virtual void setColSetBounds(const int* indexFirst,
301  const int* indexLast,
302  const double* boundList);
303 
306  virtual void setRowLower( int elementIndex, double elementValue );
307 
310  virtual void setRowUpper( int elementIndex, double elementValue );
311 
315  virtual void setRowBounds( int elementIndex,
316  double lower, double upper );
317 
319  virtual void setRowType(int index, char sense, double rightHandSide,
320  double range);
321 
330  virtual void setRowSetBounds(const int* indexFirst,
331  const int* indexLast,
332  const double* boundList);
333 
344  virtual void setRowSetTypes(const int* indexFirst,
345  const int* indexLast,
346  const char* senseList,
347  const double* rhsList,
348  const double* rangeList);
350 
351  //-------------------------------------------------------------------------
355  virtual void setContinuous(int index);
357  virtual void setInteger(int index);
360  virtual void setContinuous(const int* indices, int len);
363  virtual void setInteger(const int* indices, int len);
365 
366  //-------------------------------------------------------------------------
368  virtual void setObjSense(double s);
369 
380  virtual void setColSolution(const double * colsol);
381 
392  virtual void setRowPrice(const double * rowprice);
393 
394  //-------------------------------------------------------------------------
400  virtual void addCol(const CoinPackedVectorBase& vec,
401  const double collb, const double colub,
402  const double obj);
404  virtual void addCols(const int numcols,
405  const CoinPackedVectorBase * const * cols,
406  const double* collb, const double* colub,
407  const double* obj);
409  virtual void deleteCols(const int num, const int * colIndices);
410 
412  virtual void addRow(const CoinPackedVectorBase& vec,
413  const double rowlb, const double rowub);
415  virtual void addRow(const CoinPackedVectorBase& vec,
416  const char rowsen, const double rowrhs,
417  const double rowrng);
419  virtual void addRows(const int numrows,
420  const CoinPackedVectorBase * const * rows,
421  const double* rowlb, const double* rowub);
423  virtual void addRows(const int numrows,
424  const CoinPackedVectorBase * const * rows,
425  const char* rowsen, const double* rowrhs,
426  const double* rowrng);
428  virtual void deleteRows(const int num, const int * rowIndices);
429 #if 0
430  //-----------------------------------------------------------------------
452  virtual ApplyCutsReturnCode applyCuts(const OsiCuts & cs,
453  double effectivenessLb = 0.0);
455 
456 #endif
457  //---------------------------------------------------------------------------
458 
472  virtual void loadProblem(const CoinPackedMatrix& matrix,
473  const double* collb, const double* colub,
474  const double* obj,
475  const double* rowlb, const double* rowub);
476 
484  virtual void assignProblem(CoinPackedMatrix*& matrix,
485  double*& collb, double*& colub, double*& obj,
486  double*& rowlb, double*& rowub);
487 
500  virtual void loadProblem(const CoinPackedMatrix& matrix,
501  const double* collb, const double* colub,
502  const double* obj,
503  const char* rowsen, const double* rowrhs,
504  const double* rowrng);
505 
513  virtual void assignProblem(CoinPackedMatrix*& matrix,
514  double*& collb, double*& colub, double*& obj,
515  char*& rowsen, double*& rowrhs,
516  double*& rowrng);
517 
520  virtual void loadProblem(const int numcols, const int numrows,
521  const int* start, const int* index,
522  const double* value,
523  const double* collb, const double* colub,
524  const double* obj,
525  const double* rowlb, const double* rowub);
526 
529  virtual void loadProblem(const int numcols, const int numrows,
530  const int* start, const int* index,
531  const double* value,
532  const double* collb, const double* colub,
533  const double* obj,
534  const char* rowsen, const double* rowrhs,
535  const double* rowrng);
536 
537 
539  virtual int readMps(const char *filename,
540  const char *extension = "mps");
541 
542 
547  virtual void writeMps(const char *filename,
548  const char *extension = "mps",
549  double objSense=0.0) const;
551 
559  void passInMessageHandler(CoinMessageHandler * handler);
561 
562  //---------------------------------------------------------------------------
563 
577  static void incrementInstanceCounter();
578 
587  static void decrementInstanceCounter();
588 
591  static unsigned int getNumInstances();
592 
594  XPRSprob getLpPtr() { return prob_; }
596 
598  static int version();
599 
602  static int iXprCallCount_;
603 
604 
606  static FILE * getLogFilePtr();
609  static void setLogFileName( const char * filename );
611 
612 
615 
616  OsiXprSolverInterface (int newrows = 50, int newnz = 100);
617 
619  virtual OsiSolverInterface * clone(bool copyData = true) const;
620 
623 
626 
628  virtual ~OsiXprSolverInterface ();
630 
631 protected:
632 
635 
636  virtual void applyRowCut( const OsiRowCut & rc );
637 
641  virtual void applyColCut( const OsiColCut & cc );
643 
644 private:
645 
648 
649  static const char * logFileName_;
650 
652  static FILE * logFilePtr_;
653 
655  static unsigned int numInstances_;
656 
658  static unsigned int osiSerial_;
659 
661 
664 
665  void gutsOfCopy( const OsiXprSolverInterface & source );
666 
668  void gutsOfConstructor();
669 
671  void gutsOfDestructor();
672 
674  void freeSolution();
675 
678  void freeCachedResults();
679 
681  int getNumIntVars() const;
682 
685 
686  void getVarTypes() const;
687 
691  void activateMe() const;
692 
697  bool isDataLoaded() const;
699 
700 
703 
706 
707  mutable XPRSprob prob_;
708 
710  mutable std::string xprProbname_;
712 
720  mutable CoinPackedMatrix *matrixByRow_;
721  mutable CoinPackedMatrix *matrixByCol_;
722 
724  mutable double *colupper_;
725 
727  mutable double *collower_;
728 
730  mutable double *rowupper_;
731 
733  mutable double *rowlower_;
734 
736  mutable char *rowsense_;
737 
739  mutable double *rhs_;
740 
744  mutable double *rowrange_;
745 
747  mutable double *objcoeffs_;
748 
750  mutable double objsense_;
751 
753  mutable double *colsol_;
754 
756  mutable double *rowsol_;
757 
759  mutable double *rowact_;
760 
762  mutable double *rowprice_;
763 
765  mutable double *colprice_;
766 
768  mutable int *ivarind_;
769 
778  mutable char *ivartype_;
779 
783  mutable char *vartype_;
785 
786 };
787 
788 //#############################################################################
794 void
795 OsiXprSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
796 
797 #endif