Changeset 1286 for branches/sandbox/Cbc/src/CbcBranchBase.cpp
 Timestamp:
 Nov 9, 2009 6:33:07 PM (11 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

branches/sandbox/Cbc/src/CbcBranchBase.cpp
r1271 r1286 20 20 21 21 // Default Constructor 22 CbcObject::CbcObject() 23 : OsiObject(),24 model_(NULL),25 id_(1),26 position_(1),27 preferredWay_(0)22 CbcObject::CbcObject() 23 : OsiObject(), 24 model_(NULL), 25 id_(1), 26 position_(1), 27 preferredWay_(0) 28 28 { 29 29 } … … 31 31 // Constructor from model 32 32 CbcObject::CbcObject(CbcModel * model) 33 : OsiObject(),34 model_(model),35 id_(1),36 position_(1),37 preferredWay_(0)38 { 39 } 40 41 42 // Destructor 33 : OsiObject(), 34 model_(model), 35 id_(1), 36 position_(1), 37 preferredWay_(0) 38 { 39 } 40 41 42 // Destructor 43 43 CbcObject::~CbcObject () 44 44 { 45 45 } 46 46 47 // Copy constructor 47 // Copy constructor 48 48 CbcObject::CbcObject ( const CbcObject & rhs) 49 : OsiObject(rhs) 50 { 51 model_ = rhs.model_; 52 id_ = rhs.id_; 53 position_ = rhs.position_; 54 preferredWay_ = rhs.preferredWay_; 55 } 56 57 // Assignment operator 58 CbcObject & 59 CbcObject::operator=( const CbcObject& rhs) 60 { 61 if (this!=&rhs) { 62 OsiObject::operator=(rhs); 49 : OsiObject(rhs) 50 { 63 51 model_ = rhs.model_; 64 52 id_ = rhs.id_; 65 53 position_ = rhs.position_; 66 54 preferredWay_ = rhs.preferredWay_; 67 } 68 return *this; 55 } 56 57 // Assignment operator 58 CbcObject & 59 CbcObject::operator=( const CbcObject & rhs) 60 { 61 if (this != &rhs) { 62 OsiObject::operator=(rhs); 63 model_ = rhs.model_; 64 id_ = rhs.id_; 65 position_ = rhs.position_; 66 preferredWay_ = rhs.preferredWay_; 67 } 68 return *this; 69 69 } 70 70 71 71 /* Returns floor and ceiling i.e. closest valid points 72 72 */ 73 void 73 void 74 74 CbcObject::floorCeiling(double & floorValue, double & ceilingValue, double value, 75 76 { 77 if (fabs(floor(value+0.5)value)>tolerance) {78 floorValue = floor(value);79 } else {80 floorValue = floor(value+0.5);81 }82 ceilingValue = floorValue+1.0;75 double tolerance) const 76 { 77 if (fabs(floor(value + 0.5)  value) > tolerance) { 78 floorValue = floor(value); 79 } else { 80 floorValue = floor(value + 0.5); 81 } 82 ceilingValue = floorValue + 1.0; 83 83 } 84 84 /* For the variable(s) referenced by the object, … … 86 86 Returns measure of how much it had to move solution to make feasible 87 87 */ 88 double 89 CbcObject::feasibleRegion(OsiSolverInterface * /*solver*/) const 90 { 91 //assert (solver==model_>solver());92 CbcObject * fudge = const_cast<CbcObject *>(this);93 fudge>feasibleRegion();94 return 0.0;95 } 96 88 double 89 CbcObject::feasibleRegion(OsiSolverInterface * /*solver*/) const 90 { 91 //assert (solver==model_>solver()); 92 CbcObject * fudge = const_cast<CbcObject *>(this); 93 fudge>feasibleRegion(); 94 return 0.0; 95 } 96 97 97 /* For the variable(s) referenced by the object, 98 98 look at the current solution and set bounds to match the solution. 99 99 Returns measure of how much it had to move solution to make feasible 100 100 */ 101 double 101 double 102 102 CbcObject::feasibleRegion(OsiSolverInterface * /*solver*/, 103 const OsiBranchingInformation * /*info*/) const 104 { 105 //assert (solver==model_>solver());106 CbcObject * fudge = const_cast<CbcObject *>(this);107 fudge>feasibleRegion();108 return 0.0;103 const OsiBranchingInformation * /*info*/) const 104 { 105 //assert (solver==model_>solver()); 106 CbcObject * fudge = const_cast<CbcObject *>(this); 107 fudge>feasibleRegion(); 108 return 0.0; 109 109 } 110 110 /* Create a branching object and indicate which way to branch first. 111 111 112 112 The branching object has to know how to create branches (fix 113 113 variables, etc.) 114 114 */ 115 OsiBranchingObject * 115 OsiBranchingObject * 116 116 CbcObject::createOsiBranch(OsiSolverInterface * solver, 117 const OsiBranchingInformation * info, 118 int way) const 119 { 120 //assert (solver==model_>solver());121 CbcObject * fudge = const_cast<CbcObject *>(this);122 return fudge>createBranch(solver,info,way);117 const OsiBranchingInformation * info, 118 int way) const 119 { 120 //assert (solver==model_>solver()); 121 CbcObject * fudge = const_cast<CbcObject *>(this); 122 return fudge>createBranch(solver, info, way); 123 123 } 124 124 /* Create an OsiSolverBranch object 125 125 126 126 This returns NULL if branch not represented by bound changes 127 127 */ 128 OsiSolverBranch * 128 OsiSolverBranch * 129 129 CbcObject::solverBranch() const 130 130 { 131 return NULL;131 return NULL; 132 132 } 133 133 /* Pass in information on branch just done and create CbcObjectUpdateData instance. 134 134 If object does not need data then backward pointer will be NULL. 135 135 Assumes can get information from solver */ 136 CbcObjectUpdateData 137 CbcObject::createUpdateInformation(const OsiSolverInterface * /*solver*/, 138 139 140 { 141 return CbcObjectUpdateData();142 } 143 144 // Default Constructor 136 CbcObjectUpdateData 137 CbcObject::createUpdateInformation(const OsiSolverInterface * /*solver*/, 138 const CbcNode * /*node*/, 139 const CbcBranchingObject * /*branchingObject*/) 140 { 141 return CbcObjectUpdateData(); 142 } 143 144 // Default Constructor 145 145 CbcBranchingObject::CbcBranchingObject() 146 : OsiBranchingObject()147 { 148 model_=NULL;149 originalCbcObject_=NULL;150 variable_=1;151 way_=0;146 : OsiBranchingObject() 147 { 148 model_ = NULL; 149 originalCbcObject_ = NULL; 150 variable_ = 1; 151 way_ = 0; 152 152 } 153 153 154 154 // Useful constructor 155 155 CbcBranchingObject::CbcBranchingObject (CbcModel * model, int variable, int way , double value) 156 : OsiBranchingObject(model>solver(),value)157 { 158 model_= model;159 originalCbcObject_=NULL;160 variable_=variable;161 way_=way;162 } 163 164 // Copy constructor 156 : OsiBranchingObject(model>solver(), value) 157 { 158 model_ = model; 159 originalCbcObject_ = NULL; 160 variable_ = variable; 161 way_ = way; 162 } 163 164 // Copy constructor 165 165 CbcBranchingObject::CbcBranchingObject ( const CbcBranchingObject & rhs) 166 : OsiBranchingObject(rhs)167 { 168 model_=rhs.model_;169 originalCbcObject_=rhs.originalCbcObject_;170 variable_=rhs.variable_;171 way_=rhs.way_;172 value_=rhs.value_;173 } 174 175 // Assignment operator 176 CbcBranchingObject & 177 CbcBranchingObject::operator=( const CbcBranchingObject & rhs)178 { 179 if (this != &rhs) {180 OsiBranchingObject::operator=(rhs);181 model_=rhs.model_;182 originalCbcObject_=rhs.originalCbcObject_;183 variable_=rhs.variable_;184 way_=rhs.way_;185 }186 return *this;187 } 188 189 // Destructor 166 : OsiBranchingObject(rhs) 167 { 168 model_ = rhs.model_; 169 originalCbcObject_ = rhs.originalCbcObject_; 170 variable_ = rhs.variable_; 171 way_ = rhs.way_; 172 value_ = rhs.value_; 173 } 174 175 // Assignment operator 176 CbcBranchingObject & 177 CbcBranchingObject::operator=( const CbcBranchingObject & rhs) 178 { 179 if (this != &rhs) { 180 OsiBranchingObject::operator=(rhs); 181 model_ = rhs.model_; 182 originalCbcObject_ = rhs.originalCbcObject_; 183 variable_ = rhs.variable_; 184 way_ = rhs.way_; 185 } 186 return *this; 187 } 188 189 // Destructor 190 190 CbcBranchingObject::~CbcBranchingObject () 191 191 { 192 192 } 193 // Default Constructor 193 // Default Constructor 194 194 CbcBranchDecision::CbcBranchDecision () 195 : object_(NULL),model_(NULL),chooseMethod_(NULL)196 { 197 } 198 199 // Copy Constructor 195 : object_(NULL), model_(NULL), chooseMethod_(NULL) 196 { 197 } 198 199 // Copy Constructor 200 200 CbcBranchDecision::CbcBranchDecision (const CbcBranchDecision &rhs) 201 : object_(NULL),model_(rhs.model_),chooseMethod_(NULL)202 { 203 if (rhs.chooseMethod_)204 chooseMethod_ = rhs.chooseMethod_>clone();201 : object_(NULL), model_(rhs.model_), chooseMethod_(NULL) 202 { 203 if (rhs.chooseMethod_) 204 chooseMethod_ = rhs.chooseMethod_>clone(); 205 205 } 206 206 207 207 CbcBranchDecision::~CbcBranchDecision() 208 208 { 209 delete object_;210 delete chooseMethod_;209 delete object_; 210 delete chooseMethod_; 211 211 } 212 212 /* Compare N branching objects. Return index of best 213 213 and sets way of branching in chosen object. 214 214 215 215 This routine is used only after strong branching. 216 216 This is reccommended version as it can be more sophisticated … … 219 219 int 220 220 CbcBranchDecision::bestBranch (CbcBranchingObject ** objects, int numberObjects, 221 222 223 224 double /*objectiveValue*/) 225 { 226 int bestWay=0;227 int whichObject = 1;228 if (numberObjects) {229 initialize(objects[0]>model());230 CbcBranchingObject * bestObject = NULL;231 for (int i = 0 ; i < numberObjects ; i++) {232 int betterWay = betterBranch(objects[i],233 234 235 236 237 238 if (betterWay) {239 240 241 whichObject=i;242 }243 }244 // set way in best245 if (whichObject>=0)246 objects[whichObject]>way(bestWay);247 }248 return whichObject;221 int /*numberUnsatisfied*/, 222 double * changeUp, int * numberInfeasibilitiesUp, 223 double * changeDown, int * numberInfeasibilitiesDown, 224 double /*objectiveValue*/) 225 { 226 int bestWay = 0; 227 int whichObject = 1; 228 if (numberObjects) { 229 initialize(objects[0]>model()); 230 CbcBranchingObject * bestObject = NULL; 231 for (int i = 0 ; i < numberObjects ; i++) { 232 int betterWay = betterBranch(objects[i], 233 bestObject, 234 changeUp[i], 235 numberInfeasibilitiesUp [i], 236 changeDown[i], 237 numberInfeasibilitiesDown[i] ); 238 if (betterWay) { 239 bestObject = objects[i]; 240 bestWay = betterWay; 241 whichObject = i; 242 } 243 } 244 // set way in best 245 if (whichObject >= 0) 246 objects[whichObject]>way(bestWay); 247 } 248 return whichObject; 249 249 } 250 250 // Set (clone) chooseMethod 251 void 251 void 252 252 CbcBranchDecision::setChooseMethod(const OsiChooseVariable & method) 253 { 254 delete chooseMethod_;255 chooseMethod_ = method.clone();253 { 254 delete chooseMethod_; 255 chooseMethod_ = method.clone(); 256 256 } 257 257 // Default constructor … … 261 261 262 262 263 // Destructor 263 // Destructor 264 264 CbcConsequence::~CbcConsequence () 265 265 { 266 266 } 267 267 268 // Copy constructor 268 // Copy constructor 269 269 CbcConsequence::CbcConsequence ( const CbcConsequence & /*rhs*/) 270 270 { 271 271 } 272 272 273 // Assignment operator 274 CbcConsequence & 275 CbcConsequence::operator=( const CbcConsequence & rhs)276 { 277 if (this!=&rhs) {278 }279 return *this;273 // Assignment operator 274 CbcConsequence & 275 CbcConsequence::operator=( const CbcConsequence & rhs) 276 { 277 if (this != &rhs) { 278 } 279 return *this; 280 280 } 281 281 // Default constructor 282 282 CbcObjectUpdateData::CbcObjectUpdateData() 283 : object_(NULL),284 way_(0),285 objectNumber_(1),286 change_(0.0),287 status_(0),288 intDecrease_(0),289 branchingValue_(0.0),290 originalObjective_(COIN_DBL_MAX),291 cutoff_(COIN_DBL_MAX)283 : object_(NULL), 284 way_(0), 285 objectNumber_(1), 286 change_(0.0), 287 status_(0), 288 intDecrease_(0), 289 branchingValue_(0.0), 290 originalObjective_(COIN_DBL_MAX), 291 cutoff_(COIN_DBL_MAX) 292 292 { 293 293 } … … 295 295 // Useful constructor 296 296 CbcObjectUpdateData::CbcObjectUpdateData (CbcObject * object, 297 298 299 300 301 302 : object_(object),303 way_(way),304 objectNumber_(1),305 change_(change),306 status_(status),307 intDecrease_(intDecrease),308 branchingValue_(branchingValue),309 originalObjective_(COIN_DBL_MAX),310 cutoff_(COIN_DBL_MAX)311 { 312 } 313 314 // Destructor 297 int way, 298 double change, 299 int status, 300 int intDecrease, 301 double branchingValue) 302 : object_(object), 303 way_(way), 304 objectNumber_(1), 305 change_(change), 306 status_(status), 307 intDecrease_(intDecrease), 308 branchingValue_(branchingValue), 309 originalObjective_(COIN_DBL_MAX), 310 cutoff_(COIN_DBL_MAX) 311 { 312 } 313 314 // Destructor 315 315 CbcObjectUpdateData::~CbcObjectUpdateData () 316 316 { 317 317 } 318 318 319 // Copy constructor 319 // Copy constructor 320 320 CbcObjectUpdateData::CbcObjectUpdateData ( const CbcObjectUpdateData & rhs) 321 : object_(rhs.object_),322 way_(rhs.way_),323 objectNumber_(rhs.objectNumber_),324 change_(rhs.change_),325 status_(rhs.status_),326 intDecrease_(rhs.intDecrease_),327 branchingValue_(rhs.branchingValue_),328 originalObjective_(rhs.originalObjective_),329 cutoff_(rhs.cutoff_)330 { 331 } 332 333 // Assignment operator 334 CbcObjectUpdateData & 335 CbcObjectUpdateData::operator=( const CbcObjectUpdateData & rhs)336 { 337 if (this!=&rhs) {338 object_ = rhs.object_;339 way_ = rhs.way_;340 objectNumber_ = rhs.objectNumber_;341 change_ = rhs.change_;342 status_ = rhs.status_;343 intDecrease_ = rhs.intDecrease_;344 branchingValue_ = rhs.branchingValue_;345 originalObjective_ = rhs.originalObjective_;346 cutoff_ = rhs.cutoff_;347 }348 return *this;349 } 350 351 321 : object_(rhs.object_), 322 way_(rhs.way_), 323 objectNumber_(rhs.objectNumber_), 324 change_(rhs.change_), 325 status_(rhs.status_), 326 intDecrease_(rhs.intDecrease_), 327 branchingValue_(rhs.branchingValue_), 328 originalObjective_(rhs.originalObjective_), 329 cutoff_(rhs.cutoff_) 330 { 331 } 332 333 // Assignment operator 334 CbcObjectUpdateData & 335 CbcObjectUpdateData::operator=( const CbcObjectUpdateData & rhs) 336 { 337 if (this != &rhs) { 338 object_ = rhs.object_; 339 way_ = rhs.way_; 340 objectNumber_ = rhs.objectNumber_; 341 change_ = rhs.change_; 342 status_ = rhs.status_; 343 intDecrease_ = rhs.intDecrease_; 344 branchingValue_ = rhs.branchingValue_; 345 originalObjective_ = rhs.originalObjective_; 346 cutoff_ = rhs.cutoff_; 347 } 348 return *this; 349 } 350 351
Note: See TracChangeset
for help on using the changeset viewer.