/home/coin/SVN-release/Osi-0.97.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 double 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 
00384   int stateOfSearch_;
00386   double objectiveValue_;
00388   double cutoff_;
00390   double direction_;
00392   double integerTolerance_;
00394   double primalTolerance_;
00396   double timeRemaining_;
00398   double defaultDual_;
00400   mutable const OsiSolverInterface * solver_;
00402   int numberColumns_;
00404   mutable const double * lower_;
00406   mutable const double * solution_;
00408   mutable const double * upper_;
00410   const double * hotstartSolution_;
00412   const double * pi_;
00414   const double * rowActivity_;
00416   const double * objective_;
00418   const double * rowLower_;
00420   const double * rowUpper_;
00422   const double * elementByColumn_;
00424   const CoinBigIndex * columnStart_;
00426   const int * columnLength_;
00428   const int * row_;
00434   double * usefulRegion_;
00436   int * indexRegion_;
00438   int numberSolutions_;
00440   int numberBranchingSolutions_;
00442   int depth_;
00444   bool owningSolution_;
00445 };
00446 
00448 
00449 class OsiTwoWayBranchingObject : public OsiBranchingObject {
00450 
00451 public:
00452 
00454   OsiTwoWayBranchingObject ();
00455 
00462   OsiTwoWayBranchingObject (OsiSolverInterface *solver,const OsiObject * originalObject,
00463                              int way , double value) ;
00464     
00466   OsiTwoWayBranchingObject ( const OsiTwoWayBranchingObject &);
00467    
00469   OsiTwoWayBranchingObject & operator= (const OsiTwoWayBranchingObject& rhs);
00470 
00472   virtual ~OsiTwoWayBranchingObject ();
00473 
00474   using OsiBranchingObject::branch ;
00480   virtual double branch(OsiSolverInterface * solver)=0;
00481 
00482   inline int firstBranch() const { return firstBranch_; }
00483 
00484 protected:
00486   int firstBranch_;
00487 };
00489 
00490 
00491 class OsiSimpleInteger : public OsiObject2 {
00492 
00493 public:
00494 
00496   OsiSimpleInteger ();
00497 
00499   OsiSimpleInteger (const OsiSolverInterface * solver, int iColumn);
00500   
00502   OsiSimpleInteger (int iColumn, double lower, double upper);
00503   
00505   OsiSimpleInteger ( const OsiSimpleInteger &);
00506    
00508   virtual OsiObject * clone() const;
00509 
00511   OsiSimpleInteger & operator=( const OsiSimpleInteger& rhs);
00512 
00514   virtual ~OsiSimpleInteger ();
00515   
00516   using OsiObject::infeasibility ;
00518   virtual double infeasibility(const OsiBranchingInformation * info, int & whichWay) const;
00519 
00520   using OsiObject::feasibleRegion ;
00526   virtual double feasibleRegion(OsiSolverInterface * solver, const OsiBranchingInformation * info) const;
00527 
00532   virtual OsiBranchingObject * createBranch(OsiSolverInterface * solver, const OsiBranchingInformation * info, int way) const;
00533 
00534 
00536   inline void setColumnNumber(int value)
00537   {columnNumber_=value;}
00538   
00543   virtual int columnNumber() const;
00544 
00546   inline double originalLowerBound() const
00547   { return originalLower_;}
00548   inline void setOriginalLowerBound(double value)
00549   { originalLower_=value;}
00550   inline double originalUpperBound() const
00551   { return originalUpper_;}
00552   inline void setOriginalUpperBound(double value)
00553   { originalUpper_=value;}
00558   virtual void resetBounds(const OsiSolverInterface * solver) ;
00561   virtual void resetSequenceEtc(int numberColumns, const int * originalColumns);
00562   
00564   virtual double upEstimate() const;
00566   virtual double downEstimate() const;
00568   virtual bool canHandleShadowPrices() const
00569   { return false;}
00570 protected:
00573   double originalLower_;
00575   double originalUpper_;
00577   int columnNumber_;
00578   
00579 };
00587 class OsiIntegerBranchingObject : public OsiTwoWayBranchingObject {
00588 
00589 public:
00590 
00592   OsiIntegerBranchingObject ();
00593 
00601   OsiIntegerBranchingObject (OsiSolverInterface *solver,const OsiSimpleInteger * originalObject,
00602                              int way , double value) ;
00610   OsiIntegerBranchingObject (OsiSolverInterface *solver,const OsiSimpleInteger * originalObject,
00611                              int way , double value, double downUpperBound, double upLowerBound) ;
00612     
00614   OsiIntegerBranchingObject ( const OsiIntegerBranchingObject &);
00615    
00617   OsiIntegerBranchingObject & operator= (const OsiIntegerBranchingObject& rhs);
00618 
00620   virtual OsiBranchingObject * clone() const;
00621 
00623   virtual ~OsiIntegerBranchingObject ();
00624   
00625   using OsiBranchingObject::branch ;
00631   virtual double branch(OsiSolverInterface * solver);
00632 
00633   using OsiBranchingObject::print ;
00636   virtual void print(const OsiSolverInterface * solver=NULL);
00637 
00638 protected:
00639   // Probably could get away with just value which is already stored 
00641   double down_[2];
00643   double up_[2];
00644 };
00645 
00646 
00654 class OsiSOS : public OsiObject2 {
00655 
00656 public:
00657 
00658   // Default Constructor 
00659   OsiSOS ();
00660 
00665   OsiSOS (const OsiSolverInterface * solver, int numberMembers,
00666            const int * which, const double * weights, int type=1);
00667   
00668   // Copy constructor 
00669   OsiSOS ( const OsiSOS &);
00670    
00672   virtual OsiObject * clone() const;
00673 
00674   // Assignment operator 
00675   OsiSOS & operator=( const OsiSOS& rhs);
00676 
00677   // Destructor 
00678   virtual ~OsiSOS ();
00679   
00680   using OsiObject::infeasibility ;
00682   virtual double infeasibility(const OsiBranchingInformation * info,int & whichWay) const;
00683 
00684   using OsiObject::feasibleRegion ;
00690   virtual double feasibleRegion(OsiSolverInterface * solver, const OsiBranchingInformation * info) const;
00691 
00696   virtual OsiBranchingObject * createBranch(OsiSolverInterface * solver, const OsiBranchingInformation * info, int way) const;
00698   virtual double upEstimate() const;
00700   virtual double downEstimate() const;
00701   
00703   virtual void resetSequenceEtc(int numberColumns, const int * originalColumns);
00704   
00706   inline int numberMembers() const
00707   {return numberMembers_;}
00708 
00710   inline const int * members() const
00711   {return members_;}
00712 
00714   inline int sosType() const
00715   {return sosType_;}
00716 
00718   inline int setType() const
00719   {return sosType_;}
00720 
00722   inline const double * weights() const
00723   { return weights_;}
00724 
00727   virtual bool canDoHeuristics() const 
00728   {return (sosType_==1&&integerValued_);}
00730   inline void setIntegerValued(bool yesNo)
00731   { integerValued_=yesNo;}
00733   virtual bool canHandleShadowPrices() const
00734   { return true;}
00736   inline void setNumberMembers(int value)
00737   {numberMembers_=value;}
00738 
00740   inline int * mutableMembers() const
00741   {return members_;}
00742 
00744   inline void setSosType(int value)
00745   {sosType_=value;}
00746 
00748   inline  double * mutableWeights() const
00749   { return weights_;}
00750 protected:
00752 
00754   int * members_;
00756   double * weights_;
00757 
00759   int numberMembers_;
00761   int sosType_;
00763   bool integerValued_;
00764 };
00765 
00769 class OsiSOSBranchingObject : public OsiTwoWayBranchingObject {
00770 
00771 public:
00772 
00773   // Default Constructor 
00774   OsiSOSBranchingObject ();
00775 
00776   // Useful constructor
00777   OsiSOSBranchingObject (OsiSolverInterface * solver,  const OsiSOS * originalObject,
00778                             int way,
00779                          double separator);
00780   
00781   // Copy constructor 
00782   OsiSOSBranchingObject ( const OsiSOSBranchingObject &);
00783    
00784   // Assignment operator 
00785   OsiSOSBranchingObject & operator=( const OsiSOSBranchingObject& rhs);
00786 
00788   virtual OsiBranchingObject * clone() const;
00789 
00790   // Destructor 
00791   virtual ~OsiSOSBranchingObject ();
00792   
00793   using OsiBranchingObject::branch ;
00795   virtual double branch(OsiSolverInterface * solver);
00796 
00797   using OsiBranchingObject::print ;
00800   virtual void print(const OsiSolverInterface * solver=NULL);
00801 private:
00803 };
00807 class OsiLotsize : public OsiObject2 {
00808 
00809 public:
00810 
00811   // Default Constructor 
00812   OsiLotsize ();
00813 
00814   /* Useful constructor - passed model index.
00815      Also passed valid values - if range then pairs
00816   */
00817   OsiLotsize (const OsiSolverInterface * solver, int iColumn,
00818               int numberPoints, const double * points, bool range=false);
00819   
00820   // Copy constructor 
00821   OsiLotsize ( const OsiLotsize &);
00822    
00824   virtual OsiObject * clone() const;
00825 
00826   // Assignment operator 
00827   OsiLotsize & operator=( const OsiLotsize& rhs);
00828 
00829   // Destructor 
00830   ~OsiLotsize ();
00831   
00832   using OsiObject::infeasibility ;
00834   virtual double infeasibility(const OsiBranchingInformation * info, int & whichWay) const;
00835 
00836   using OsiObject::feasibleRegion ;
00844   virtual double feasibleRegion(OsiSolverInterface * solver, const OsiBranchingInformation * info) const;
00845 
00850   virtual OsiBranchingObject * createBranch(OsiSolverInterface * solver, const OsiBranchingInformation * info, int way) const;
00851 
00852 
00854   inline void setColumnNumber(int value)
00855   {columnNumber_=value;}
00856   
00861   virtual int columnNumber() const;
00867   virtual void resetBounds(const OsiSolverInterface * solver);
00868 
00872   bool findRange(double value, double integerTolerance) const;
00873   
00876   virtual void floorCeiling(double & floorLotsize, double & ceilingLotsize, double value,
00877                             double tolerance) const;
00878   
00880   inline double originalLowerBound() const
00881   { return bound_[0];}
00882   inline double originalUpperBound() const
00883   { return bound_[rangeType_*numberRanges_-1];}
00885   inline int rangeType() const
00886   { return rangeType_;}
00888   inline int numberRanges() const
00889   { return numberRanges_;}
00891   inline double * bound() const
00892   { return bound_;}
00895   virtual void resetSequenceEtc(int numberColumns, const int * originalColumns);
00896   
00898   virtual double upEstimate() const;
00900   virtual double downEstimate() const;
00902   virtual bool canHandleShadowPrices() const
00903   { return true;}
00906   virtual bool canDoHeuristics() const 
00907   {return false;}
00908 
00909 private:
00911 
00913   int columnNumber_;
00915   int rangeType_;
00917   int numberRanges_;
00918   // largest gap
00919   double largestGap_;
00921   double * bound_;
00923   mutable int range_;
00924 };
00925 
00926 
00937 class OsiLotsizeBranchingObject : public OsiTwoWayBranchingObject {
00938 
00939 public:
00940 
00942   OsiLotsizeBranchingObject ();
00943 
00951   OsiLotsizeBranchingObject (OsiSolverInterface *solver,const OsiLotsize * originalObject, 
00952                              int way , double value) ;
00953   
00955   OsiLotsizeBranchingObject ( const OsiLotsizeBranchingObject &);
00956    
00958   OsiLotsizeBranchingObject & operator= (const OsiLotsizeBranchingObject& rhs);
00959 
00961   virtual OsiBranchingObject * clone() const;
00962 
00964   virtual ~OsiLotsizeBranchingObject ();
00965 
00966   using OsiBranchingObject::branch ;
00972   virtual double branch(OsiSolverInterface * solver);
00973 
00974   using OsiBranchingObject::print ;
00977   virtual void print(const OsiSolverInterface * solver=NULL);
00978 
00979 protected:
00981   double down_[2];
00983   double up_[2];
00984 };
00985 #endif

Generated on Fri May 16 00:16:56 2008 by  doxygen 1.4.7