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

towards common use with other solvers

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/devel/Cbc/src/CbcBranchBase.cpp

    r310 r439  
    1111#include "OsiSolverInterface.hpp"
    1212#include "OsiSolverBranch.hpp"
     13#include "OsiChooseVariable.hpp"
    1314#include "CbcModel.hpp"
    1415#include "CbcMessage.hpp"
     
    1819// Default Constructor
    1920CbcObject::CbcObject()
    20   :model_(NULL),
     21  : OsiObject(),
     22    model_(NULL),
    2123   id_(-1),
    22    priority_(1000),
    2324   preferredWay_(0)
    2425{
     
    2728// Constructor from model
    2829CbcObject::CbcObject(CbcModel * model)
    29 :
    30   model_(model),
    31   id_(-1),
    32   priority_(1000),
    33   preferredWay_(0)
     30  : OsiObject(),
     31    model_(model),
     32    id_(-1),
     33    preferredWay_(0)
    3434{
    3535}
     
    4343// Copy constructor
    4444CbcObject::CbcObject ( const CbcObject & rhs)
     45  : OsiObject(rhs)
    4546{
    4647  model_ = rhs.model_;
    4748  id_ = rhs.id_;
    48   priority_ = rhs.priority_;
    4949  preferredWay_ = rhs.preferredWay_;
    5050}
     
    5555{
    5656  if (this!=&rhs) {
     57    OsiObject::operator=(rhs);
    5758    model_ = rhs.model_;
    5859    id_ = rhs.id_;
    59     priority_ = rhs.priority_;
    6060    preferredWay_ = rhs.preferredWay_;
    6161  }
     
    7676  ceilingValue = floorValue+1.0;
    7777}
    78 // Return "up" estimate (default 1.0e-5)
     78/* Infeasibility of the object
     79     
     80    This is some measure of the infeasibility of the object. 0.0
     81    indicates that the object is satisfied.
     82 
     83    The preferred branching direction is returned in way,
     84 
     85    This is used to prepare for strong branching but should also think of
     86    case when no strong branching
     87 
     88    The object may also compute an estimate of cost of going "up" or "down".
     89    This will probably be based on pseudo-cost ideas
     90
     91    This should also set mutable infeasibility_ and whichWay_
     92    This is for instant re-use for speed
     93*/
    7994double
    80 CbcObject::upEstimate() const
    81 {
    82   return 1.0e-5;
    83 }
    84 // Return "down" estimate (default 1.0e-5)
     95CbcObject::infeasibility(const OsiSolverInterface * solver,int &preferredWay) const
     96{
     97  assert (solver==model_->solver());
     98  return infeasibility(preferredWay);
     99}
     100 
     101/* For the variable(s) referenced by the object,
     102      look at the current solution and set bounds to match the solution.
     103      Returns measure of how much it had to move solution to make feasible
     104*/
    85105double
    86 CbcObject::downEstimate() const
    87 {
    88   return 1.0e-5;
    89 }
    90 // Column number if single column object -1 otherwise
    91 int
    92 CbcObject::columnNumber() const
    93 {
    94   // Say not as at present only used by heuristics
    95   return -1;
     106CbcObject::feasibleRegion(OsiSolverInterface * solver) const
     107{
     108  assert (solver==model_->solver());
     109  CbcObject * fudge = const_cast<CbcObject *>(this);
     110  fudge->feasibleRegion();
     111  return 0.0;
     112}
     113/* Infeasibility of the object
     114     
     115    This is some measure of the infeasibility of the object. 0.0
     116    indicates that the object is satisfied.
     117 
     118    The preferred branching direction is returned in way,
     119 
     120    This is used to prepare for strong branching but should also think of
     121    case when no strong branching
     122 
     123    The object may also compute an estimate of cost of going "up" or "down".
     124    This will probably be based on pseudo-cost ideas
     125
     126    This should also set mutable infeasibility_ and whichWay_
     127    This is for instant re-use for speed
     128*/
     129double
     130CbcObject::infeasibility(const OsiBranchingInformation * info,
     131                         int &preferredWay) const
     132{
     133  return infeasibility(preferredWay);
     134}
     135 
     136/* For the variable(s) referenced by the object,
     137      look at the current solution and set bounds to match the solution.
     138      Returns measure of how much it had to move solution to make feasible
     139*/
     140double
     141CbcObject::feasibleRegion(OsiSolverInterface * solver,const OsiBranchingInformation * info) const
     142{
     143  assert (solver==model_->solver());
     144  CbcObject * fudge = const_cast<CbcObject *>(this);
     145  fudge->feasibleRegion();
     146  return 0.0;
     147}
     148 
     149/* Create a branching object and indicate which way to branch first.
     150     
     151      The branching object has to know how to create branches (fix
     152      variables, etc.)
     153*/
     154OsiBranchingObject *
     155CbcObject::createBranch(OsiSolverInterface * solver, int way) const
     156{
     157  assert (solver==model_->solver());
     158  CbcObject * fudge = const_cast<CbcObject *>(this);
     159  return fudge->createBranch(way);
    96160}
    97161/* Create an OsiSolverBranch object
     
    107171// Default Constructor
    108172CbcBranchingObject::CbcBranchingObject()
     173  : OsiBranchingObject()
    109174{
    110175  model_=NULL;
    111   originalObject_=NULL;
     176  originalCbcObject_=NULL;
    112177  variable_=-1;
    113178  way_=0;
    114   value_=0.0;
    115   numberBranchesLeft_=2;
    116179}
    117180
    118181// Useful constructor
    119182CbcBranchingObject::CbcBranchingObject (CbcModel * model, int variable, int way , double value)
     183  : OsiBranchingObject(model->solver(),value)
    120184{
    121185  model_= model;
    122   originalObject_=NULL;
     186  originalCbcObject_=NULL;
    123187  variable_=variable;
    124188  way_=way;
    125   value_=value;
    126   numberBranchesLeft_=2;
    127189}
    128190
    129191// Copy constructor
    130192CbcBranchingObject::CbcBranchingObject ( const CbcBranchingObject & rhs)
     193  : OsiBranchingObject(rhs)
    131194{
    132195  model_=rhs.model_;
    133   originalObject_=rhs.originalObject_;
     196  originalCbcObject_=rhs.originalCbcObject_;
    134197  variable_=rhs.variable_;
    135198  way_=rhs.way_;
    136199  value_=rhs.value_;
    137   numberBranchesLeft_=rhs.numberBranchesLeft_;
    138200}
    139201
     
    143205{
    144206  if (this != &rhs) {
     207    OsiBranchingObject::operator=(rhs);
    145208    model_=rhs.model_;
    146     originalObject_=rhs.originalObject_;
     209    originalCbcObject_=rhs.originalCbcObject_;
    147210    variable_=rhs.variable_;
    148211    way_=rhs.way_;
    149     value_=rhs.value_;
    150     numberBranchesLeft_=rhs.numberBranchesLeft_;
    151212  }
    152213  return *this;
     
    159220// Default Constructor
    160221CbcBranchDecision::CbcBranchDecision ()
    161   : object_(NULL)
    162 {
     222  : object_(NULL),model_(NULL),chooseMethod_(NULL)
     223{
     224}
     225
     226// Copy Constructor
     227CbcBranchDecision::CbcBranchDecision (const CbcBranchDecision &rhs)
     228  : object_(NULL),model_(rhs.model_),chooseMethod_(NULL)
     229{
     230  if (rhs.chooseMethod_)
     231    chooseMethod_ = rhs.chooseMethod_->clone();
    163232}
    164233
     
    166235{
    167236  delete object_;
     237  delete chooseMethod_;
    168238}
    169239/* Compare N branching objects. Return index of best
     
    205275  return whichObject;
    206276}
    207 
     277// Set (clone) chooseMethod
     278void
     279CbcBranchDecision::setChooseMethod(const OsiChooseVariable & method)
     280{
     281  delete chooseMethod_;
     282  chooseMethod_ = method.clone();
     283}
    208284// Default constructor
    209285CbcConsequence::CbcConsequence()
Note: See TracChangeset for help on using the changeset viewer.