1 // $Id$ 2 // Copyright (C) 2002, International Business Machines 3 // Corporation and others. All Rights Reserved. 4 // This code is licensed under the terms of the Eclipse Public License (EPL). 5 6 // Edwin 11/12/2009 carved from CbcBranchBase 7 8 #ifndef CbcBranchDecision_H 9 #define CbcBranchDecision_H 10 11 #include "CbcBranchBase.hpp" 12 13 /** Abstract branching decision base class 14 15 In the abstract, an CbcBranchDecision object is expected to be able to 16 compare two possible branching choices. 17 18 The #betterBranch() method is the crucial routine. It is expected to be able 19 to compare two \link CbcBranchingObject CbcBranchingObjects \endlink. 20 21 See CbcObject for an overview of the three classes (CbcObject, 22 CbcBranchingObject, and CbcBranchDecision) which make up cbc's branching 23 model. 24 */ 25 class CbcModel; 26 class OsiChooseVariable; 27 28 class CbcBranchDecision { 29 public: 30 /// Default Constructor 31 CbcBranchDecision(); 32 33 // Copy constructor 34 CbcBranchDecision(const CbcBranchDecision &); 35 36 /// Destructor 37 virtual ~CbcBranchDecision(); 38 39 /// Clone 40 virtual CbcBranchDecision *clone() const = 0; 41 42 /// Initialize <i>e.g.</i> before starting to choose a branch at a node 43 virtual void initialize(CbcModel *model) = 0; 44 45 /** \brief Compare two branching objects. Return nonzero if branching 46 using \p thisOne is better than branching using \p bestSoFar. 47 48 If \p bestSoFar is NULL, the routine should return a nonzero value. 49 This routine is used only after strong branching. 50 Either this or bestBranch is used depending which user wants. 51 52 */ 53 54 virtual int 55 betterBranch(CbcBranchingObject *thisOne, 56 CbcBranchingObject *bestSoFar, 57 double changeUp, int numberInfeasibilitiesUp, 58 double changeDown, int numberInfeasibilitiesDown) 59 = 0; 60 61 /** \brief Compare N branching objects. Return index of best 62 and sets way of branching in chosen object. 63 64 Either this or betterBranch is used depending which user wants. 65 */ 66 67 virtual int 68 bestBranch(CbcBranchingObject **objects, int numberObjects, int numberUnsatisfied, 69 double *changeUp, int *numberInfeasibilitiesUp, 70 double *changeDown, int *numberInfeasibilitiesDown, 71 double objectiveValue); 72 73 /** Says whether this method can handle both methods - 74 1 better, 2 best, 3 both */ whichMethod()75 virtual int whichMethod() 76 { 77 return 2; 78 } 79 80 /** Saves a clone of current branching object. Can be used to update 81 information on object causing branch - after branch */ saveBranchingObject(OsiBranchingObject *)82 virtual void saveBranchingObject(OsiBranchingObject *) {} 83 /** Pass in information on branch just done. 84 assumes object can get information from solver */ updateInformation(OsiSolverInterface *,const CbcNode *)85 virtual void updateInformation(OsiSolverInterface *, 86 const CbcNode *) {} 87 /** Sets or gets best criterion so far */ setBestCriterion(double)88 virtual void setBestCriterion(double) {} getBestCriterion() const89 virtual double getBestCriterion() const 90 { 91 return 0.0; 92 } 93 /// Create C++ lines to get to current state generateCpp(FILE *)94 virtual void generateCpp(FILE *) {} 95 /// Model cbcModel() const96 inline CbcModel *cbcModel() const 97 { 98 return model_; 99 } 100 /* If chooseMethod_ id non-null then the rest is fairly pointless 101 as choosemethod_ will be doing all work 102 This comment makes more sense if you realise that there's a conversion in 103 process from the Cbc branching classes to Osi branching classes. The test 104 for use of the Osi branching classes is CbcModel::branchingMethod_ 105 non-null (i.e., it points to one of these CbcBranchDecision objects) and 106 that branch decision object has an OsiChooseVariable method set. In which 107 case, we'll use it, rather than the choose[*]Variable methods defined in 108 CbcNode. 109 */ 110 chooseMethod() const111 OsiChooseVariable *chooseMethod() const 112 { 113 return chooseMethod_; 114 } 115 /// Set (clone) chooseMethod 116 void setChooseMethod(const OsiChooseVariable &method); 117 118 protected: 119 // Clone of branching object 120 CbcBranchingObject *object_; 121 /// Pointer to model 122 CbcModel *model_; 123 /* If chooseMethod_ id non-null then the rest is fairly pointless 124 as choosemethod_ will be doing all work 125 */ 126 OsiChooseVariable *chooseMethod_; 127 128 private: 129 /// Assignment is illegal 130 CbcBranchDecision &operator=(const CbcBranchDecision &rhs); 131 }; 132 #endif 133 134 /* vi: softtabstop=2 shiftwidth=2 expandtab tabstop=2 135 */ 136