/home/coin/SVN-release/Cbc-1.1.1/Cbc/src/CbcBranchBase.hpp

Go to the documentation of this file.
00001 // Copyright (C) 2002, International Business Machines
00002 // Corporation and others.  All Rights Reserved.
00003 #ifndef CbcBranchBase_H
00004 #define CbcBranchBase_H
00005 
00006 #include <string>
00007 #include <vector>
00008 
00009 class OsiSolverInterface;
00010 class OsiSolverBranch;
00011 
00012 class CbcModel;
00013 class CbcNode;
00014 class CbcNodeInfo;
00015 class CbcBranchingObject;
00016 
00017 //#############################################################################
00018 
00043 // This can be used if object wants to skip strong branching
00044   typedef struct {
00045     CbcBranchingObject * possibleBranch; // what a branch would do
00046     double upMovement; // cost going up (and initial away from feasible)
00047     double downMovement; // cost going down
00048     int numIntInfeasUp ; // without odd ones
00049     int numObjInfeasUp ; // just odd ones
00050     bool finishedUp; // true if solver finished
00051     int numItersUp ; // number of iterations in solver
00052     int numIntInfeasDown ; // without odd ones
00053     int numObjInfeasDown ; // just odd ones
00054     bool finishedDown; // true if solver finished
00055     int numItersDown; // number of iterations in solver
00056     int objectNumber; // Which object it is
00057     int fix; // 0 if no fix, 1 if we can fix up, -1 if we can fix down
00058   } CbcStrongInfo;
00059 
00060 class CbcObject {
00061 
00062 public:
00063 
00064   // Default Constructor 
00065   CbcObject ();
00066 
00067   // Useful constructor
00068   CbcObject (CbcModel * model);
00069   
00070   // Copy constructor 
00071   CbcObject ( const CbcObject &);
00072    
00073   // Assignment operator 
00074   CbcObject & operator=( const CbcObject& rhs);
00075 
00077   virtual CbcObject * clone() const=0;
00078 
00080   virtual ~CbcObject ();
00081 
00096   virtual double infeasibility(int &preferredWay) const = 0;
00097 
00101   virtual void feasibleRegion() = 0;
00102 
00108   virtual CbcBranchingObject * createBranch(int way) = 0;
00109   
00114   virtual OsiSolverBranch * solverBranch() const;
00115   
00124   virtual CbcBranchingObject * preferredNewFeasible() const 
00125   { return NULL;};
00126   
00135   virtual CbcBranchingObject * notPreferredNewFeasible() const 
00136   { return NULL;};
00137 
00143   virtual void resetBounds() {};
00144   
00147   virtual bool boundBranch() const 
00148   {return true;};
00151   virtual void floorCeiling(double & floorValue, double & ceilingValue, double value,
00152                             double tolerance) const;
00153 
00155   inline int id() const
00156   { return id_;};
00158   inline int priority() const
00159   { return priority_;};
00161   inline void setPriority(int priority)
00162   { priority_ = priority;};
00163   
00165   virtual int columnNumber() const;
00166 
00167   
00169   inline void setModel(CbcModel * model)
00170   { model_ = model;};
00171   
00173   inline CbcModel * model() const
00174   {return  model_;};
00175 
00177   virtual double upEstimate() const;
00179   virtual double downEstimate() const;
00181   inline int preferredWay() const
00182   { return preferredWay_;};
00184   inline void setPreferredWay(int value)
00185   { preferredWay_=value;};
00187   virtual void redoSequenceEtc(CbcModel * model, int numberColumns, const int * originalColumns) {};
00188   
00189 protected:
00191 
00193   CbcModel * model_;
00195   int id_;
00197   int priority_;
00199   int preferredWay_;
00200 
00201 };
00202 
00220 class CbcBranchingObject {
00221 
00222 public:
00223 
00225   CbcBranchingObject ();
00226 
00228   CbcBranchingObject (CbcModel * model, int variable, int way , double value);
00229   
00231   CbcBranchingObject ( const CbcBranchingObject &);
00232    
00234   CbcBranchingObject & operator=( const CbcBranchingObject& rhs);
00235 
00237   virtual CbcBranchingObject * clone() const=0;
00238 
00240   virtual ~CbcBranchingObject ();
00241 
00246   virtual int fillStrongInfo( CbcStrongInfo & info) {return 0;};
00252   virtual int numberBranches() const
00253   {return 2;};
00254 
00256   virtual int numberBranchesLeft() const
00257   {return numberBranchesLeft_;};
00259   inline void resetNumberBranchesLeft()
00260   { numberBranchesLeft_ = numberBranches();};
00261 
00268   virtual double branch(bool normalBranch=false)=0;
00269 
00272   virtual void print(bool normalBranch) {};
00273 
00276   virtual bool boundBranch() const 
00277   {return true;};
00278 
00290   inline int variable() const
00291   {return variable_;};
00292 
00300   inline int way() const
00301   {return way_;};
00302 
00307   inline void way(int way)
00308   {way_=way;};
00309 
00311   inline double value() const
00312   {return value_;};
00313   
00315   inline CbcModel * model() const
00316   {return  model_;};
00317 
00319   inline CbcObject * object() const
00320   {return  originalObject_;};
00322   inline void setOriginalObject(CbcObject * object)
00323   {originalObject_=object;};
00324 
00325 protected:
00326 
00328   CbcModel * model_;
00330   CbcObject * originalObject_;
00331 
00333   int variable_;
00334   // was - Way to branch - -1 down (first), 1 up, -2 down (second), 2 up (second)
00342   int way_;
00343 
00345   double value_;
00346 
00352   int numberBranchesLeft_;
00353 
00354 };
00355 
00356 
00370 class CbcBranchDecision {
00371 public:
00373   CbcBranchDecision ();
00374 
00376   virtual ~CbcBranchDecision();
00377 
00379   virtual CbcBranchDecision * clone() const = 0;
00380 
00382   virtual void initialize(CbcModel * model) = 0;
00383 
00393   virtual int
00394   betterBranch (CbcBranchingObject * thisOne,
00395                 CbcBranchingObject * bestSoFar,
00396                 double changeUp, int numberInfeasibilitiesUp,
00397                 double changeDown, int numberInfeasibilitiesDown) = 0 ;
00398 
00405   virtual int
00406   bestBranch (CbcBranchingObject ** objects, int numberObjects, int numberUnsatisfied,
00407               double * changeUp, int * numberInfeasibilitiesUp,
00408               double * changeDown, int * numberInfeasibilitiesDown,
00409               double objectiveValue) ;
00410 
00413   virtual int whichMethod() {return 2;};
00414 
00417   virtual void saveBranchingObject(CbcBranchingObject * object) {};
00420   virtual void updateInformation(OsiSolverInterface * solver, 
00421                                  const CbcNode * node) {};
00423   virtual void setBestCriterion(double value) {};
00424   virtual double getBestCriterion() const {return 0.0;};
00426   virtual void generateCpp( FILE * fp) {};
00427 
00428 protected:
00429   
00430   // Clone of branching object
00431   CbcBranchingObject * object_;
00432 private:
00434   CbcBranchDecision & operator=(const CbcBranchDecision& rhs);
00435   
00436 };
00446 class CbcConsequence {
00447 
00448 public:
00449 
00450   // Default Constructor 
00451   CbcConsequence ();
00452 
00453   // Copy constructor 
00454   CbcConsequence ( const CbcConsequence & rhs);
00455    
00456   // Assignment operator 
00457   CbcConsequence & operator=( const CbcConsequence & rhs);
00458 
00460   virtual CbcConsequence * clone() const=0;
00461 
00463   virtual ~CbcConsequence ();
00464 
00467   virtual void applyToSolver(OsiSolverInterface * solver, int state) const=0;
00468   
00469 protected:
00470 };
00471 
00472 #endif

Generated on Thu May 15 21:59:04 2008 by  doxygen 1.4.7