/home/coin/SVN-release/Cbc-2.0.0/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 #include "OsiBranchingObject.hpp"
00009 class OsiSolverInterface;
00010 class OsiSolverBranch;
00011 
00012 class CbcModel;
00013 class CbcNode;
00014 class CbcNodeInfo;
00015 class CbcBranchingObject;
00016 class OsiChooseVariable;
00017 class CbcObjectUpdateData;
00018 
00019 //#############################################################################
00020 
00046 // This can be used if object wants to skip strong branching
00047   typedef struct {
00048     CbcBranchingObject * possibleBranch; // what a branch would do
00049     double upMovement; // cost going up (and initial away from feasible)
00050     double downMovement; // cost going down
00051     int numIntInfeasUp ; // without odd ones
00052     int numObjInfeasUp ; // just odd ones
00053     bool finishedUp; // true if solver finished
00054     int numItersUp ; // number of iterations in solver
00055     int numIntInfeasDown ; // without odd ones
00056     int numObjInfeasDown ; // just odd ones
00057     bool finishedDown; // true if solver finished
00058     int numItersDown; // number of iterations in solver
00059     int objectNumber; // Which object it is
00060     int fix; // 0 if no fix, 1 if we can fix up, -1 if we can fix down
00061   } CbcStrongInfo;
00062 
00063 class CbcObject : public OsiObject {
00064 
00065 public:
00066 
00067   // Default Constructor 
00068   CbcObject ();
00069 
00070   // Useful constructor
00071   CbcObject (CbcModel * model);
00072   
00073   // Copy constructor 
00074   CbcObject ( const CbcObject &);
00075    
00076   // Assignment operator 
00077   CbcObject & operator=( const CbcObject& rhs);
00078 
00080   virtual CbcObject * clone() const=0;
00081 
00083   virtual ~CbcObject ();
00084 
00099   virtual double infeasibility(int &preferredWay) const = 0;
00101   virtual double infeasibility(const OsiBranchingInformation * info,
00102                                int &preferredWay) const;
00103 
00107   virtual void feasibleRegion() = 0;
00109   virtual double feasibleRegion(OsiSolverInterface * solver, const OsiBranchingInformation * info) const;
00110 
00116   virtual CbcBranchingObject * createBranch(int way) = 0;
00117   
00134   virtual double infeasibility(const OsiSolverInterface * solver,int &preferredWay) const;
00135   
00140   virtual double feasibleRegion(OsiSolverInterface * solver) const ;
00141   
00147   virtual OsiBranchingObject * createBranch(OsiSolverInterface * solver, int way) const;
00153   virtual OsiBranchingObject * createBranch(OsiSolverInterface * solver,const OsiBranchingInformation * info, int way) const;
00158   virtual OsiSolverBranch * solverBranch() const;
00159   
00168   virtual CbcBranchingObject * preferredNewFeasible() const 
00169   { return NULL;}
00170   
00179   virtual CbcBranchingObject * notPreferredNewFeasible() const 
00180   { return NULL;}
00181 
00186   virtual void resetBounds(const OsiSolverInterface * solver) {}
00187   
00190   virtual void floorCeiling(double & floorValue, double & ceilingValue, double value,
00191                             double tolerance) const;
00192 
00196   virtual CbcObjectUpdateData createUpdateInformation(const OsiSolverInterface * solver, 
00197                                                         const CbcNode * node,
00198                                                         const CbcBranchingObject * branchingObject);
00199 
00201   virtual void updateInformation(const CbcObjectUpdateData & data) {}
00202 
00204   inline int id() const
00205   { return id_;}
00206   
00208   inline void setModel(CbcModel * model)
00209   { model_ = model;}
00210   
00212   inline CbcModel * model() const
00213   {return  model_;}
00214 
00216   inline int preferredWay() const
00217   { return preferredWay_;}
00219   inline void setPreferredWay(int value)
00220   { preferredWay_=value;}
00222   virtual void redoSequenceEtc(CbcModel * model, int numberColumns, const int * originalColumns) {}
00223   
00224 protected:
00226 
00228   CbcModel * model_;
00230   int id_;
00232   int preferredWay_;
00233 
00234 };
00235 
00254 class CbcBranchingObject : public OsiBranchingObject {
00255 
00256 public:
00257 
00259   CbcBranchingObject ();
00260 
00262   CbcBranchingObject (CbcModel * model, int variable, int way , double value);
00263   
00265   CbcBranchingObject ( const CbcBranchingObject &);
00266    
00268   CbcBranchingObject & operator=( const CbcBranchingObject& rhs);
00269 
00271   virtual CbcBranchingObject * clone() const=0;
00272 
00274   virtual ~CbcBranchingObject ();
00275 
00280   virtual int fillStrongInfo( CbcStrongInfo & info) {return 0;}
00282   inline void resetNumberBranchesLeft()
00283   { branchIndex_=0;}
00284 
00291   virtual double branch()=0;
00298   virtual double branch(OsiSolverInterface * solver)
00299   { return branch();}
00300 
00301   using OsiBranchingObject::print ;
00304   virtual void print() const {}
00305 
00317   inline int variable() const
00318   {return variable_;}
00319 
00327   inline int way() const
00328   {return way_;}
00329 
00334   inline void way(int way)
00335   {way_=way;}
00336 
00338   inline void setModel(CbcModel * model)
00339   { model_ = model;}
00341   inline CbcModel * model() const
00342   {return  model_;}
00343 
00345   inline CbcObject * object() const
00346   {return  originalCbcObject_;}
00348   inline void setOriginalObject(CbcObject * object)
00349   {originalCbcObject_=object;}
00350 
00351 protected:
00352 
00354   CbcModel * model_;
00356   CbcObject * originalCbcObject_;
00357 
00359   int variable_;
00360   // was - Way to branch - -1 down (first), 1 up, -2 down (second), 2 up (second)
00368   int way_;
00369 
00370 };
00371 
00372 
00386 class CbcBranchDecision {
00387 public:
00389   CbcBranchDecision ();
00390 
00391   // Copy constructor 
00392   CbcBranchDecision ( const CbcBranchDecision &);
00393    
00395   virtual ~CbcBranchDecision();
00396 
00398   virtual CbcBranchDecision * clone() const = 0;
00399 
00401   virtual void initialize(CbcModel * model) = 0;
00402 
00412   virtual int
00413   betterBranch (CbcBranchingObject * thisOne,
00414                 CbcBranchingObject * bestSoFar,
00415                 double changeUp, int numberInfeasibilitiesUp,
00416                 double changeDown, int numberInfeasibilitiesDown) = 0 ;
00417 
00424   virtual int
00425   bestBranch (CbcBranchingObject ** objects, int numberObjects, int numberUnsatisfied,
00426               double * changeUp, int * numberInfeasibilitiesUp,
00427               double * changeDown, int * numberInfeasibilitiesDown,
00428               double objectiveValue) ;
00429 
00432   virtual int whichMethod() {return 2;}
00433 
00436   virtual void saveBranchingObject(OsiBranchingObject * object) {}
00439   virtual void updateInformation(OsiSolverInterface * solver, 
00440                                  const CbcNode * node) {}
00442   virtual void setBestCriterion(double value) {}
00443   virtual double getBestCriterion() const {return 0.0;}
00445   virtual void generateCpp( FILE * fp) {}
00447   inline CbcModel * cbcModel() const
00448   { return model_;}
00449   /* If chooseMethod_ id non-null then the rest is fairly pointless
00450      as choosemethod_ will be doing all work
00451   */
00452   OsiChooseVariable * chooseMethod() const
00453   { return chooseMethod_;}
00455   void setChooseMethod(const OsiChooseVariable & method);
00456 
00457 protected:
00458   
00459   // Clone of branching object
00460   CbcBranchingObject * object_;
00462   CbcModel * model_;
00463   /* If chooseMethod_ id non-null then the rest is fairly pointless
00464      as choosemethod_ will be doing all work
00465   */
00466   OsiChooseVariable * chooseMethod_;
00467 private:
00469   CbcBranchDecision & operator=(const CbcBranchDecision& rhs);
00470   
00471 };
00481 class CbcConsequence {
00482 
00483 public:
00484 
00485   // Default Constructor 
00486   CbcConsequence ();
00487 
00488   // Copy constructor 
00489   CbcConsequence ( const CbcConsequence & rhs);
00490    
00491   // Assignment operator 
00492   CbcConsequence & operator=( const CbcConsequence & rhs);
00493 
00495   virtual CbcConsequence * clone() const=0;
00496 
00498   virtual ~CbcConsequence ();
00499 
00502   virtual void applyToSolver(OsiSolverInterface * solver, int state) const=0;
00503   
00504 protected:
00505 };
00506 /*  This stores data so an object can be updated
00507  */
00508 class CbcObjectUpdateData {
00509 
00510 public:
00511 
00513   CbcObjectUpdateData ();
00514 
00516   CbcObjectUpdateData (CbcObject * object,
00517                        int way,
00518                        double change,
00519                        int status,
00520                        int intDecrease_,
00521                        double branchingValue);
00522   
00524   CbcObjectUpdateData ( const CbcObjectUpdateData &);
00525    
00527   CbcObjectUpdateData & operator=( const CbcObjectUpdateData& rhs);
00528 
00530   virtual ~CbcObjectUpdateData ();
00531 
00532   
00533 public:
00535 
00537   CbcObject * object_;
00539   int way_;
00541   int objectNumber_;
00543   double change_;
00545   int status_;
00547   int intDecrease_;
00549   double branchingValue_;
00550 
00551 };
00552 
00553 #endif

Generated on Thu May 15 22:07:39 2008 by  doxygen 1.4.7