Changeset 129


Ignore:
Timestamp:
May 12, 2005 9:33:59 AM (14 years ago)
Author:
forrest
Message:

make createBranch non const

Location:
trunk
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/CbcBranchActual.cpp

    r122 r129  
    214214// Creates a branching object
    215215CbcBranchingObject *
    216 CbcClique::createBranch(int way) const
     216CbcClique::createBranch(int way)
    217217{
    218218  int numberUnsatis=0;
     
    492492// Creates a branching object
    493493CbcBranchingObject *
    494 CbcSOS::createBranch(int way) const
     494CbcSOS::createBranch(int way)
    495495{
    496496  int j;
     
    686686// Creates a branching object
    687687CbcBranchingObject *
    688 CbcSimpleInteger::createBranch(int way) const
     688CbcSimpleInteger::createBranch(int way)
    689689{
    690690  OsiSolverInterface * solver = model_->solver();
     
    918918    olb = model_->solver()->getColLower()[iColumn] ;
    919919    oub = model_->solver()->getColUpper()[iColumn] ;
    920     printf("CbcInteger would branch down on var %d: [%g,%g] => [%g,%g]\n",
    921            iColumn,olb,oub,down_[0],down_[1]) ; }
     920    printf("CbcInteger would branch down on var %d (int var %d): [%g,%g] => [%g,%g]\n",
     921           iColumn,variable_,olb,oub,down_[0],down_[1]) ; }
    922922  } else {
    923923  { double olb,oub ;
    924924    olb = model_->solver()->getColLower()[iColumn] ;
    925925    oub = model_->solver()->getColUpper()[iColumn] ;
    926     printf("CbcInteger would branch up on var %d: [%g,%g] => [%g,%g]\n",
    927            iColumn,olb,oub,up_[0],up_[1]) ; }
     926    printf("CbcInteger would branch up on var %d (int var %d): [%g,%g] => [%g,%g]\n",
     927           iColumn,variable_,olb,oub,up_[0],up_[1]) ; }
    928928  }
    929929}
     
    10101010// Creates a branching object
    10111011CbcBranchingObject *
    1012 CbcSimpleIntegerPseudoCost::createBranch(int way) const
     1012CbcSimpleIntegerPseudoCost::createBranch(int way)
    10131013{
    10141014  OsiSolverInterface * solver = model_->solver();
     
    17321732  :CbcBranchDecision()
    17331733{
     1734  bestCriterion_ = 0.0;
     1735  bestChangeUp_ = 0.0;
     1736  bestNumberUp_ = 0;
     1737  bestChangeDown_ = 0.0;
     1738  bestNumberDown_ = 0;
     1739  bestObject_ = NULL;
    17341740}
    17351741
     
    17391745  :CbcBranchDecision()
    17401746{
     1747  bestCriterion_ = rhs.bestCriterion_;
     1748  bestChangeUp_ = rhs.bestChangeUp_;
     1749  bestNumberUp_ = rhs.bestNumberUp_;
     1750  bestChangeDown_ = rhs.bestChangeDown_;
     1751  bestNumberDown_ = rhs.bestNumberDown_;
     1752  bestObject_ = rhs.bestObject_;
    17411753}
    17421754
     
    17561768CbcBranchDefaultDecision::initialize(CbcModel * model)
    17571769{
     1770  bestCriterion_ = 0.0;
     1771  bestChangeUp_ = 0.0;
     1772  bestNumberUp_ = 0;
     1773  bestChangeDown_ = 0.0;
     1774  bestNumberDown_ = 0;
     1775  bestObject_ = NULL;
    17581776}
    17591777
     
    17721790                            double changeDn, int numInfDn)
    17731791{
    1774   printf("Now obsolete CbcBranchDefaultDecision::betterBranch\n");
    1775   abort();
    1776   return 0;
     1792  bool beforeSolution = thisOne->model()->getSolutionCount()==
     1793    thisOne->model()->getNumberHeuristicSolutions();;
     1794  int betterWay=0;
     1795  if (beforeSolution) {
     1796    if (!bestObject_) {
     1797      bestNumberUp_=INT_MAX;
     1798      bestNumberDown_=INT_MAX;
     1799    }
     1800    // before solution - choose smallest number
     1801    // could add in depth as well
     1802    int bestNumber = CoinMin(bestNumberUp_,bestNumberDown_);
     1803    if (numInfUp<numInfDn) {
     1804      if (numInfUp<bestNumber) {
     1805        betterWay = 1;
     1806      } else if (numInfUp==bestNumber) {
     1807        if (changeUp<bestCriterion_)
     1808          betterWay=1;
     1809      }
     1810    } else if (numInfUp>numInfDn) {
     1811      if (numInfDn<bestNumber) {
     1812        betterWay = -1;
     1813      } else if (numInfDn==bestNumber) {
     1814        if (changeDn<bestCriterion_)
     1815          betterWay=-1;
     1816      }
     1817    } else {
     1818      // up and down have same number
     1819      bool better=false;
     1820      if (numInfUp<bestNumber) {
     1821        better=true;
     1822      } else if (numInfUp==bestNumber) {
     1823        if (min(changeUp,changeDn)<bestCriterion_)
     1824          better=true;;
     1825      }
     1826      if (better) {
     1827        // see which way
     1828        if (changeUp<=changeDn)
     1829          betterWay=1;
     1830        else
     1831          betterWay=-1;
     1832      }
     1833    }
     1834  } else {
     1835    if (!bestObject_) {
     1836      bestCriterion_=-1.0;
     1837    }
     1838    // got a solution
     1839    if (changeUp<=changeDn) {
     1840      if (changeUp>bestCriterion_)
     1841        betterWay=1;
     1842    } else {
     1843      if (changeDn>bestCriterion_)
     1844        betterWay=-1;
     1845    }
     1846  }
     1847  if (betterWay) {
     1848    bestCriterion_ = CoinMin(changeUp,changeDn);
     1849    bestChangeUp_ = changeUp;
     1850    bestNumberUp_ = numInfUp;
     1851    bestChangeDown_ = changeDn;
     1852    bestNumberDown_ = numInfDn;
     1853    bestObject_=thisOne;
     1854  }
     1855  return betterWay;
    17771856}
    17781857
     
    17811860   
    17821861   This routine is used only after strong branching.
    1783    This is reccommended version as it can be more sophisticated
    17841862*/
    17851863
     
    23212399// Creates a branching object
    23222400CbcBranchingObject *
    2323 CbcFollowOn::createBranch(int way) const
     2401CbcFollowOn::createBranch(int way)
    23242402{
    23252403  int otherRow=0;
  • trunk/CbcBranchBase.cpp

    r122 r129  
    140140// Default Constructor
    141141CbcBranchDecision::CbcBranchDecision ()
     142  : object_(NULL)
    142143{
    143144}
     
    145146CbcBranchDecision::~CbcBranchDecision()
    146147{
     148  delete object_;
    147149}
    148150/* Compare N branching objects. Return index of best
  • trunk/CbcBranchCut.cpp

    r37 r129  
    8484// Creates a branching object
    8585CbcBranchingObject *
    86 CbcBranchCut::createBranch(int way) const
     86CbcBranchCut::createBranch(int way)
    8787{
    8888  throw CoinError("Use of base class","createBranch","CbcBranchCut");
  • trunk/CbcBranchLotsize.cpp

    r76 r129  
    520520// Creates a branching object
    521521CbcBranchingObject *
    522 CbcLotsize::createBranch(int way) const
     522CbcLotsize::createBranch(int way)
    523523{
    524524  OsiSolverInterface * solver = model_->solver();
  • trunk/Samples/CbcBranchFollow2.cpp

    r123 r129  
    322322// Creates a branching object
    323323CbcBranchingObject *
    324 CbcFollowOn2::createBranch(int way) const
     324CbcFollowOn2::createBranch(int way)
    325325{
    326326  int otherRow=0;
  • trunk/Samples/CbcBranchFollow2.hpp

    r123 r129  
    5050  virtual void feasibleRegion();
    5151  /// Creates a branching object
    52   virtual CbcBranchingObject * createBranch(int way) const;
     52  virtual CbcBranchingObject * createBranch(int way) ;
    5353  /** As some computation is needed in more than one place - returns row.
    5454      Also returns other row and effective rhs (so we can know if cut)
  • trunk/Samples/CbcBranchLink.cpp

    r121 r129  
    215215// Creates a branching object
    216216CbcBranchingObject *
    217 CbcLink::createBranch(int way) const
     217CbcLink::createBranch(int way)
    218218{
    219219  int j;
  • trunk/Samples/CbcBranchLink.hpp

    r121 r129  
    4646  virtual void feasibleRegion();
    4747  /// Creates a branching object
    48   virtual CbcBranchingObject * createBranch(int way) const;
     48  virtual CbcBranchingObject * createBranch(int way) ;
    4949
    5050  /// Number of members
  • trunk/include/CbcBranchActual.hpp

    r122 r129  
    4343  virtual void feasibleRegion();
    4444  /// Creates a branching object
    45   virtual CbcBranchingObject * createBranch(int way) const;
     45  virtual CbcBranchingObject * createBranch(int way) ;
    4646  /// Number of members
    4747  inline int numberMembers() const
     
    126126  virtual void feasibleRegion();
    127127  /// Creates a branching object
    128   virtual CbcBranchingObject * createBranch(int way) const;
     128  virtual CbcBranchingObject * createBranch(int way) ;
    129129
    130130  /// Number of members
     
    196196
    197197  /// Creates a branching object
    198   virtual CbcBranchingObject * createBranch(int way) const;
     198  virtual CbcBranchingObject * createBranch(int way) ;
    199199
    200200  /** \brief Given a valid solution (with reduced costs, etc.),
     
    376376
    377377  /// Creates a branching object
    378   virtual CbcBranchingObject * createBranch(int way) const;
     378  virtual CbcBranchingObject * createBranch(int way) ;
    379379
    380380  /// Down pseudo cost
     
    673673   
    674674    This routine is used only after strong branching.
    675     This is reccommended version as it can be more sophisticated
    676675  */
    677676
     
    686685  CbcBranchDefaultDecision & operator=(const CbcBranchDefaultDecision& rhs);
    687686
     687  /// data
     688
     689  /// "best" so far
     690  double bestCriterion_;
     691
     692  /// Change up for best
     693  double bestChangeUp_;
     694
     695  /// Number of infeasibilities for up
     696  int bestNumberUp_;
     697
     698  /// Change down for best
     699  double bestChangeDown_;
     700
     701  /// Number of infeasibilities for down
     702  int bestNumberDown_;
     703
     704  /// Pointer to best branching object
     705  CbcBranchingObject * bestObject_;
     706
    688707};
    689708
     
    728747  virtual void feasibleRegion();
    729748  /// Creates a branching object
    730   virtual CbcBranchingObject * createBranch(int way) const;
     749  virtual CbcBranchingObject * createBranch(int way) ;
    731750  /// As some computation is needed in more than one place - returns row
    732751  virtual int gutsOfFollowOn(int & otherRow, int & preferredWay) const;
  • trunk/include/CbcBranchBase.hpp

    r122 r129  
    4040        recoding.
    4141 */
     42// This can be used if object wants to skip strong branching
     43  typedef struct {
     44    CbcBranchingObject * possibleBranch; // what a branch would do
     45    double upMovement; // cost going up (and initial away from feasible)
     46    double downMovement; // cost going down
     47    int numIntInfeasUp ; // without odd ones
     48    int numObjInfeasUp ; // just odd ones
     49    bool finishedUp; // true if solver finished
     50    int numItersUp ; // number of iterations in solver
     51    int numIntInfeasDown ; // without odd ones
     52    int numObjInfeasDown ; // just odd ones
     53    bool finishedDown; // true if solver finished
     54    int numItersDown; // number of iterations in solver
     55    int objectNumber; // Which object it is
     56    int fix; // 0 if no fix, 1 if we can fix up, -1 if we can fix down
     57  } CbcStrongInfo;
    4258
    4359class CbcObject {
     
    89105      variables, etc.)
    90106  */
    91   virtual CbcBranchingObject * createBranch(int way) const = 0;
     107  virtual CbcBranchingObject * createBranch(int way) = 0;
    92108 
    93109  /** \brief Given a valid solution (with reduced costs, etc.),
     
    205221  /// Destructor
    206222  virtual ~CbcBranchingObject ();
    207  
     223
     224  /** Some branchingObjects may claim to be able to skip
     225      strong branching.  If so they ahve to fill in CbcStrongInfo.
     226      The object mention in incoming CbcStrongInfo must match.
     227      Returns nonzero if skip is wanted */
     228  virtual int fillStrongInfo( CbcStrongInfo & info) {return 0;};
    208229  /** The number of branch arms created for this branching object
    209230
     
    336357    If \p bestSoFar is NULL, the routine should return a nonzero value.
    337358    This routine is used only after strong branching.
    338 
    339     It is now reccommended that bestBranch is used - see below.
    340     This has been left for compatibility.
     359    Either this or bestBranch is used depending which user wants.
    341360 */
    342361
     
    350369      and sets way of branching in chosen object.
    351370   
    352     This routine is used only after strong branching.
    353     This is reccommended version as it can be more sophisticated
     371    Either this or betterBranch is used depending which user wants.
    354372  */
    355373
     
    360378              double objectiveValue) ;
    361379
    362 
    363 
     380  /** Says whether this method can handle both methods -
     381      1 better, 2 best, 3 both */
     382  virtual int whichMethod() {return 2;};
     383
     384  /** Saves a clone of current branching object.  Can be used to update
     385      information on object causing branch - after branch */
     386  virtual void saveBranchingObject(CbcBranchingObject * object) {};
     387  /** Pass in information on branch just done.
     388      assumes object can get information from solver */
     389  virtual void updateInformation(OsiSolverInterface * solver) {};
     390
     391protected:
     392 
     393  // Clone of branching object
     394  CbcBranchingObject * object_;
    364395private:
    365  
    366396  /// Assignment is illegal
    367397  CbcBranchDecision & operator=(const CbcBranchDecision& rhs);
  • trunk/include/CbcBranchCut.hpp

    r11 r129  
    5252  virtual bool boundBranch() const ;
    5353  /// Creates a branching object
    54   virtual CbcBranchingObject * createBranch(int way) const;
     54  virtual CbcBranchingObject * createBranch(int way) ;
    5555
    5656  /** \brief Given a valid solution (with reduced costs, etc.),
  • trunk/include/CbcBranchLotsize.hpp

    r74 r129  
    4747
    4848  /// Creates a branching object
    49   virtual CbcBranchingObject * createBranch(int way) const;
     49  virtual CbcBranchingObject * createBranch(int way) ;
    5050
    5151  /** \brief Given a valid solution (with reduced costs, etc.),
Note: See TracChangeset for help on using the changeset viewer.