source: branches/devel/Cbc/src/CbcBranchBase.cpp @ 464

Last change on this file since 464 was 445, checked in by forrest, 13 years ago

for OsiSOS and add more stats to cut generators

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.7 KB
Line 
1// Copyright (C) 2002, International Business Machines
2// Corporation and others.  All Rights Reserved.
3#if defined(_MSC_VER)
4// Turn off compiler warning about long names
5#  pragma warning(disable:4786)
6#endif
7#include <cassert>
8#include <cmath>
9#include <cfloat>
10
11#include "OsiSolverInterface.hpp"
12#include "OsiSolverBranch.hpp"
13#include "OsiChooseVariable.hpp"
14#include "CbcModel.hpp"
15#include "CbcMessage.hpp"
16#include "CbcBranchBase.hpp"
17
18
19// Default Constructor
20CbcObject::CbcObject() 
21  : OsiObject(),
22    model_(NULL),
23   id_(-1),
24   preferredWay_(0)
25{
26}
27
28// Constructor from model
29CbcObject::CbcObject(CbcModel * model)
30  : OsiObject(),
31    model_(model),
32    id_(-1),
33    preferredWay_(0)
34{
35}
36
37
38// Destructor
39CbcObject::~CbcObject ()
40{
41}
42
43// Copy constructor
44CbcObject::CbcObject ( const CbcObject & rhs)
45  : OsiObject(rhs)
46{
47  model_ = rhs.model_;
48  id_ = rhs.id_;
49  preferredWay_ = rhs.preferredWay_;
50}
51
52// Assignment operator
53CbcObject & 
54CbcObject::operator=( const CbcObject& rhs)
55{
56  if (this!=&rhs) {
57    OsiObject::operator=(rhs);
58    model_ = rhs.model_;
59    id_ = rhs.id_;
60    preferredWay_ = rhs.preferredWay_;
61  }
62  return *this;
63}
64
65/* Returns floor and ceiling i.e. closest valid points
66 */
67void 
68CbcObject::floorCeiling(double & floorValue, double & ceilingValue, double value,
69                        double tolerance) const
70{
71  if (fabs(floor(value+0.5)-value)>tolerance) {
72    floorValue = floor(value);
73  } else {
74    floorValue = floor(value+0.5);
75  }
76  ceilingValue = floorValue+1.0;
77}
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*/
94double 
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*/
105double 
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);
160}
161/* Create a branching object and indicate which way to branch first.
162     
163      The branching object has to know how to create branches (fix
164      variables, etc.)
165*/
166OsiBranchingObject * 
167CbcObject::createBranch(OsiSolverInterface * solver,const OsiBranchingInformation * info, int way) const 
168{
169  assert (solver==model_->solver());
170  CbcObject * fudge = const_cast<CbcObject *>(this);
171  return fudge->createBranch(way);
172}
173/* Create an OsiSolverBranch object
174   
175This returns NULL if branch not represented by bound changes
176*/
177OsiSolverBranch * 
178CbcObject::solverBranch() const
179{
180  return NULL;
181}
182 
183// Default Constructor
184CbcBranchingObject::CbcBranchingObject()
185  : OsiBranchingObject()
186{
187  model_=NULL;
188  originalCbcObject_=NULL;
189  variable_=-1;
190  way_=0;
191}
192
193// Useful constructor
194CbcBranchingObject::CbcBranchingObject (CbcModel * model, int variable, int way , double value)
195  : OsiBranchingObject(model->solver(),value)
196{
197  model_= model;
198  originalCbcObject_=NULL;
199  variable_=variable;
200  way_=way;
201}
202
203// Copy constructor
204CbcBranchingObject::CbcBranchingObject ( const CbcBranchingObject & rhs)
205  : OsiBranchingObject(rhs)
206{
207  model_=rhs.model_;
208  originalCbcObject_=rhs.originalCbcObject_;
209  variable_=rhs.variable_;
210  way_=rhs.way_;
211  value_=rhs.value_;
212}
213
214// Assignment operator
215CbcBranchingObject & 
216CbcBranchingObject::operator=( const CbcBranchingObject& rhs)
217{
218  if (this != &rhs) {
219    OsiBranchingObject::operator=(rhs);
220    model_=rhs.model_;
221    originalCbcObject_=rhs.originalCbcObject_;
222    variable_=rhs.variable_;
223    way_=rhs.way_;
224  }
225  return *this;
226}
227
228// Destructor
229CbcBranchingObject::~CbcBranchingObject ()
230{
231}
232// Default Constructor
233CbcBranchDecision::CbcBranchDecision ()
234  : object_(NULL),model_(NULL),chooseMethod_(NULL)
235{
236}
237
238// Copy Constructor
239CbcBranchDecision::CbcBranchDecision (const CbcBranchDecision &rhs)
240  : object_(NULL),model_(rhs.model_),chooseMethod_(NULL)
241{
242  if (rhs.chooseMethod_)
243    chooseMethod_ = rhs.chooseMethod_->clone();
244}
245
246CbcBranchDecision::~CbcBranchDecision()
247{
248  delete object_;
249  delete chooseMethod_;
250}
251/* Compare N branching objects. Return index of best
252   and sets way of branching in chosen object.
253   
254   This routine is used only after strong branching.
255   This is reccommended version as it can be more sophisticated
256*/
257
258int
259CbcBranchDecision::bestBranch (CbcBranchingObject ** objects, int numberObjects,
260                               int numberUnsatisfied,
261                               double * changeUp, int * numberInfeasibilitiesUp,
262                               double * changeDown, int * numberInfeasibilitiesDown,
263                               double objectiveValue) 
264{
265  int bestWay=0;
266  int whichObject = -1;
267  if (numberObjects) {
268    initialize(objects[0]->model()); 
269    CbcBranchingObject * bestObject = NULL;
270    for (int i = 0 ; i < numberObjects ; i++) {
271      int betterWay = betterBranch(objects[i],
272                                   bestObject,
273                                   changeUp[i],
274                                   numberInfeasibilitiesUp [i],
275                                   changeDown[i],
276                                   numberInfeasibilitiesDown[i] );
277      if (betterWay) {
278        bestObject = objects[i];
279        bestWay = betterWay;
280        whichObject=i;
281      }
282    }
283    // set way in best
284    if (whichObject>=0) 
285      objects[whichObject]->way(bestWay);
286  }
287  return whichObject;
288}
289// Set (clone) chooseMethod
290void 
291CbcBranchDecision::setChooseMethod(const OsiChooseVariable & method)
292{ 
293  delete chooseMethod_;
294  chooseMethod_ = method.clone();
295}
296// Default constructor
297CbcConsequence::CbcConsequence()
298{
299}
300
301
302// Destructor
303CbcConsequence::~CbcConsequence ()
304{
305}
306
307// Copy constructor
308CbcConsequence::CbcConsequence ( const CbcConsequence & rhs)
309{
310}
311
312// Assignment operator
313CbcConsequence & 
314CbcConsequence::operator=( const CbcConsequence& rhs)
315{
316  if (this!=&rhs) {
317  }
318  return *this;
319}
320
321 
Note: See TracBrowser for help on using the repository browser.