Ignore:
Timestamp:
Oct 8, 2006 7:34:21 PM (13 years ago)
Author:
forrest
Message:

try and keep examples in sync

Location:
branches/devel/Cbc/examples
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/devel/Cbc/examples/CbcBranchLink.cpp

    r425 r440  
    564564}
    565565double
    566 CbcLinkBranchingObject::branch(bool normalBranch)
    567 {
    568   if (model_->messageHandler()->logLevel()>2&&normalBranch)
    569     print(normalBranch);
    570   numberBranchesLeft_--;
     566CbcLinkBranchingObject::branch()
     567{
     568  decrementNumberBranchesLeft();
    571569  int numberMembers = set_->numberMembers();
    572570  int numberLinks = set_->numberLinks();
     
    614612// Print what would happen 
    615613void
    616 CbcLinkBranchingObject::print(bool normalBranch)
     614CbcLinkBranchingObject::print()
    617615{
    618616  int numberMembers = set_->numberMembers();
  • branches/devel/Cbc/examples/CbcBranchLink.hpp

    r425 r440  
    118118 
    119119  /// Does next branch and updates state
    120   virtual double branch(bool normalBranch=false);
     120  virtual double branch();
    121121
    122122  /** \brief Print something about branch - only if log level high
    123123  */
    124   virtual void print(bool normalBranch);
     124  virtual void print();
    125125private:
    126126  /// data
  • branches/devel/Cbc/examples/CbcBranchLotsizeSimple.cpp

    r403 r440  
    341341*/
    342342double
    343 CbcLotsizeSimpleBranchingObject::branch(bool normalBranch)
    344 {
    345   numberBranchesLeft_--;
     343CbcLotsizeSimpleBranchingObject::branch()
     344{
     345  decrementNumberBranchesLeft();
    346346  int iColumn = variable_;
    347347  if (way_<0) {
  • branches/devel/Cbc/examples/CbcBranchLotsizeSimple.hpp

    r403 r440  
    143143             of the branch and advances the object state to the next arm.
    144144  */
    145   virtual double branch(bool normalBranch=false);
     145  virtual double branch();
    146146
    147147protected:
  • branches/devel/Cbc/examples/CbcBranchUser.cpp

    r2 r440  
    323323  return whichObject;
    324324}
     325/** Default Constructor
     326
     327  Equivalent to an unspecified binary variable.
     328*/
     329CbcSimpleIntegerFixed::CbcSimpleIntegerFixed ()
     330  : CbcSimpleInteger()
     331{
     332}
     333
     334/** Useful constructor
     335
     336  Loads actual upper & lower bounds for the specified variable.
     337*/
     338CbcSimpleIntegerFixed::CbcSimpleIntegerFixed (CbcModel * model,
     339                                    int iColumn, double breakEven)
     340  : CbcSimpleInteger(model,iColumn,breakEven)
     341{
     342}
     343// Constructor from simple
     344CbcSimpleIntegerFixed::CbcSimpleIntegerFixed (const CbcSimpleInteger & rhs)
     345  : CbcSimpleInteger(rhs)
     346{
     347}
     348
     349// Copy constructor
     350CbcSimpleIntegerFixed::CbcSimpleIntegerFixed ( const CbcSimpleIntegerFixed & rhs)
     351  :CbcSimpleInteger(rhs)
     352
     353{
     354}
     355
     356// Clone
     357CbcObject *
     358CbcSimpleIntegerFixed::clone() const
     359{
     360  return new CbcSimpleIntegerFixed(*this);
     361}
     362
     363// Assignment operator
     364CbcSimpleIntegerFixed &
     365CbcSimpleIntegerFixed::operator=( const CbcSimpleIntegerFixed& rhs)
     366{
     367  if (this!=&rhs) {
     368    CbcSimpleInteger::operator=(rhs);
     369  }
     370  return *this;
     371}
     372
     373// Destructor
     374CbcSimpleIntegerFixed::~CbcSimpleIntegerFixed ()
     375{
     376}
     377
     378// Infeasibility - large is 0.5
     379double
     380CbcSimpleIntegerFixed::infeasibility(int & preferredWay) const
     381{
     382  OsiSolverInterface * solver = model_->solver();
     383  const double * solution = model_->testSolution();
     384  const double * lower = solver->getColLower();
     385  const double * upper = solver->getColUpper();
     386  double value = solution[columnNumber_];
     387  value = CoinMax(value, lower[columnNumber_]);
     388  value = CoinMin(value, upper[columnNumber_]);
     389  /*printf("%d %g %g %g %g\n",columnNumber_,value,lower[columnNumber_],
     390    solution[columnNumber_],upper[columnNumber_]);*/
     391  double nearest = floor(value+(1.0-breakEven_));
     392  assert (breakEven_>0.0&&breakEven_<1.0);
     393  double integerTolerance =
     394    model_->getDblParam(CbcModel::CbcIntegerTolerance);
     395  if (nearest>value)
     396    preferredWay=1;
     397  else
     398    preferredWay=-1;
     399  if (preferredWay_)
     400    preferredWay=preferredWay_;
     401  double weight = fabs(value-nearest);
     402  // normalize so weight is 0.5 at break even
     403  if (nearest<value)
     404    weight = (0.5/breakEven_)*weight;
     405  else
     406    weight = (0.5/(1.0-breakEven_))*weight;
     407  if (fabs(value-nearest)<=integerTolerance) {
     408    if (upper[columnNumber_]==lower[columnNumber_])
     409      return 0.0;
     410    else
     411      return 1.0e-5;
     412  } else {
     413    return weight;
     414  }
     415}
     416// Creates a branching object
     417CbcBranchingObject *
     418CbcSimpleIntegerFixed::createBranch(int way)
     419{
     420  OsiSolverInterface * solver = model_->solver();
     421  const double * solution = model_->testSolution();
     422  const double * lower = solver->getColLower();
     423  const double * upper = solver->getColUpper();
     424  double value = solution[columnNumber_];
     425  value = CoinMax(value, lower[columnNumber_]);
     426  value = CoinMin(value, upper[columnNumber_]);
     427  assert (upper[columnNumber_]>lower[columnNumber_]);
     428  if (!model_->hotstartSolution()) {
     429#ifndef NDEBUG
     430    double nearest = floor(value+0.5);
     431    double integerTolerance =
     432    model_->getDblParam(CbcModel::CbcIntegerTolerance);
     433    if (fabs(value-nearest)<integerTolerance) {
     434      // adjust value
     435      if (nearest!=upper[columnNumber_])
     436        value = nearest+2.0*integerTolerance;
     437      else
     438        value = nearest-2.0*integerTolerance;
     439    }
     440#endif
     441  } else {
     442    const double * hotstartSolution = model_->hotstartSolution();
     443    double targetValue = hotstartSolution[columnNumber_];
     444    if (way>0)
     445      value = targetValue-0.1;
     446    else
     447      value = targetValue+0.1;
     448  }
     449  CbcBranchingObject * branch = new CbcIntegerBranchingObject(model_,columnNumber_,way,
     450                                             value);
     451  branch->setOriginalObject(this);
     452  return branch;
     453}
  • branches/devel/Cbc/examples/CbcBranchUser.hpp

    r2 r440  
    55
    66#include "CbcBranchBase.hpp"
     7#include "CbcBranchActual.hpp"
    78
    89/** Branching decision user class */
     
    5556};
    5657
     58/// Define a single integer class where branching is forced until fixed
     59
     60
     61class CbcSimpleIntegerFixed : public CbcSimpleInteger {
     62
     63public:
     64
     65  // Default Constructor
     66  CbcSimpleIntegerFixed ();
     67
     68  // Useful constructor - passed integer index and model index
     69  CbcSimpleIntegerFixed (CbcModel * model, int iColumn, double breakEven=0.5);
     70 
     71  // Constructor from simple
     72  CbcSimpleIntegerFixed (const CbcSimpleInteger & simple);
     73 
     74  // Copy constructor
     75  CbcSimpleIntegerFixed ( const CbcSimpleIntegerFixed &);
     76   
     77  /// Clone
     78  virtual CbcObject * clone() const;
     79
     80  // Assignment operator
     81  CbcSimpleIntegerFixed & operator=( const CbcSimpleIntegerFixed& rhs);
     82
     83  // Destructor
     84  ~CbcSimpleIntegerFixed ();
     85 
     86  /// Infeasibility - large is 0.5
     87  virtual double infeasibility(int & preferredWay) const;
     88
     89  /** Creates a branching object
     90
     91    The preferred direction is set by \p way, -1 for down, +1 for up.
     92  */
     93  virtual CbcBranchingObject * createBranch(int way) ;
     94
     95protected:
     96  /// data
     97};
     98
    5799#endif
Note: See TracChangeset for help on using the changeset viewer.