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

try and keep examples in sync

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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}
Note: See TracChangeset for help on using the changeset viewer.