Changeset 889 for branches/heur


Ignore:
Timestamp:
Mar 5, 2008 1:47:07 PM (11 years ago)
Author:
ladanyi
Message:

code to decide when to run heuristics is done and compiles, need to debug

Location:
branches/heur/Cbc/src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • branches/heur/Cbc/src/CbcBranchActual.cpp

    r886 r889  
    1818#include "CoinSort.hpp"
    1919#include "CoinError.hpp"
    20 
    21 //##############################################################################
    22 
    23 /** Compare two ranges. The two bounds arrays are both of size two and
    24     describe closed intervals. Return the appropriate CbcRangeCompare value
    25     (first argument being the sub/superset if that's the case). In case of
    26     overlap (and if \c replaceIfOverlap is true) replace the content of thisBd
    27     with the intersection of the ranges.
    28 */
    29 static inline CbcRangeCompare
    30 CbcCompareRanges(double* thisBd, const double* otherBd,
    31                  const bool replaceIfOverlap)
    32 {
    33   const double lbDiff = thisBd[0] - otherBd[0];
    34   if (lbDiff < 0) { // lb of this < lb of other
    35     if (thisBd[1] >= otherBd[1]) { // ub of this >= ub of other
    36       return CbcRangeSuperset;
    37     } else if (thisBd[1] < otherBd[0]) {
    38       return CbcRangeDisjoint;
    39     } else {
    40       // overlap
    41       if (replaceIfOverlap) {
    42         thisBd[0] = otherBd[0];
    43       }
    44       return CbcRangeOverlap;
    45     }
    46   } else if (lbDiff > 0) { // lb of this > lb of other
    47     if (thisBd[1] <= otherBd[1]) { // ub of this <= ub of other
    48       return CbcRangeSubset;
    49     } else if (thisBd[0] > otherBd[1]) {
    50       return CbcRangeDisjoint;
    51     } else {
    52       // overlap
    53       if (replaceIfOverlap) {
    54         thisBd[1] = otherBd[1];
    55       }
    56       return CbcRangeOverlap;
    57     }
    58   } else { // lb of this == lb of other
    59     if (thisBd[1] == otherBd[1]) {
    60       return CbcRangeSame;
    61     }
    62     return thisBd[1] < otherBd[1] ? CbcRangeSubset : CbcRangeSuperset;
    63   }
    64 
    65   return CbcRangeSame; // fake return
    66 
    67 }
    6820
    6921//##############################################################################
  • branches/heur/Cbc/src/CbcBranchBase.hpp

    r886 r889  
    594594};
    595595
     596//##############################################################################
     597
     598/** Compare two ranges. The two bounds arrays are both of size two and
     599    describe closed intervals. Return the appropriate CbcRangeCompare value
     600    (first argument being the sub/superset if that's the case). In case of
     601    overlap (and if \c replaceIfOverlap is true) replace the content of thisBd
     602    with the intersection of the ranges.
     603*/
     604static inline CbcRangeCompare
     605CbcCompareRanges(double* thisBd, const double* otherBd,
     606                 const bool replaceIfOverlap)
     607{
     608  const double lbDiff = thisBd[0] - otherBd[0];
     609  if (lbDiff < 0) { // lb of this < lb of other
     610    if (thisBd[1] >= otherBd[1]) { // ub of this >= ub of other
     611      return CbcRangeSuperset;
     612    } else if (thisBd[1] < otherBd[0]) {
     613      return CbcRangeDisjoint;
     614    } else {
     615      // overlap
     616      if (replaceIfOverlap) {
     617        thisBd[0] = otherBd[0];
     618      }
     619      return CbcRangeOverlap;
     620    }
     621  } else if (lbDiff > 0) { // lb of this > lb of other
     622    if (thisBd[1] <= otherBd[1]) { // ub of this <= ub of other
     623      return CbcRangeSubset;
     624    } else if (thisBd[0] > otherBd[1]) {
     625      return CbcRangeDisjoint;
     626    } else {
     627      // overlap
     628      if (replaceIfOverlap) {
     629        thisBd[1] = otherBd[1];
     630      }
     631      return CbcRangeOverlap;
     632    }
     633  } else { // lb of this == lb of other
     634    if (thisBd[1] == otherBd[1]) {
     635      return CbcRangeSame;
     636    }
     637    return thisBd[1] < otherBd[1] ? CbcRangeSubset : CbcRangeSuperset;
     638  }
     639
     640  return CbcRangeSame; // fake return
     641
     642}
     643
    596644//#############################################################################
    597645
  • branches/heur/Cbc/src/CbcBranchCut.cpp

    r640 r889  
    284284  return false;
    285285}
     286
     287/** Compare the original object of \c this with the original object of \c
     288    brObj. Assumes that there is an ordering of the original objects.
     289    This method should be invoked only if \c this and brObj are of the same
     290    type.
     291    Return negative/0/positive depending on whether \c this is
     292    smaller/same/larger than the argument.
     293*/
     294int
     295CbcCutBranchingObject::compareOriginalObject
     296(const CbcBranchingObject* brObj) const
     297{
     298  const CbcCutBranchingObject* br =
     299    dynamic_cast<const CbcCutBranchingObject*>(brObj);
     300  assert(br);
     301  const OsiRowCut& r0 = way_ == -1 ? down_ : up_;
     302  const OsiRowCut& r1 = br->way_ == -1 ? br->down_ : br->up_;
     303  return r0.row().compare(r1.row());
     304}
     305
     306/** Compare the \c this with \c brObj. \c this and \c brObj must be os the
     307    same type and must have the same original object, but they may have
     308    different feasible regions.
     309    Return the appropriate CbcRangeCompare value (first argument being the
     310    sub/superset if that's the case). In case of overlap (and if \c
     311    replaceIfOverlap is true) replace the current branching object with one
     312    whose feasible region is the overlap.
     313*/
     314
     315CbcRangeCompare
     316CbcCutBranchingObject::compareBranchingObject
     317(const CbcBranchingObject* brObj, const bool replaceIfOverlap)
     318{
     319  const CbcCutBranchingObject* br =
     320    dynamic_cast<const CbcCutBranchingObject*>(brObj);
     321  assert(br);
     322  OsiRowCut& r0 = way_ == -1 ? down_ : up_;
     323  const OsiRowCut& r1 = br->way_ == -1 ? br->down_ : br->up_;
     324  double thisBd[2];
     325  thisBd[0] = r0.lb();
     326  thisBd[1] = r0.ub();
     327  double otherBd[2];
     328  otherBd[0] = r1.lb();
     329  otherBd[1] = r1.ub();
     330  CbcRangeCompare comp = CbcCompareRanges(thisBd, otherBd, replaceIfOverlap);
     331  if (comp != CbcRangeOverlap || (comp==CbcRangeOverlap && !replaceIfOverlap)) {
     332    return comp;
     333  }
     334  r0.setLb(thisBd[0]);
     335  r0.setUb(thisBd[1]);
     336  return comp;
     337}
     338
     339//##############################################################################
    286340
    287341/** Default Constructor
  • branches/heur/Cbc/src/CbcBranchCut.hpp

    r886 r889  
    150150  /** Return the type (an integer identifier) of \c this */
    151151  virtual int type() const { return 200; }
     152
     153  /** Compare the original object of \c this with the original object of \c
     154      brObj. Assumes that there is an ordering of the original objects.
     155      This method should be invoked only if \c this and brObj are of the same
     156      type.
     157      Return negative/0/positive depending on whether \c this is
     158      smaller/same/larger than the argument.
     159  */
     160  virtual int compareOriginalObject(const CbcBranchingObject* brObj) const;
    152161
    153162  /** Compare the \c this with \c brObj. \c this and \c brObj must be os the
  • branches/heur/Cbc/src/CbcBranchDynamic.hpp

    r886 r889  
    397397  virtual int type() const { return 400; }
    398398
    399   /** Compare the \c this with \c brObj. \c this and \c brObj must be os the
    400       same type and must have the same original object, but they may have
    401       different feasible regions.
    402       Return the appropriate CbcRangeCompare value (first argument being the
    403       sub/superset if that's the case). In case of overlap (and if \c
    404       replaceIfOverlap is true) replace the current branching object with one
    405       whose feasible region is the overlap.
    406    */
    407   virtual CbcRangeCompare compareBranchingObject
    408   (const CbcBranchingObject* brObj, const bool replaceIfOverlap = false);
     399  // LL: compareOriginalObject and compareBranchingObject are inherited from
     400  // CbcIntegerBranchingObject thus need not be declared/defined here. After
     401  // all, this kind of branching object is simply using pseudocosts to make
     402  // decisions, but once the decisions are made they are the same kind as in
     403  // the underlying class.
    409404
    410405protected:
  • branches/heur/Cbc/src/CbcBranchLotsize.cpp

    r640 r889  
    778778  }
    779779}
     780
     781/** Compare the \c this with \c brObj. \c this and \c brObj must be os the
     782    same type and must have the same original object, but they may have
     783    different feasible regions.
     784    Return the appropriate CbcRangeCompare value (first argument being the
     785    sub/superset if that's the case). In case of overlap (and if \c
     786    replaceIfOverlap is true) replace the current branching object with one
     787    whose feasible region is the overlap.
     788*/
     789CbcRangeCompare
     790CbcLotsizeBranchingObject::compareBranchingObject
     791(const CbcBranchingObject* brObj, const bool replaceIfOverlap)
     792{
     793  const CbcLotsizeBranchingObject* br =
     794    dynamic_cast<const CbcLotsizeBranchingObject*>(brObj);
     795  assert(br);
     796  double* thisBd = way_ == -1 ? down_ : up_;
     797  const double* otherBd = br->way_ == -1 ? br->down_ : br->up_;
     798  return CbcCompareRanges(thisBd, otherBd, replaceIfOverlap);
     799}
  • branches/heur/Cbc/src/CbcBranchLotsize.hpp

    r886 r889  
    205205  virtual int type() const { return 300; }
    206206
     207  // LL: compareOriginalObject can be inherited from the CbcBranchingObject
     208  // since variable_ uniquely defines the lot sizing object.
     209
    207210  /** Compare the \c this with \c brObj. \c this and \c brObj must be os the
    208211      same type and must have the same original object, but they may have
Note: See TracChangeset for help on using the changeset viewer.