 Timestamp:
 May 7, 2007 1:44:28 PM (13 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

branches/Couenne/Couenne/src/branch/CouenneThreeWayBranchObj.cpp
r531 r534 7 7 */ 8 8 9 #include <CouenneBranchingObject.hpp> 9 10 #include <CouenneThreeWayBranchObj.hpp> 10 11 12 //CouNumber CouenneThreeWayBranchObj::lcrop_ = 0.8;13 //CouNumber CouenneThreeWayBranchObj::rcrop_ = 0.8;14 11 15 12 … … 18 15 */ 19 16 20 CouenneThreeWayBranchObj::CouenneThreeWayBranchObj (expression *var): 17 CouenneThreeWayBranchObj::CouenneThreeWayBranchObj (expression *var, 18 CouNumber x, 19 CouNumber l, 20 CouNumber u): 21 reference_ (var) { 21 22 22 reference_ (var) { 23 value_ = x; 24 numberBranches_ = 3; 23 25 24 // set the branching value at the current point25 // value_ = expression::Variable (reference_ > Index ());26 // Depending on where x, l, and u are, divide bound interval into 27 // three and set lcrop_ and rcrop_ accordingly. 26 28 27 int index = reference_ > Index ();29 // if l and u are unbounded, crop around x using COUENNE_CROP 28 30 29 long double 30 x = expression::Variable (index), // current solution 31 l = expression::Lbound (index), // lower bound 32 u = expression::Ubound (index), // upper 33 alpha = 0;//CouenneBranchingObject::Alpha (); 34 35 if (x<l) x = l; 36 else if (x>u) x = u; 37 38 if ((x > l + COUENNE_EPS) && 39 (x < u  COUENNE_EPS)) // x is not at the boundary 40 value_ = x; 41 42 else // current point is at one of the bounds 43 if ((l >  COUENNE_INFINITY + 1) && 44 (u < COUENNE_INFINITY  1)) 45 // finite bounds, apply midpoint rule 46 value_ = alpha * x + (1.  alpha) * (l + u) / 2.; 47 31 if ((xl > COUENNE_LARGE_INTERVAL) && 32 (ux > COUENNE_LARGE_INTERVAL)) { 33 lcrop_ = x  COUENNE_CROP; 34 rcrop_ = x + COUENNE_CROP; 35 first_ = 1; 36 } 37 else 38 if ((xl > COUENNE_LARGE_INTERVAL) && 39 (ux < COUENNE_NEAR_BOUND)) { 40 lcrop_ = x  COUENNE_CROP; 41 rcrop_ = x  COUENNE_LCROP; 42 first_ = 2; 43 } 48 44 else 49 // infinite (one direction) bound interval, x is at the boundary 50 // push it inwards 51 // TODO: look for a proper displacement 52 if (fabs (xl) < COUENNE_EPS) value_ = l + (1+fabs (l)) / 2.; 53 else value_ = u  (1+fabs (u)) / 2.; 54 55 if (0) { 56 printf ("Branch::constructor: "); 57 reference_ > print (std::cout); 58 printf (" on %.6e (%.6e) [%.6e,%.6e]\n", 59 value_, 60 expression::Variable (reference_ > Index ()), 61 expression::Lbound (reference_ > Index ()), 62 expression::Ubound (reference_ > Index ())); 63 } 45 if ((xl < COUENNE_NEAR_BOUND) && 46 (ux > COUENNE_LARGE_INTERVAL)) { 47 lcrop_ = x + COUENNE_CROP; 48 rcrop_ = x + COUENNE_LCROP; 49 first_ = 0; 50 } 64 51 } 65 52 … … 77 64 // 1 if ">= b" node 78 65 79 int way = branchIndex_  1, 80 ind = reference_ > Index (); 66 int way, ind = reference_ > Index (); 81 67 82 /*CouNumber l = solver > getColLower () [ind], 83 u = solver > getColUpper () [ind]; 68 switch (branchIndex_) { 69 case 0: 70 way = first_; // if first offspring, let first_ decide who's first 71 break; 72 case 1: 73 way = (first_ == 0) ? 1 : 0; 74 break; 75 case 2: 76 way = (first_ == 2) ? 1 : 2; 77 break; 78 default: 79 printf ("Warning, branchIndex_ has a strange value (%d)\n", branchIndex_); 80 } 84 81 85 if (way) { 86 if (value_ < l) printf ("Nonsense upbranch: [ %f ,(%f)] > [%f\n", l,u,value_); 87 else if (value_ < l+COUENNE_EPS) printf ("## WEAK upbranch: [ %f ,(%f)] > [%f\n", l,u,value_); 88 } else { 89 if (value_ > u) printf ("Nonsense dnbranch: [(%f), %f ] > %f]\n", l,u,value_); 90 else if (value_ > u+COUENNE_EPS) printf ("## WEAK dnbranch: [(%f), %f ] > %f]\n", l,u,value_); 91 } 92 */ 82 way ; // from {0,1,2} to {1,0,1} 93 83 94 84 // set lower or upper bound (round if this variable is integer) … … 99 89 100 90 case 1: // left interval 91 // printf ("Left branch: x%d <= %.3f\n", ind, lcrop_); 101 92 solver > setColUpper (ind, intvar ? floor (lcrop_) : lcrop_); 102 93 break; 103 94 case 0: // central interval 95 // printf ("Central branch: %.3f <= x%d <= %.3f\n", lcrop_, ind, rcrop_); 104 96 solver > setColLower (ind, intvar ? ceil (lcrop_) : lcrop_); 105 97 solver > setColUpper (ind, intvar ? floor (rcrop_) : rcrop_); 106 98 break; 107 99 case 1: // right interval 100 // printf ("Right branch: x%d >= %.3f\n", ind, rcrop_); 108 101 solver > setColLower (ind, intvar ? ceil (rcrop_) : rcrop_); 109 102 break;
Note: See TracChangeset
for help on using the changeset viewer.