/home/coin/SVN-release/Osi-0.96.1/Osi/src/OsiBranchingObject.hpp

Go to the documentation of this file.
00001 // Copyright (C) 2006, International Business Machines
00002 // Corporation and others.  All Rights Reserved.
00003 #ifndef OsiBranchingObject_H
00004 #define OsiBranchingObject_H
00005 
00006 #include <cassert>
00007 #include <string>
00008 #include <vector>
00009 
00010 class OsiSolverInterface;
00011 class OsiSolverBranch;
00012 
00013 class OsiBranchingObject;
00014 class OsiBranchingInformation;
00015 
00016 //#############################################################################
00017 //This contains the abstract base class for an object and for branching.
00018 //It also contains a simple integer class
00019 //#############################################################################
00020 
00051 class OsiObject {
00052 
00053 public:
00054   
00056   OsiObject ();
00057   
00059   OsiObject ( const OsiObject &);
00060   
00062   OsiObject & operator=( const OsiObject& rhs);
00063   
00065   virtual OsiObject * clone() const=0;
00066   
00068   virtual ~OsiObject ();
00069   
00091   virtual double infeasibility(const OsiSolverInterface * solver,int &whichWay) const ;
00092   // Faster version when more information available
00093   virtual double infeasibility(const OsiBranchingInformation * info, int &whichWay) const =0;
00094   // This does NOT set mutable stuff
00095   virtual double checkInfeasibility(const OsiBranchingInformation * info) const;
00096   
00101   virtual double feasibleRegion(OsiSolverInterface * solver) const ;
00107   virtual double feasibleRegion(OsiSolverInterface * solver, const OsiBranchingInformation * info) const =0;
00108   
00114   virtual OsiBranchingObject * createBranch(OsiSolverInterface * solver, const OsiBranchingInformation * info, int way) const = 0;
00115   
00118   virtual bool canDoHeuristics() const 
00119   {return true;};
00122   virtual bool canMoveToNearest() const 
00123   {return false;};
00127   virtual int columnNumber() const;
00129   inline int priority() const
00130   { return priority_;};
00132   inline void setPriority(int priority)
00133   { priority_ = priority;};
00136   virtual bool boundBranch() const 
00137   {return true;};
00139   virtual bool canHandleShadowPrices() const
00140   { return false;};
00142   inline int numberWays() const
00143   { return numberWays_;};
00145   inline void setNumberWays(int numberWays)
00146   { numberWays_ = numberWays;};
00151   inline void setWhichWay(int way)
00152   { whichWay_ = way;};
00157   inline int whichWay() const
00158   { return whichWay_;};
00160   virtual int preferredWay() const
00161   { return -1;};
00163   inline double infeasibility() const
00164   { return infeasibility_;};
00166   virtual double upEstimate() const;
00168   virtual double downEstimate() const;
00173   virtual void resetBounds(const OsiSolverInterface * solver) {};
00176   virtual void resetSequenceEtc(int numberColumns, const int * originalColumns) {};
00177   
00178 
00179 protected:
00181 
00183   mutable double infeasibility_;
00185   mutable short whichWay_;
00187   short  numberWays_;
00189   int priority_;
00190 
00191 };
00194 
00195 
00196 class OsiObject2 : public OsiObject {
00197 
00198 public:
00199 
00201   OsiObject2 ();
00202 
00204   OsiObject2 ( const OsiObject2 &);
00205    
00207   OsiObject2 & operator=( const OsiObject2& rhs);
00208 
00210   virtual ~OsiObject2 ();
00211   
00213   inline void setPreferredWay(int value)
00214   {preferredWay_=value;};
00215   
00217   virtual int preferredWay() const
00218   { return preferredWay_;};
00219 protected:
00221   int preferredWay_;
00223   mutable float otherInfeasibility_;
00224   
00225 };
00226 
00244 class OsiBranchingObject {
00245 
00246 public:
00247 
00249   OsiBranchingObject ();
00250 
00252   OsiBranchingObject (OsiSolverInterface * solver, double value);
00253   
00255   OsiBranchingObject ( const OsiBranchingObject &);
00256    
00258   OsiBranchingObject & operator=( const OsiBranchingObject& rhs);
00259 
00261   virtual OsiBranchingObject * clone() const=0;
00262 
00264   virtual ~OsiBranchingObject ();
00265 
00267   inline int numberBranches() const
00268   {return numberBranches_;};
00269 
00271   inline int numberBranchesLeft() const
00272   {return numberBranches_-branchIndex_;};
00273 
00277   inline void setNumberBranchesLeft(int value)
00278   {assert (value==1&&!branchIndex_); numberBranches_=1;};
00279 
00281   inline void decrementNumberBranchesLeft()
00282   {branchIndex_++;};
00283 
00289   virtual double branch(OsiSolverInterface * solver)=0;
00295   virtual double branch() {return branch(NULL);};
00298   virtual bool boundBranch() const 
00299   {return true;};
00303   inline int branchIndex() const
00304   {return branchIndex_;};
00305 
00308   inline void setBranchingIndex(int branchIndex)
00309   {branchIndex_=branchIndex;};
00310 
00312   inline double value() const
00313   {return value_;};
00314   
00316   inline const OsiObject * originalObject() const
00317   {return  originalObject_;};
00319   inline void setOriginalObject(const OsiObject * object)
00320   {originalObject_=object;};
00322   int columnNumber() const;
00325   virtual void print(const OsiSolverInterface * solver=NULL) const {};
00326 
00327 protected:
00328 
00330   double value_;
00331 
00333   const OsiObject * originalObject_;
00334 
00337   int numberBranches_;
00338 
00342   short branchIndex_;
00343 
00344 };
00345 /* This contains information
00346    This could also contain pseudo shadow prices
00347    or information for dealing with computing and trusting pseudo-costs
00348 */
00349 class OsiBranchingInformation {
00350 
00351 public:
00352   
00354   OsiBranchingInformation ();
00355   
00360   OsiBranchingInformation (const OsiSolverInterface * solver, bool normalSolver,bool copySolution=false);
00361   
00363   OsiBranchingInformation ( const OsiBranchingInformation &);
00364   
00366   OsiBranchingInformation & operator=( const OsiBranchingInformation& rhs);
00367   
00369   virtual OsiBranchingInformation * clone() const;
00370   
00372   virtual ~OsiBranchingInformation ();
00373   
00374   // Note public
00375 public:
00377 
00379   double objectiveValue_;
00381   double cutoff_;
00383   double direction_;
00385   double integerTolerance_;
00387   double primalTolerance_;
00389   double timeRemaining_;
00391   double defaultDual_;
00393   mutable const OsiSolverInterface * solver_;
00395   int numberColumns_;
00397   mutable const double * lower_;
00399   mutable const double * solution_;
00401   mutable const double * upper_;
00403   const double * hotstartSolution_;
00405   const double * pi_;
00407   const double * rowActivity_;
00409   const double * objective_;
00411   const double * rowLower_;
00413   const double * rowUpper_;
00415   const double * elementByColumn_;
00417   const CoinBigIndex * columnStart_;
00419   const int * columnLength_;
00421   const int * row_;
00427   double * usefulRegion_;
00429   int * indexRegion_;
00431   int numberSolutions_;
00433   int numberBranchingSolutions_;
00435   int depth_;
00437   bool owningSolution_;
00438 };
00439 
00441 
00442 class OsiTwoWayBranchingObject : public OsiBranchingObject {
00443 
00444 public:
00445 
00447   OsiTwoWayBranchingObject ();
00448 
00455   OsiTwoWayBranchingObject (OsiSolverInterface *solver,const OsiObject * originalObject,
00456                              int way , double value) ;
00457     
00459   OsiTwoWayBranchingObject ( const OsiTwoWayBranchingObject &);
00460    
00462   OsiTwoWayBranchingObject & operator= (const OsiTwoWayBranchingObject& rhs);
00463 
00465   virtual ~OsiTwoWayBranchingObject ();
00466   
00472   virtual double branch(OsiSolverInterface * solver)=0;
00473 
00474   inline int firstBranch() const { return firstBranch_; }
00475 
00476 protected:
00478   int firstBranch_;
00479 };
00481 
00482 
00483 class OsiSimpleInteger : public OsiObject2 {
00484 
00485 public:
00486 
00488   OsiSimpleInteger ();
00489 
00491   OsiSimpleInteger (const OsiSolverInterface * solver, int iColumn);
00492   
00494   OsiSimpleInteger (int iColumn, double lower, double upper);
00495   
00497   OsiSimpleInteger ( const OsiSimpleInteger &);
00498    
00500   virtual OsiObject * clone() const;
00501 
00503   OsiSimpleInteger & operator=( const OsiSimpleInteger& rhs);
00504 
00506   virtual ~OsiSimpleInteger ();
00507   
00509   virtual double infeasibility(const OsiBranchingInformation * info, int & whichWay) const;
00510 
00516   virtual double feasibleRegion(OsiSolverInterface * solver, const OsiBranchingInformation * info) const;
00517 
00522   virtual OsiBranchingObject * createBranch(OsiSolverInterface * solver, const OsiBranchingInformation * info, int way) const;
00523 
00524 
00526   inline void setColumnNumber(int value)
00527   {columnNumber_=value;};
00528   
00533   virtual int columnNumber() const;
00534 
00536   inline double originalLowerBound() const
00537   { return originalLower_;};
00538   inline void setOriginalLowerBound(double value)
00539   { originalLower_=value;};
00540   inline double originalUpperBound() const
00541   { return originalUpper_;};
00542   inline void setOriginalUpperBound(double value)
00543   { originalUpper_=value;};
00548   virtual void resetBounds(const OsiSolverInterface * solver) ;
00551   virtual void resetSequenceEtc(int numberColumns, const int * originalColumns);
00552   
00554   virtual double upEstimate() const;
00556   virtual double downEstimate() const;
00558   virtual bool canHandleShadowPrices() const
00559   { return false;};
00560 protected:
00563   double originalLower_;
00565   double originalUpper_;
00567   int columnNumber_;
00568   
00569 };
00577 class OsiIntegerBranchingObject : public OsiTwoWayBranchingObject {
00578 
00579 public:
00580 
00582   OsiIntegerBranchingObject ();
00583 
00591   OsiIntegerBranchingObject (OsiSolverInterface *solver,const OsiSimpleInteger * originalObject,
00592                              int way , double value) ;
00593     
00595   OsiIntegerBranchingObject ( const OsiIntegerBranchingObject &);
00596    
00598   OsiIntegerBranchingObject & operator= (const OsiIntegerBranchingObject& rhs);
00599 
00601   virtual OsiBranchingObject * clone() const;
00602 
00604   virtual ~OsiIntegerBranchingObject ();
00605   
00611   virtual double branch(OsiSolverInterface * solver);
00612 
00615   virtual void print(const OsiSolverInterface * solver=NULL);
00616 
00617 protected:
00618   // Probably could get away with just value which is already stored 
00620   double down_[2];
00622   double up_[2];
00623 };
00624 
00625 
00633 class OsiSOS : public OsiObject2 {
00634 
00635 public:
00636 
00637   // Default Constructor 
00638   OsiSOS ();
00639 
00644   OsiSOS (const OsiSolverInterface * solver, int numberMembers,
00645            const int * which, const double * weights, int type=1);
00646   
00647   // Copy constructor 
00648   OsiSOS ( const OsiSOS &);
00649    
00651   virtual OsiObject * clone() const;
00652 
00653   // Assignment operator 
00654   OsiSOS & operator=( const OsiSOS& rhs);
00655 
00656   // Destructor 
00657   virtual ~OsiSOS ();
00658   
00660   virtual double infeasibility(const OsiBranchingInformation * info,int & whichWay) const;
00661 
00667   virtual double feasibleRegion(OsiSolverInterface * solver, const OsiBranchingInformation * info) const;
00668 
00673   virtual OsiBranchingObject * createBranch(OsiSolverInterface * solver, const OsiBranchingInformation * info, int way) const;
00675   virtual double upEstimate() const;
00677   virtual double downEstimate() const;
00678   
00680   virtual void resetSequenceEtc(int numberColumns, const int * originalColumns);
00681   
00683   inline int numberMembers() const
00684   {return numberMembers_;};
00685 
00687   inline const int * members() const
00688   {return members_;};
00689 
00691   inline int sosType() const
00692   {return sosType_;};
00693 
00695   inline int setType() const
00696   {return sosType_;};
00697 
00699   inline const double * weights() const
00700   { return weights_;};
00701 
00704   virtual bool canDoHeuristics() const 
00705   {return (sosType_==1&&integerValued_);};
00707   inline void setIntegerValued(bool yesNo)
00708   { integerValued_=yesNo;};
00710   virtual bool canHandleShadowPrices() const
00711   { return true;};
00713   inline void setNumberMembers(int value)
00714   {numberMembers_=value;};
00715 
00717   inline int * mutableMembers() const
00718   {return members_;};
00719 
00721   inline void setSosType(int value)
00722   {sosType_=value;};
00723 
00725   inline  double * mutableWeights() const
00726   { return weights_;};
00727 protected:
00729 
00731   int * members_;
00733   double * weights_;
00734 
00736   int numberMembers_;
00738   int sosType_;
00740   bool integerValued_;
00741 };
00742 
00746 class OsiSOSBranchingObject : public OsiTwoWayBranchingObject {
00747 
00748 public:
00749 
00750   // Default Constructor 
00751   OsiSOSBranchingObject ();
00752 
00753   // Useful constructor
00754   OsiSOSBranchingObject (OsiSolverInterface * solver,  const OsiSOS * originalObject,
00755                             int way,
00756                          double separator);
00757   
00758   // Copy constructor 
00759   OsiSOSBranchingObject ( const OsiSOSBranchingObject &);
00760    
00761   // Assignment operator 
00762   OsiSOSBranchingObject & operator=( const OsiSOSBranchingObject& rhs);
00763 
00765   virtual OsiBranchingObject * clone() const;
00766 
00767   // Destructor 
00768   virtual ~OsiSOSBranchingObject ();
00769   
00771   virtual double branch(OsiSolverInterface * solver);
00772 
00775   virtual void print(const OsiSolverInterface * solver=NULL);
00776 private:
00778 };
00782 class OsiLotsize : public OsiObject2 {
00783 
00784 public:
00785 
00786   // Default Constructor 
00787   OsiLotsize ();
00788 
00789   /* Useful constructor - passed model index.
00790      Also passed valid values - if range then pairs
00791   */
00792   OsiLotsize (const OsiSolverInterface * solver, int iColumn,
00793               int numberPoints, const double * points, bool range=false);
00794   
00795   // Copy constructor 
00796   OsiLotsize ( const OsiLotsize &);
00797    
00799   virtual OsiObject * clone() const;
00800 
00801   // Assignment operator 
00802   OsiLotsize & operator=( const OsiLotsize& rhs);
00803 
00804   // Destructor 
00805   ~OsiLotsize ();
00806   
00808   virtual double infeasibility(const OsiBranchingInformation * info, int & whichWay) const;
00809 
00817   virtual double feasibleRegion(OsiSolverInterface * solver, const OsiBranchingInformation * info) const;
00818 
00823   virtual OsiBranchingObject * createBranch(OsiSolverInterface * solver, const OsiBranchingInformation * info, int way) const;
00824 
00825 
00827   inline void setColumnNumber(int value)
00828   {columnNumber_=value;};
00829   
00834   virtual int columnNumber() const;
00840   virtual void resetBounds(const OsiSolverInterface * solver);
00841 
00845   bool findRange(double value, double integerTolerance) const;
00846   
00849   virtual void floorCeiling(double & floorLotsize, double & ceilingLotsize, double value,
00850                             double tolerance) const;
00851   
00853   inline double originalLowerBound() const
00854   { return bound_[0];};
00855   inline double originalUpperBound() const
00856   { return bound_[rangeType_*numberRanges_-1];};
00858   inline int rangeType() const
00859   { return rangeType_;};
00861   inline int numberRanges() const
00862   { return numberRanges_;};
00864   inline double * bound() const
00865   { return bound_;};
00868   virtual void resetSequenceEtc(int numberColumns, const int * originalColumns);
00869   
00871   virtual double upEstimate() const;
00873   virtual double downEstimate() const;
00875   virtual bool canHandleShadowPrices() const
00876   { return true;};
00879   virtual bool canDoHeuristics() const 
00880   {return false;};
00881 
00882 private:
00884 
00886   int columnNumber_;
00888   int rangeType_;
00890   int numberRanges_;
00891   // largest gap
00892   double largestGap_;
00894   double * bound_;
00896   mutable int range_;
00897 };
00898 
00899 
00910 class OsiLotsizeBranchingObject : public OsiTwoWayBranchingObject {
00911 
00912 public:
00913 
00915   OsiLotsizeBranchingObject ();
00916 
00924   OsiLotsizeBranchingObject (OsiSolverInterface *solver,const OsiLotsize * originalObject, 
00925                              int way , double value) ;
00926   
00928   OsiLotsizeBranchingObject ( const OsiLotsizeBranchingObject &);
00929    
00931   OsiLotsizeBranchingObject & operator= (const OsiLotsizeBranchingObject& rhs);
00932 
00934   virtual OsiBranchingObject * clone() const;
00935 
00937   virtual ~OsiLotsizeBranchingObject ();
00938   
00944   virtual double branch(OsiSolverInterface * solver);
00945 
00948   virtual void print(const OsiSolverInterface * solver=NULL);
00949 
00950 protected:
00952   double down_[2];
00954   double up_[2];
00955 };
00956 #endif

Generated on Fri May 16 00:13:03 2008 by  doxygen 1.4.7