Ignore:
Timestamp:
Apr 10, 2008 1:55:10 PM (13 years ago)
Author:
ladanyi
Message:

Incorporated changes from branches/heur

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Cbc/src/CbcBranchBase.hpp

    r833 r912  
    1616class OsiChooseVariable;
    1717class CbcObjectUpdateData;
     18
     19//#############################################################################
     20
     21enum CbcRangeCompare {
     22  CbcRangeSame,
     23  CbcRangeDisjoint,
     24  CbcRangeSubset,
     25  CbcRangeSuperset,
     26  CbcRangeOverlap
     27};
    1828
    1929//#############################################################################
     
    299309  { return branch();}
    300310
     311  /** Reset every information so that the branching object appears to point to
     312      the previous child. This method does not need to modify anything in any
     313      solver. */
     314  virtual void previousBranch() {
     315    assert(branchIndex_ > 0);
     316    branchIndex_--;
     317    way_ = -way_;
     318  }
     319
    301320  using OsiBranchingObject::print ;
    302321  /** \brief Print something about branch - only if log level high
     
    348367  inline void setOriginalObject(CbcObject * object)
    349368  {originalCbcObject_=object;}
     369
     370  // Methods used in heuristics
     371 
     372  /** Return the type (an integer identifier) of \c this */
     373  virtual int type() const = 0;
     374
     375  /** Compare the original object of \c this with the original object of \c
     376      brObj. Assumes that there is an ordering of the original objects.
     377      This method should be invoked only if \c this and brObj are of the same
     378      type.
     379      Return negative/0/positive depending on whether \c this is
     380      smaller/same/larger than the argument.
     381  */
     382  virtual int compareOriginalObject(const CbcBranchingObject* brObj) const
     383  {
     384    const CbcBranchingObject* br=dynamic_cast<const CbcBranchingObject*>(brObj);
     385    return variable() - br->variable();
     386  }
     387
     388  /** Compare the \c this with \c brObj. \c this and \c brObj must be os the
     389      same type and must have the same original object, but they may have
     390      different feasible regions.
     391      Return the appropriate CbcRangeCompare value (first argument being the
     392      sub/superset if that's the case). In case of overlap (and if \c
     393      replaceIfOverlap is true) replace the current branching object with one
     394      whose feasible region is the overlap.
     395   */
     396  virtual CbcRangeCompare compareBranchingObject
     397  (const CbcBranchingObject* brObj, const bool replaceIfOverlap = false) = 0;
    350398
    351399protected:
     
    555603};
    556604
     605//##############################################################################
     606
     607/** Compare two ranges. The two bounds arrays are both of size two and
     608    describe closed intervals. Return the appropriate CbcRangeCompare value
     609    (first argument being the sub/superset if that's the case). In case of
     610    overlap (and if \c replaceIfOverlap is true) replace the content of thisBd
     611    with the intersection of the ranges.
     612*/
     613static inline CbcRangeCompare
     614CbcCompareRanges(double* thisBd, const double* otherBd,
     615                 const bool replaceIfOverlap)
     616{
     617  const double lbDiff = thisBd[0] - otherBd[0];
     618  if (lbDiff < 0) { // lb of this < lb of other
     619    if (thisBd[1] >= otherBd[1]) { // ub of this >= ub of other
     620      return CbcRangeSuperset;
     621    } else if (thisBd[1] < otherBd[0]) {
     622      return CbcRangeDisjoint;
     623    } else {
     624      // overlap
     625      if (replaceIfOverlap) {
     626        thisBd[0] = otherBd[0];
     627      }
     628      return CbcRangeOverlap;
     629    }
     630  } else if (lbDiff > 0) { // lb of this > lb of other
     631    if (thisBd[1] <= otherBd[1]) { // ub of this <= ub of other
     632      return CbcRangeSubset;
     633    } else if (thisBd[0] > otherBd[1]) {
     634      return CbcRangeDisjoint;
     635    } else {
     636      // overlap
     637      if (replaceIfOverlap) {
     638        thisBd[1] = otherBd[1];
     639      }
     640      return CbcRangeOverlap;
     641    }
     642  } else { // lb of this == lb of other
     643    if (thisBd[1] == otherBd[1]) {
     644      return CbcRangeSame;
     645    }
     646    return thisBd[1] < otherBd[1] ? CbcRangeSubset : CbcRangeSuperset;
     647  }
     648
     649  return CbcRangeSame; // fake return
     650
     651}
     652
     653//#############################################################################
     654
    557655#endif
Note: See TracChangeset for help on using the changeset viewer.