Ignore:
Timestamp:
May 7, 2007 1:44:28 PM (13 years ago)
Author:
pbelotti
Message:

moved include files to make them doxygenable. Introduced three-way branching, with fixed intervals for now. Added check for small bound interval within all generateCuts()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/Couenne/Couenne/src/branch/CouenneThreeWayBranchObj.cpp

    r531 r534  
    77 */
    88
     9#include <CouenneBranchingObject.hpp>
    910#include <CouenneThreeWayBranchObj.hpp>
    10 
    11 
    12 //CouNumber CouenneThreeWayBranchObj::lcrop_ = 0.8;
    13 //CouNumber CouenneThreeWayBranchObj::rcrop_ = 0.8;
    1411
    1512
     
    1815*/
    1916
    20 CouenneThreeWayBranchObj::CouenneThreeWayBranchObj (expression *var):
     17CouenneThreeWayBranchObj::CouenneThreeWayBranchObj (expression *var,
     18                                                    CouNumber x,
     19                                                    CouNumber l,
     20                                                    CouNumber u):
     21  reference_      (var) {
    2122
    22   reference_ (var) {
     23  value_          = x;
     24  numberBranches_ = 3;
    2325
    24   // set the branching value at the current point
    25   //  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.
    2628
    27   int index = reference_ -> Index ();
     29  // if l and u are unbounded, crop around x using COUENNE_CROP
    2830
    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 ((x-l > COUENNE_LARGE_INTERVAL) &&
     32      (u-x > COUENNE_LARGE_INTERVAL)) {
     33    lcrop_ = x - COUENNE_CROP;
     34    rcrop_ = x + COUENNE_CROP;
     35    first_ = 1;
     36  }
     37  else
     38    if ((x-l > COUENNE_LARGE_INTERVAL) &&
     39        (u-x < COUENNE_NEAR_BOUND)) {
     40      lcrop_ = x - COUENNE_CROP;
     41      rcrop_ = x - COUENNE_LCROP;
     42      first_ = 2;
     43    }
    4844    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 (x-l) < 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 ((x-l < COUENNE_NEAR_BOUND) &&
     46          (u-x > COUENNE_LARGE_INTERVAL)) {
     47        lcrop_ = x + COUENNE_CROP;
     48        rcrop_ = x + COUENNE_LCROP;
     49        first_ = 0;
     50      }
    6451}
    6552
     
    7764  //        1 if ">= b"  node
    7865
    79   int way = branchIndex_ - 1,
    80       ind = reference_ -> Index ();
     66  int way, ind = reference_ -> Index ();
    8167
    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  }
    8481
    85   if (way) {
    86     if      (value_ < l)             printf ("Nonsense up-branch: [ %f ,(%f)] -> [%f\n", l,u,value_);
    87     else if (value_ < l+COUENNE_EPS) printf ("## WEAK  up-branch: [ %f ,(%f)] -> [%f\n", l,u,value_);
    88   } else {
    89     if      (value_ > u)             printf ("Nonsense dn-branch: [(%f), %f ] -> %f]\n", l,u,value_);
    90     else if (value_ > u+COUENNE_EPS) printf ("## WEAK  dn-branch: [(%f), %f ] -> %f]\n", l,u,value_);
    91   }
    92   */
     82  way --; // from {0,1,2} to {-1,0,1}
    9383
    9484  // set lower or upper bound (round if this variable is integer)
     
    9989
    10090  case -1: // left interval
     91    //    printf ("Left branch: x%d <= %.3f\n", ind, lcrop_);
    10192    solver -> setColUpper (ind, intvar ? floor (lcrop_) : lcrop_);
    10293    break;
    10394  case  0: // central interval
     95    //    printf ("Central branch: %.3f <= x%d <= %.3f\n", lcrop_, ind, rcrop_);
    10496    solver -> setColLower (ind, intvar ? ceil  (lcrop_) : lcrop_);
    10597    solver -> setColUpper (ind, intvar ? floor (rcrop_) : rcrop_);
    10698    break;
    10799  case  1: // right interval
     100    //    printf ("Right branch: x%d >= %.3f\n", ind, rcrop_);
    108101    solver -> setColLower (ind, intvar ? ceil  (rcrop_) : rcrop_);
    109102    break;
Note: See TracChangeset for help on using the changeset viewer.