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 Common 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 #include "symphony.h"
26 
27 #include "CoinPackedVector.hpp"
28 #include "CoinPackedMatrix.hpp"
29 
30 #include <iostream>
31 #include <string>
32 #include <cassert>
33 
34 //#############################################################################
35 
57 class OsiSymSolverInterface : virtual public OsiSolverInterface {
58  friend int OsiSymSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
59 
60 public:
62 
63  virtual void initialSolve();
65 
67  virtual void resolve();
68 
70  virtual void branchAndBound();
71 
73  virtual void multiCriteriaBranchAndBound();
74 
76  virtual double getLbForNewRhs(int cnt, int *index,
77  double * value);
79  virtual double getUbForNewRhs(int cnt, int *index,
80  double * value);
81 #if 0
82  virtual double getLbForNewObj(int cnt, int *index,
84  double * value);
86 #endif
87  virtual double getUbForNewObj(int cnt, int *index,
88  double * value);
89 
91 
92  //---------------------------------------------------------------------------
109  // Set an integer parameter
110  virtual bool setIntParam(OsiIntParam key, int value);
111 
112  // Set SYMPHONY int parameter
113  virtual bool setSymParam(OsiSymIntParam key, int value);
114 
115  // Set SYMPHONY int parameter directly by the C interface parameter name
116  virtual bool setSymParam(const std::string key, int value);
117 
118 
119  // Set an double parameter
120  virtual bool setDblParam(OsiDblParam key, double value);
121 
122  // Set SYMPHONY double parameter
123  virtual bool setSymParam(OsiSymDblParam key, double value);
124 
125  // Set SYMPHONY double parameter directly by the C interface parameter name
126  virtual bool setSymParam(const std::string key, double value);
127 
128 
129 
130  // Set a string parameter
131  virtual bool setStrParam(OsiStrParam key, const std::string & value);
132 
133  // Set SYMPHONY string parameter
134  virtual bool setSymParam(OsiSymStrParam key, const std::string & value);
135 
136  // Set SYMPHONY string parameter directly by the C interface parameter name
137  virtual bool setSymParam(const std::string key, const std::string value);
138 
139 
140 
141  // Get an integer parameter
142  virtual bool getIntParam(OsiIntParam key, int& value) const;
143 
144  // Get SYMPHONY int parameter
145  virtual bool getSymParam(OsiSymIntParam key, int& value) const;
146 
147  // Get SYMPHONY int parameter directly by the C interface parameter name
148  virtual bool getSymParam(const std::string key, int& value) const;
149 
150 
151  // Get an double parameter
152  virtual bool getDblParam(OsiDblParam key, double& value) const;
153 
154  // Get SYMPHONY double parameter
155  virtual bool getSymParam(OsiSymDblParam key, double& value) const;
156 
157  // Get SYMPHONY double parameter directly by the C interface parameter name
158  virtual bool getSymParam(const std::string key, double& value) const;
159 
160 
161 
162  // Get a string parameter
163  virtual bool getStrParam(OsiStrParam key, std::string& value) const;
164 
165  // Get SYMPHONY string parameter
166  virtual bool getSymParam(OsiSymStrParam key, std::string& value) const;
167 
168  // Get SYMPHONY string parameter directly by the C interface parameter name
169  virtual bool getSymParam(const std::string key, std::string& value) const;
170 
172 
173  //---------------------------------------------------------------------------
175 
176  virtual bool isAbandoned() const;
178 
180  virtual bool isProvenOptimal() const;
181 
183  virtual bool isProvenPrimalInfeasible() const;
184 
186  virtual bool isProvenDualInfeasible() const {
187  throw CoinError("Error: Function not implemented",
188  "isProvenDualInfeasible", "OsiSymSolverInterface");
189  }
191  virtual bool isPrimalObjectiveLimitReached() const;
192 
194  virtual bool isDualObjectiveLimitReached() const{
195  throw CoinError("Error: Function not implemented",
196  "isDualObjectiveLimitReached", "OsiSymSolverInterface");
197  }
199  virtual bool isIterationLimitReached() const;
200 
202  virtual bool isTimeLimitReached() const;
203 
205  virtual bool isTargetGapReached() const;
206 
208 
209  //---------------------------------------------------------------------------
219  virtual CoinWarmStart *getEmptyWarmStart () const{
220  throw CoinError("Error: Function not implemented",
221  "getEmptyWarmStart", "OsiSymSolverInterface");
222  }
223 
230  /*
231  virtual CoinWarmStart* getWarmStart(bool keepTreeInSymEnv = false) const;
232  */
233 
234  virtual CoinWarmStart* getWarmStart() const;
235 
240  virtual bool setWarmStart(const CoinWarmStart* warmstart);
242 
243  //---------------------------------------------------------------------------
254  sym_environment *getSymphonyEnvironment() const {return env_;}
256 
258  virtual int getNumCols() const;
259 
261  virtual int getNumRows() const;
262 
264  virtual int getNumElements() const;
265 
267  virtual const double * getColLower() const;
268 
270  virtual const double * getColUpper() const;
271 
281  virtual const char * getRowSense() const;
282 
295  virtual const double * getRightHandSide() const;
296 
305  virtual const double * getRowRange() const;
306 
308  virtual const double * getRowLower() const;
309 
311  virtual const double * getRowUpper() const;
312 
314  virtual const double * getObjCoefficients() const;
315 
319  virtual const double * getObj2Coefficients() const;
320 
322  virtual double getObjSense() const;
323 
325  virtual bool isContinuous(int colIndex) const;
326 
328  virtual bool isBinary(int colIndex) const;
329 
334  virtual bool isInteger(int colIndex) const;
335 
337  virtual bool isIntegerNonBinary(int colIndex) const;
338 
340  virtual bool isFreeBinary(int colIndex) const;
341 
343  virtual const CoinPackedMatrix * getMatrixByRow() const;
344 
346  virtual const CoinPackedMatrix * getMatrixByCol() const;
347 
349  virtual double getInfinity() const;
350 
352 
355  virtual const double * getColSolution() const;
357 
359  virtual const double * getRowPrice() const{
360  // throw CoinError("Error: Function not implemented",
361  // "getRowPrice", "OsiSymSolverInterface");
362  return (0);
363  }
364 
366  virtual const double * getReducedCost() const{
367  // throw CoinError("Error: Function not implemented",
368  // "getReducedCost", "OsiSymSolverInterface");
369  return (0);
370  }
371 
374  virtual const double * getRowActivity() const;
375 
377  virtual double getObjValue() const;
378 
380  virtual double getPrimalBound() const;
381 
384  virtual int getIterationCount() const;
385 
399  virtual std::vector<double*> getDualRays(int maxNumRays) const{
400  throw CoinError("Error: Function not implemented",
401  "getDualRays", "OsiSymSolverInterface");
402  }
414  virtual std::vector<double*> getPrimalRays(int maxNumRays) const{
415  throw CoinError("Error: Function not implemented",
416  "getPrimalRays", "OsiSymSolverInterface");
417  }
418 
420 
421  //-------------------------------------------------------------------------
434  virtual void setObjCoeff( int elementIndex, double elementValue );
435 
437  virtual void setObj2Coeff( int elementIndex, double elementValue );
438 
442  virtual void setColLower( int elementIndex, double elementValue );
443 
447  virtual void setColUpper( int elementIndex, double elementValue );
448 
451  virtual void setRowLower( int elementIndex, double elementValue );
452 
455  virtual void setRowUpper( int elementIndex, double elementValue );
456 
458  virtual void setRowType(int index, char sense, double rightHandSide,
459  double range);
460 
463  virtual void setObjSense(double s);
464 
474  virtual void setColSolution(const double *colsol);
475 
478  virtual void setPrimalBound(const double bound);
479 
490  virtual void setRowPrice(const double * rowprice){
491  throw CoinError("Error: Function not implemented",
492  "setRowPrice", "OsiSymSolverInterface");
493  }
494 
496 
497  //-------------------------------------------------------------------------
500 
503  virtual void setContinuous(int index);
504 
507  virtual void setInteger(int index);
508 
509 
511  virtual void setColName(char **colname);
512 
514  //-------------------------------------------------------------------------
515 
516  //-------------------------------------------------------------------------
523 
526  virtual void addCol(const CoinPackedVectorBase& vec,
527  const double collb, const double colub,
528  const double obj);
529 
531  virtual void deleteCols(const int num, const int * colIndices);
532 
535  virtual void addRow(const CoinPackedVectorBase& vec,
536  const double rowlb, const double rowub);
538  virtual void addRow(const CoinPackedVectorBase& vec,
539  const char rowsen, const double rowrhs,
540  const double rowrng);
541 
543  virtual void deleteRows(const int num, const int * rowIndices);
544 
546 
547  //---------------------------------------------------------------------------
548 
551 
552  virtual void loadProblem();
553 
565  virtual void loadProblem(const CoinPackedMatrix& matrix,
566  const double* collb, const double* colub,
567  const double* obj,
568  const double* rowlb, const double* rowub);
569 
579  virtual void assignProblem(CoinPackedMatrix*& matrix,
580  double*& collb, double*& colub, double*& obj,
581  double*& rowlb, double*& rowub);
582 
595  virtual void loadProblem(const CoinPackedMatrix& matrix,
596  const double* collb, const double* colub,
597  const double* obj,
598  const char* rowsen, const double* rowrhs,
599  const double* rowrng);
600 
610  virtual void assignProblem(CoinPackedMatrix*& matrix,
611  double*& collb, double*& colub, double*& obj,
612  char*& rowsen, double*& rowrhs,
613  double*& rowrng);
614 
617  virtual void loadProblem(const int numcols, const int numrows,
618  const CoinBigIndex * start, const int* index,
619  const double* value,
620  const double* collb, const double* colub,
621  const double* obj,
622  const double* rowlb, const double* rowub);
623 
626  virtual void loadProblem(const int numcols, const int numrows,
627  const CoinBigIndex * start, const int* index,
628  const double* value,
629  const double* collb, const double* colub,
630  const double* obj,
631  const char* rowsen, const double* rowrhs,
632  const double* rowrng);
633 
640  virtual void writeMps(const char *filename,
641  const char *extension = "mps",
642  double objSense=0.0) const;
643 
644  void parseCommandLine(int argc, char **argv);
645 
647  virtual int readMps(const char * infile, const char *extension = "mps");
648 
649  virtual int readGMPL(const char * modelFile, const char * dataFile=NULL);
650 
651  void findInitialBounds();
652 
654 
656 
657  //---------------------------------------------------------------------------
658 
682  };
683 
685 
688 
694  virtual OsiSolverInterface * clone(bool copyData = true) const;
695 
698 
701 
703  virtual ~OsiSymSolverInterface ();
704 
711  virtual void reset();
713 
714  //---------------------------------------------------------------------------
715 
716 protected:
718 
719 
720  virtual void applyRowCut( const OsiRowCut & rc );
721 
723  virtual void applyColCut( const OsiColCut & cc );
724 
732  void setInitialData();
734 
735 private:
736 
738  void gutsOfConstructor();
739 
741  void gutsOfDestructor();
742 
744  void freeCachedColRim();
745 
747  void freeCachedRowRim();
748 
750  void freeCachedResults();
751 
753  void freeCachedMatrix();
754 
756  void freeCachedData( int keepCached = KEEPCACHED_NONE );
757 
759  void freeAllMemory();
760 
762  void printBounds();
763 
766  sym_environment *env_;
769 
771  mutable double *obj_;
772 
774  mutable double *obj2_;
775 
777  mutable double *collower_;
778 
780  mutable double *colupper_;
781 
783  mutable char *rowsense_;
784 
786  mutable double *rhs_;
787 
791  mutable double *rowrange_;
792 
794  mutable double *rowlower_;
795 
797  mutable double *rowupper_;
798 
800  mutable double *colsol_;
801 
803  mutable double *rowact_;
804 
806  mutable CoinPackedMatrix *matrixByRow_;
807 
809  mutable CoinPackedMatrix *matrixByCol_;
810 
811 };
812 
813 //#############################################################################
819 int OsiSymSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir);
820 
821 #endif