1 /* $Id$ */ 2 // Copyright (C) 2005, 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 #ifndef CbcStrategy_H 7 #define CbcStrategy_H 8 9 #include "CbcModel.hpp" 10 class CglPreProcess; 11 class CbcNodeInfo; 12 class CbcNode; 13 class CoinWarmStartDiff; 14 15 //############################################################################# 16 /** Strategy base class */ 17 18 class CbcStrategy { 19 public: 20 // Default Constructor 21 CbcStrategy(); 22 23 virtual ~CbcStrategy(); 24 25 /// Clone 26 virtual CbcStrategy *clone() const = 0; 27 28 /// Setup cut generators 29 virtual void setupCutGenerators(CbcModel &model) = 0; 30 /// Setup heuristics 31 virtual void setupHeuristics(CbcModel &model) = 0; 32 /// Do printing stuff 33 virtual void setupPrinting(CbcModel &model, int modelLogLevel) = 0; 34 /// Other stuff e.g. strong branching and preprocessing 35 virtual void setupOther(CbcModel &model) = 0; 36 /// Set model depth (i.e. how nested) setNested(int depth)37 inline void setNested(int depth) 38 { 39 depth_ = depth; 40 } 41 /// Get model depth (i.e. how nested) getNested() const42 inline int getNested() const 43 { 44 return depth_; 45 } 46 /// Say preProcessing done setPreProcessState(int state)47 inline void setPreProcessState(int state) 48 { 49 preProcessState_ = state; 50 } 51 /// See what sort of preprocessing was done preProcessState() const52 inline int preProcessState() const 53 { 54 return preProcessState_; 55 } 56 /// Pre-processing object process() const57 inline CglPreProcess *process() const 58 { 59 return process_; 60 } 61 /// Delete pre-processing object to save memory 62 void deletePreProcess(); 63 /// Return a new Full node information pointer (descendant of CbcFullNodeInfo) 64 virtual CbcNodeInfo *fullNodeInfo(CbcModel *model, int numberRowsAtContinuous) const; 65 /// Return a new Partial node information pointer (descendant of CbcPartialNodeInfo) 66 virtual CbcNodeInfo *partialNodeInfo(CbcModel *model, CbcNodeInfo *parent, CbcNode *owner, 67 int numberChangedBounds, const int *variables, 68 const double *boundChanges, 69 const CoinWarmStartDiff *basisDiff) const; 70 /// Create C++ lines to get to current state generateCpp(FILE *)71 virtual void generateCpp(FILE *) {} 72 /** After a CbcModel::resolve this can return a status 73 -1 no effect 74 0 treat as optimal 75 1 as 0 but do not do any more resolves (i.e. no more cuts) 76 2 treat as infeasible 77 */ 78 virtual int status(CbcModel *model, CbcNodeInfo *parent, int whereFrom); 79 80 private: 81 /// Illegal Assignment operator 82 CbcStrategy &operator=(const CbcStrategy &rhs); 83 84 protected: 85 // Data 86 /// Model depth 87 int depth_; 88 /** PreProcessing state - 89 -1 infeasible 90 0 off 91 1 was done (so need post-processing) 92 */ 93 int preProcessState_; 94 /// If preprocessing then this is object 95 CglPreProcess *process_; 96 }; 97 98 /** Null class 99 */ 100 101 class CbcStrategyNull : public CbcStrategy { 102 public: 103 // Default Constructor CbcStrategyNull()104 CbcStrategyNull() {} 105 106 // Copy constructor CbcStrategyNull(const CbcStrategyNull & rhs)107 CbcStrategyNull(const CbcStrategyNull &rhs) 108 : CbcStrategy(rhs) 109 { 110 } 111 112 // Destructor ~CbcStrategyNull()113 ~CbcStrategyNull() {} 114 115 /// Clone clone() const116 virtual CbcStrategy *clone() const 117 { 118 return new CbcStrategyNull(*this); 119 } 120 121 /// Setup cut generators setupCutGenerators(CbcModel &)122 virtual void setupCutGenerators(CbcModel &) {} 123 /// Setup heuristics setupHeuristics(CbcModel &)124 virtual void setupHeuristics(CbcModel &) {} 125 /// Do printing stuff setupPrinting(CbcModel &,int)126 virtual void setupPrinting(CbcModel &, int) {} 127 /// Other stuff e.g. strong branching setupOther(CbcModel &)128 virtual void setupOther(CbcModel &) {} 129 130 protected: 131 // Data 132 private: 133 /// Illegal Assignment operator 134 CbcStrategyNull &operator=(const CbcStrategyNull &rhs); 135 }; 136 137 /** Default class 138 */ 139 140 class CbcStrategyDefault : public CbcStrategy { 141 public: 142 // Default Constructor 143 CbcStrategyDefault(int cutsOnlyAtRoot = 1, 144 int numberStrong = 5, 145 int numberBeforeTrust = 0, 146 int printLevel = 0); 147 148 // Copy constructor 149 CbcStrategyDefault(const CbcStrategyDefault &); 150 151 // Destructor 152 ~CbcStrategyDefault(); 153 154 /// Clone 155 virtual CbcStrategy *clone() const; 156 157 /// Setup cut generators 158 virtual void setupCutGenerators(CbcModel &model); 159 /// Setup heuristics 160 virtual void setupHeuristics(CbcModel &model); 161 /// Do printing stuff 162 virtual void setupPrinting(CbcModel &model, int modelLogLevel); 163 /// Other stuff e.g. strong branching 164 virtual void setupOther(CbcModel &model); 165 /// Set up preProcessing - see below setupPreProcessing(int desired=1,int passes=10)166 inline void setupPreProcessing(int desired = 1, int passes = 10) 167 { 168 desiredPreProcess_ = desired; 169 preProcessPasses_ = passes; 170 } 171 /// See what sort of preprocessing wanted desiredPreProcess() const172 inline int desiredPreProcess() const 173 { 174 return desiredPreProcess_; 175 } 176 /// See how many passes wanted preProcessPasses() const177 inline int preProcessPasses() const 178 { 179 return preProcessPasses_; 180 } 181 /// Create C++ lines to get to current state 182 virtual void generateCpp(FILE *fp); 183 184 protected: 185 // Data 186 187 // Whether to do cuts only at root (-1 -> switch off totally) 188 int cutsOnlyAtRoot_; 189 190 // How much strong branching to do 191 int numberStrong_; 192 193 // Number branches needed to trust with dynamic pseudo costs 194 int numberBeforeTrust_; 195 196 // Print level 0 little, 1 medium 197 int printLevel_; 198 199 /** Desired pre-processing 200 0 - none 201 1 - ordinary 202 2 - find sos 203 3 - find cliques 204 4 - more aggressive sos 205 5 - add integer slacks 206 */ 207 int desiredPreProcess_; 208 /// Number of pre-processing passes 209 int preProcessPasses_; 210 211 private: 212 /// Illegal Assignment operator 213 CbcStrategyDefault &operator=(const CbcStrategyDefault &rhs); 214 }; 215 216 /** Default class for sub trees 217 */ 218 219 class CbcStrategyDefaultSubTree : public CbcStrategy { 220 public: 221 // Default Constructor 222 CbcStrategyDefaultSubTree(CbcModel *parent = NULL, int cutsOnlyAtRoot = 1, 223 int numberStrong = 5, 224 int numberBeforeTrust = 0, 225 int printLevel = 0); 226 227 // Copy constructor 228 CbcStrategyDefaultSubTree(const CbcStrategyDefaultSubTree &); 229 230 // Destructor 231 ~CbcStrategyDefaultSubTree(); 232 233 /// Clone 234 virtual CbcStrategy *clone() const; 235 236 /// Setup cut generators 237 virtual void setupCutGenerators(CbcModel &model); 238 /// Setup heuristics 239 virtual void setupHeuristics(CbcModel &model); 240 /// Do printing stuff 241 virtual void setupPrinting(CbcModel &model, int modelLogLevel); 242 /// Other stuff e.g. strong branching 243 virtual void setupOther(CbcModel &model); 244 245 protected: 246 // Data 247 // Parent model 248 CbcModel *parentModel_; 249 // Whether to do cuts only at root (-1 -> switch off totally) 250 int cutsOnlyAtRoot_; 251 252 // How much strong branching to do 253 int numberStrong_; 254 255 // Number branches needed to trust with dynamic pseudo costs 256 int numberBeforeTrust_; 257 258 // Print level 0 little, 1 medium 259 int printLevel_; 260 261 private: 262 /// Illegal Assignment operator 263 CbcStrategyDefaultSubTree &operator=(const CbcStrategyDefaultSubTree &rhs); 264 }; 265 266 #endif 267 268 /* vi: softtabstop=2 shiftwidth=2 expandtab tabstop=2 269 */ 270