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

Last change on this file since 424 was 310, checked in by andreasw, 14 years ago

first commit for autotools conversion to be able to move more files

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.6 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 "CbcModel.hpp"
14#include "CbcMessage.hpp"
15#include "CbcBranchBase.hpp"
16
17
18// Default Constructor
19CbcObject::CbcObject() 
20  :model_(NULL),
21   id_(-1),
22   priority_(1000),
23   preferredWay_(0)
24{
25}
26
27// Constructor from model
28CbcObject::CbcObject(CbcModel * model)
29:
30  model_(model),
31  id_(-1),
32  priority_(1000),
33  preferredWay_(0)
34{
35}
36
37
38// Destructor
39CbcObject::~CbcObject ()
40{
41}
42
43// Copy constructor
44CbcObject::CbcObject ( const CbcObject & rhs)
45{
46  model_ = rhs.model_;
47  id_ = rhs.id_;
48  priority_ = rhs.priority_;
49  preferredWay_ = rhs.preferredWay_;
50}
51
52// Assignment operator
53CbcObject & 
54CbcObject::operator=( const CbcObject& rhs)
55{
56  if (this!=&rhs) {
57    model_ = rhs.model_;
58    id_ = rhs.id_;
59    priority_ = rhs.priority_;
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// Return "up" estimate (default 1.0e-5)
79double 
80CbcObject::upEstimate() const
81{
82  return 1.0e-5;
83}
84// Return "down" estimate (default 1.0e-5)
85double 
86CbcObject::downEstimate() const
87{
88  return 1.0e-5;
89}
90// Column number if single column object -1 otherwise
91int 
92CbcObject::columnNumber() const
93{
94  // Say not as at present only used by heuristics
95  return -1;
96}
97/* Create an OsiSolverBranch object
98   
99This returns NULL if branch not represented by bound changes
100*/
101OsiSolverBranch * 
102CbcObject::solverBranch() const
103{
104  return NULL;
105}
106 
107// Default Constructor
108CbcBranchingObject::CbcBranchingObject()
109{
110  model_=NULL;
111  originalObject_=NULL;
112  variable_=-1;
113  way_=0;
114  value_=0.0;
115  numberBranchesLeft_=2;
116}
117
118// Useful constructor
119CbcBranchingObject::CbcBranchingObject (CbcModel * model, int variable, int way , double value)
120{
121  model_= model;
122  originalObject_=NULL;
123  variable_=variable;
124  way_=way;
125  value_=value;
126  numberBranchesLeft_=2;
127}
128
129// Copy constructor
130CbcBranchingObject::CbcBranchingObject ( const CbcBranchingObject & rhs)
131{
132  model_=rhs.model_;
133  originalObject_=rhs.originalObject_;
134  variable_=rhs.variable_;
135  way_=rhs.way_;
136  value_=rhs.value_;
137  numberBranchesLeft_=rhs.numberBranchesLeft_;
138}
139
140// Assignment operator
141CbcBranchingObject & 
142CbcBranchingObject::operator=( const CbcBranchingObject& rhs)
143{
144  if (this != &rhs) {
145    model_=rhs.model_;
146    originalObject_=rhs.originalObject_;
147    variable_=rhs.variable_;
148    way_=rhs.way_;
149    value_=rhs.value_;
150    numberBranchesLeft_=rhs.numberBranchesLeft_;
151  }
152  return *this;
153}
154
155// Destructor
156CbcBranchingObject::~CbcBranchingObject ()
157{
158}
159// Default Constructor
160CbcBranchDecision::CbcBranchDecision ()
161  : object_(NULL)
162{
163}
164
165CbcBranchDecision::~CbcBranchDecision()
166{
167  delete object_;
168}
169/* Compare N branching objects. Return index of best
170   and sets way of branching in chosen object.
171   
172   This routine is used only after strong branching.
173   This is reccommended version as it can be more sophisticated
174*/
175
176int
177CbcBranchDecision::bestBranch (CbcBranchingObject ** objects, int numberObjects,
178                               int numberUnsatisfied,
179                               double * changeUp, int * numberInfeasibilitiesUp,
180                               double * changeDown, int * numberInfeasibilitiesDown,
181                               double objectiveValue) 
182{
183  int bestWay=0;
184  int whichObject = -1;
185  if (numberObjects) {
186    initialize(objects[0]->model()); 
187    CbcBranchingObject * bestObject = NULL;
188    for (int i = 0 ; i < numberObjects ; i++) {
189      int betterWay = betterBranch(objects[i],
190                                   bestObject,
191                                   changeUp[i],
192                                   numberInfeasibilitiesUp [i],
193                                   changeDown[i],
194                                   numberInfeasibilitiesDown[i] );
195      if (betterWay) {
196        bestObject = objects[i];
197        bestWay = betterWay;
198        whichObject=i;
199      }
200    }
201    // set way in best
202    if (whichObject>=0) 
203      objects[whichObject]->way(bestWay);
204  }
205  return whichObject;
206}
207
208// Default constructor
209CbcConsequence::CbcConsequence()
210{
211}
212
213
214// Destructor
215CbcConsequence::~CbcConsequence ()
216{
217}
218
219// Copy constructor
220CbcConsequence::CbcConsequence ( const CbcConsequence & rhs)
221{
222}
223
224// Assignment operator
225CbcConsequence & 
226CbcConsequence::operator=( const CbcConsequence& rhs)
227{
228  if (this!=&rhs) {
229  }
230  return *this;
231}
232
233 
Note: See TracBrowser for help on using the repository browser.