Changeset 440
 Timestamp:
 Oct 8, 2006 7:34:21 PM (13 years ago)
 Location:
 branches/devel/Cbc/examples
 Files:

 6 edited
Legend:
 Unmodified
 Added
 Removed

branches/devel/Cbc/examples/CbcBranchLink.cpp
r425 r440 564 564 } 565 565 double 566 CbcLinkBranchingObject::branch(bool normalBranch) 567 { 568 if (model_>messageHandler()>logLevel()>2&&normalBranch) 569 print(normalBranch); 570 numberBranchesLeft_; 566 CbcLinkBranchingObject::branch() 567 { 568 decrementNumberBranchesLeft(); 571 569 int numberMembers = set_>numberMembers(); 572 570 int numberLinks = set_>numberLinks(); … … 614 612 // Print what would happen 615 613 void 616 CbcLinkBranchingObject::print( bool normalBranch)614 CbcLinkBranchingObject::print() 617 615 { 618 616 int numberMembers = set_>numberMembers(); 
branches/devel/Cbc/examples/CbcBranchLink.hpp
r425 r440 118 118 119 119 /// Does next branch and updates state 120 virtual double branch( bool normalBranch=false);120 virtual double branch(); 121 121 122 122 /** \brief Print something about branch  only if log level high 123 123 */ 124 virtual void print( bool normalBranch);124 virtual void print(); 125 125 private: 126 126 /// data 
branches/devel/Cbc/examples/CbcBranchLotsizeSimple.cpp
r403 r440 341 341 */ 342 342 double 343 CbcLotsizeSimpleBranchingObject::branch( bool normalBranch)344 { 345 numberBranchesLeft_;343 CbcLotsizeSimpleBranchingObject::branch() 344 { 345 decrementNumberBranchesLeft(); 346 346 int iColumn = variable_; 347 347 if (way_<0) { 
branches/devel/Cbc/examples/CbcBranchLotsizeSimple.hpp
r403 r440 143 143 of the branch and advances the object state to the next arm. 144 144 */ 145 virtual double branch( bool normalBranch=false);145 virtual double branch(); 146 146 147 147 protected: 
branches/devel/Cbc/examples/CbcBranchUser.cpp
r2 r440 323 323 return whichObject; 324 324 } 325 /** Default Constructor 326 327 Equivalent to an unspecified binary variable. 328 */ 329 CbcSimpleIntegerFixed::CbcSimpleIntegerFixed () 330 : CbcSimpleInteger() 331 { 332 } 333 334 /** Useful constructor 335 336 Loads actual upper & lower bounds for the specified variable. 337 */ 338 CbcSimpleIntegerFixed::CbcSimpleIntegerFixed (CbcModel * model, 339 int iColumn, double breakEven) 340 : CbcSimpleInteger(model,iColumn,breakEven) 341 { 342 } 343 // Constructor from simple 344 CbcSimpleIntegerFixed::CbcSimpleIntegerFixed (const CbcSimpleInteger & rhs) 345 : CbcSimpleInteger(rhs) 346 { 347 } 348 349 // Copy constructor 350 CbcSimpleIntegerFixed::CbcSimpleIntegerFixed ( const CbcSimpleIntegerFixed & rhs) 351 :CbcSimpleInteger(rhs) 352 353 { 354 } 355 356 // Clone 357 CbcObject * 358 CbcSimpleIntegerFixed::clone() const 359 { 360 return new CbcSimpleIntegerFixed(*this); 361 } 362 363 // Assignment operator 364 CbcSimpleIntegerFixed & 365 CbcSimpleIntegerFixed::operator=( const CbcSimpleIntegerFixed& rhs) 366 { 367 if (this!=&rhs) { 368 CbcSimpleInteger::operator=(rhs); 369 } 370 return *this; 371 } 372 373 // Destructor 374 CbcSimpleIntegerFixed::~CbcSimpleIntegerFixed () 375 { 376 } 377 378 // Infeasibility  large is 0.5 379 double 380 CbcSimpleIntegerFixed::infeasibility(int & preferredWay) const 381 { 382 OsiSolverInterface * solver = model_>solver(); 383 const double * solution = model_>testSolution(); 384 const double * lower = solver>getColLower(); 385 const double * upper = solver>getColUpper(); 386 double value = solution[columnNumber_]; 387 value = CoinMax(value, lower[columnNumber_]); 388 value = CoinMin(value, upper[columnNumber_]); 389 /*printf("%d %g %g %g %g\n",columnNumber_,value,lower[columnNumber_], 390 solution[columnNumber_],upper[columnNumber_]);*/ 391 double nearest = floor(value+(1.0breakEven_)); 392 assert (breakEven_>0.0&&breakEven_<1.0); 393 double integerTolerance = 394 model_>getDblParam(CbcModel::CbcIntegerTolerance); 395 if (nearest>value) 396 preferredWay=1; 397 else 398 preferredWay=1; 399 if (preferredWay_) 400 preferredWay=preferredWay_; 401 double weight = fabs(valuenearest); 402 // normalize so weight is 0.5 at break even 403 if (nearest<value) 404 weight = (0.5/breakEven_)*weight; 405 else 406 weight = (0.5/(1.0breakEven_))*weight; 407 if (fabs(valuenearest)<=integerTolerance) { 408 if (upper[columnNumber_]==lower[columnNumber_]) 409 return 0.0; 410 else 411 return 1.0e5; 412 } else { 413 return weight; 414 } 415 } 416 // Creates a branching object 417 CbcBranchingObject * 418 CbcSimpleIntegerFixed::createBranch(int way) 419 { 420 OsiSolverInterface * solver = model_>solver(); 421 const double * solution = model_>testSolution(); 422 const double * lower = solver>getColLower(); 423 const double * upper = solver>getColUpper(); 424 double value = solution[columnNumber_]; 425 value = CoinMax(value, lower[columnNumber_]); 426 value = CoinMin(value, upper[columnNumber_]); 427 assert (upper[columnNumber_]>lower[columnNumber_]); 428 if (!model_>hotstartSolution()) { 429 #ifndef NDEBUG 430 double nearest = floor(value+0.5); 431 double integerTolerance = 432 model_>getDblParam(CbcModel::CbcIntegerTolerance); 433 if (fabs(valuenearest)<integerTolerance) { 434 // adjust value 435 if (nearest!=upper[columnNumber_]) 436 value = nearest+2.0*integerTolerance; 437 else 438 value = nearest2.0*integerTolerance; 439 } 440 #endif 441 } else { 442 const double * hotstartSolution = model_>hotstartSolution(); 443 double targetValue = hotstartSolution[columnNumber_]; 444 if (way>0) 445 value = targetValue0.1; 446 else 447 value = targetValue+0.1; 448 } 449 CbcBranchingObject * branch = new CbcIntegerBranchingObject(model_,columnNumber_,way, 450 value); 451 branch>setOriginalObject(this); 452 return branch; 453 } 
branches/devel/Cbc/examples/CbcBranchUser.hpp
r2 r440 5 5 6 6 #include "CbcBranchBase.hpp" 7 #include "CbcBranchActual.hpp" 7 8 8 9 /** Branching decision user class */ … … 55 56 }; 56 57 58 /// Define a single integer class where branching is forced until fixed 59 60 61 class CbcSimpleIntegerFixed : public CbcSimpleInteger { 62 63 public: 64 65 // Default Constructor 66 CbcSimpleIntegerFixed (); 67 68 // Useful constructor  passed integer index and model index 69 CbcSimpleIntegerFixed (CbcModel * model, int iColumn, double breakEven=0.5); 70 71 // Constructor from simple 72 CbcSimpleIntegerFixed (const CbcSimpleInteger & simple); 73 74 // Copy constructor 75 CbcSimpleIntegerFixed ( const CbcSimpleIntegerFixed &); 76 77 /// Clone 78 virtual CbcObject * clone() const; 79 80 // Assignment operator 81 CbcSimpleIntegerFixed & operator=( const CbcSimpleIntegerFixed& rhs); 82 83 // Destructor 84 ~CbcSimpleIntegerFixed (); 85 86 /// Infeasibility  large is 0.5 87 virtual double infeasibility(int & preferredWay) const; 88 89 /** Creates a branching object 90 91 The preferred direction is set by \p way, 1 for down, +1 for up. 92 */ 93 virtual CbcBranchingObject * createBranch(int way) ; 94 95 protected: 96 /// data 97 }; 98 57 99 #endif
Note: See TracChangeset
for help on using the changeset viewer.