Ignore:
Timestamp:
Oct 8, 2006 7:33:47 PM (13 years ago)
Author:
forrest
Message:

towards common use with other solvers

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/devel/Cbc/src/CbcBranchBase.hpp

    r424 r439  
    66#include <string>
    77#include <vector>
    8 
     8#include "OsiBranchingObject.hpp"
    99class OsiSolverInterface;
    1010class OsiSolverBranch;
     
    1414class CbcNodeInfo;
    1515class CbcBranchingObject;
     16class OsiChooseVariable;
    1617
    1718//#############################################################################
    1819
    1920/** Abstract base class for `objects'.
     21    It now just has stuff that OsiObject does not have
    2022
    2123  The branching model used in Cbc is based on the idea of an <i>object</i>.
     
    5860  } CbcStrongInfo;
    5961
    60 class CbcObject {
     62class CbcObject : public OsiObject {
    6163
    6264public:
     
    9597  */
    9698  virtual double infeasibility(int &preferredWay) const = 0;
     99  /// Dummy one for compatibility
     100  virtual double infeasibility(const OsiBranchingInformation * info,
     101                               int &preferredWay) const;
    97102
    98103  /** For the variable(s) referenced by the object,
     
    100105  */
    101106  virtual void feasibleRegion() = 0;
     107  /// Dummy one for compatibility
     108  virtual double feasibleRegion(OsiSolverInterface * solver, const OsiBranchingInformation * info) const;
    102109
    103110  /** Create a branching object and indicate which way to branch first.
     
    108115  virtual CbcBranchingObject * createBranch(int way) = 0;
    109116 
     117  /** Infeasibility of the object
     118     
     119    This is some measure of the infeasibility of the object. 0.0
     120    indicates that the object is satisfied.
     121 
     122    The preferred branching direction is returned in way,
     123 
     124    This is used to prepare for strong branching but should also think of
     125    case when no strong branching
     126 
     127    The object may also compute an estimate of cost of going "up" or "down".
     128    This will probably be based on pseudo-cost ideas
     129
     130    This should also set mutable infeasibility_ and whichWay_
     131    This is for instant re-use for speed
     132  */
     133  virtual double infeasibility(const OsiSolverInterface * solver,int &preferredWay) const;
     134 
     135  /** For the variable(s) referenced by the object,
     136      look at the current solution and set bounds to match the solution.
     137      Returns measure of how much it had to move solution to make feasible
     138  */
     139  virtual double feasibleRegion(OsiSolverInterface * solver) const ;
     140 
     141  /** Create a branching object and indicate which way to branch first.
     142     
     143      The branching object has to know how to create branches (fix
     144      variables, etc.)
     145  */
     146  virtual OsiBranchingObject * createBranch(OsiSolverInterface * solver, int way) const;
    110147  /** Create an OsiSolverBranch object
    111148
     
    141178    their original values.
    142179   */
    143   virtual void resetBounds() {};
    144  
    145   /** \brief Return true if branch created by object should fix variables
    146   */
    147   virtual bool boundBranch() const
    148   {return true;};
    149   /** \brief Return true if object can take part in normal heuristics
    150   */
    151   virtual bool canDoHeuristics() const
    152   {return true;};
     180  virtual void resetBounds(const OsiSolverInterface * solver) {};
     181 
    153182  /** Returns floor and ceiling i.e. closest valid points
    154183  */
     
    159188  inline int id() const
    160189  { return id_;};
    161   /// Return Priority
    162   inline int priority() const
    163   { return priority_;};
    164   /// Set priority
    165   inline void setPriority(int priority)
    166   { priority_ = priority;};
    167  
    168   /// Column number if single column object -1 otherwise
    169   virtual int columnNumber() const;
    170 
    171190 
    172191   /// update model
     
    178197  {return  model_;};
    179198
    180   /// Return "up" estimate (default 1.0e-5)
    181   virtual double upEstimate() const;
    182   /// Return "down" estimate (default 1.0e-5)
    183   virtual double downEstimate() const;
    184199  /// If -1 down always chosen first, +1 up always, 0 normal
    185200  inline int preferredWay() const
     
    198213  /// Identifier (normally column number in matrix)
    199214  int id_;
    200   /// Priority
    201   int priority_;
    202215  /// If -1 down always chosen first, +1 up always, 0 normal
    203216  int preferredWay_;
     
    206219
    207220/** \brief Abstract branching object base class
     221    Now just difference with OsiBranchingObject
    208222
    209223  In the abstract, an CbcBranchingObject contains instructions for how to
     
    222236*/
    223237
    224 class CbcBranchingObject {
     238class CbcBranchingObject : public OsiBranchingObject {
    225239
    226240public:
     
    249263      Returns nonzero if skip is wanted */
    250264  virtual int fillStrongInfo( CbcStrongInfo & info) {return 0;};
    251   /** The number of branch arms created for this branching object
    252 
    253     \todo The hardwired `2' has to be changed before cbc can do branches with
    254           more than two arms.
    255   */
    256   virtual int numberBranches() const
    257   {return 2;};
    258 
    259   /// The number of branch arms left to be evaluated
    260   virtual int numberBranchesLeft() const
    261   {return numberBranchesLeft_;};
    262265  /// Reset number of branches left to original
    263266  inline void resetNumberBranchesLeft()
    264   { numberBranchesLeft_ = numberBranches();};
     267  { branchIndex_=0;};
    265268
    266269  /** \brief Execute the actions required to branch, as specified by the
     
    270273             Returns change in guessed objective on next branch
    271274  */
    272   virtual double branch(bool normalBranch=false)=0;
     275  virtual double branch()=0;
    273276
    274277  /** \brief Print something about branch - only if log level high
    275278  */
    276   virtual void print(bool normalBranch) {};
    277 
    278   /** \brief Return true if branch should fix variables
    279   */
    280   virtual bool boundBranch() const
    281   {return true;};
     279  virtual void print() const {};
    282280
    283281  /** \brief Index identifying the associated CbcObject within its class.
     
    312310  {way_=way;};
    313311
    314   /// Current value
    315   inline double value() const
    316   {return value_;};
    317  
    318312  /// Return model
    319313  inline CbcModel * model() const
     
    322316  /// Return pointer back to object which created
    323317  inline CbcObject * object() const
    324   {return  originalObject_;};
     318  {return  originalCbcObject_;};
    325319  /// Set pointer back to object which created
    326320  inline void setOriginalObject(CbcObject * object)
    327   {originalObject_=object;};
     321  {originalCbcObject_=object;};
    328322
    329323protected:
     
    332326  CbcModel * model_;
    333327  /// Pointer back to object which created
    334   CbcObject * originalObject_;
     328  CbcObject * originalCbcObject_;
    335329
    336330  /// Branching variable (0 is first integer)
     
    346340  int way_;
    347341
    348   /// Current value
    349   double value_;
    350 
    351   /** Number of arms remaining to be evaluated
    352 
    353     \todo Compare with CbcNodeInfo::numberBranchesLeft_, and check for
    354           redundancy.
    355   */
    356   int numberBranchesLeft_;
    357 
    358342};
    359343
     
    377361  CbcBranchDecision ();
    378362
     363  // Copy constructor
     364  CbcBranchDecision ( const CbcBranchDecision &);
     365   
    379366  /// Destructor
    380367  virtual ~CbcBranchDecision();
     
    419406  /** Saves a clone of current branching object.  Can be used to update
    420407      information on object causing branch - after branch */
    421   virtual void saveBranchingObject(CbcBranchingObject * object) {};
     408  virtual void saveBranchingObject(OsiBranchingObject * object) {};
    422409  /** Pass in information on branch just done.
    423410      assumes object can get information from solver */
     
    429416  /// Create C++ lines to get to current state
    430417  virtual void generateCpp( FILE * fp) {};
     418  /// Model
     419  inline CbcModel * cbcModel() const
     420  { return model_;}
     421  /* If chooseMethod_ id non-null then the rest is fairly pointless
     422     as choosemethod_ will be doing all work
     423  */
     424  OsiChooseVariable * chooseMethod() const
     425  { return chooseMethod_;};
     426  /// Set (clone) chooseMethod
     427  void setChooseMethod(const OsiChooseVariable & method);
    431428
    432429protected:
     
    434431  // Clone of branching object
    435432  CbcBranchingObject * object_;
     433  /// Pointer to model
     434  CbcModel * model_;
     435  /* If chooseMethod_ id non-null then the rest is fairly pointless
     436     as choosemethod_ will be doing all work
     437  */
     438  OsiChooseVariable * chooseMethod_;
    436439private:
    437440  /// Assignment is illegal
Note: See TracChangeset for help on using the changeset viewer.