source: trunk/CbcBranchBase.cpp @ 74

Last change on this file since 74 was 74, checked in by forrest, 17 years ago

adding something to say if object a column

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.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 "CbcModel.hpp"
13#include "CbcMessage.hpp"
14#include "CbcBranchBase.hpp"
15
16
17// Default Constructor
18CbcObject::CbcObject() 
19  :model_(NULL),
20   id_(-1)
21{
22}
23
24// Constructor from model
25CbcObject::CbcObject(CbcModel * model)
26:
27  model_(model),
28  id_(-1)
29{
30}
31
32
33// Destructor
34CbcObject::~CbcObject ()
35{
36}
37
38// Copy constructor
39CbcObject::CbcObject ( const CbcObject & rhs)
40{
41  model_ = rhs.model_;
42  id_ = rhs.id_;
43}
44
45// Assignment operator
46CbcObject & 
47CbcObject::operator=( const CbcObject& rhs)
48{
49  if (this!=&rhs) {
50    model_ = rhs.model_;
51    id_ = rhs.id_;
52  }
53  return *this;
54}
55
56/* Returns floor and ceiling i.e. closest valid points
57 */
58void 
59CbcObject::floorCeiling(double & floorValue, double & ceilingValue, double value,
60                        double tolerance) const
61{
62  if (fabs(floor(value+0.5)-value)>tolerance) {
63    floorValue = floor(value);
64  } else {
65    floorValue = floor(value+0.5);
66  }
67  ceilingValue = floorValue+1.0;
68}
69// Return "up" estimate (default 1.0e-5)
70double 
71CbcObject::upEstimate() const
72{
73  return 1.0e-5;
74}
75// Return "down" estimate (default 1.0e-5)
76double 
77CbcObject::downEstimate() const
78{
79  return 1.0e-5;
80}
81// Column number if single column object -1 otherwise
82int 
83CbcObject::columnNumber() const
84{
85  // Say not as at present only used by heuristics
86  return -1;
87}
88// Default Constructor
89CbcBranchingObject::CbcBranchingObject()
90{
91  model_=NULL;
92  variable_=-1;
93  way_=0;
94  value_=0.0;
95  numberBranchesLeft_=0;
96}
97
98// Useful constructor
99CbcBranchingObject::CbcBranchingObject (CbcModel * model, int variable, int way , double value)
100{
101  model_= model;
102  variable_=variable;
103  way_=way;
104  value_=value;
105  numberBranchesLeft_=2;
106}
107
108// Copy constructor
109CbcBranchingObject::CbcBranchingObject ( const CbcBranchingObject & rhs)
110{
111  model_=rhs.model_;
112  variable_=rhs.variable_;
113  way_=rhs.way_;
114  value_=rhs.value_;
115  numberBranchesLeft_=rhs.numberBranchesLeft_;
116}
117
118// Assignment operator
119CbcBranchingObject & 
120CbcBranchingObject::operator=( const CbcBranchingObject& rhs)
121{
122  if (this != &rhs) {
123    model_=rhs.model_;
124    variable_=rhs.variable_;
125    way_=rhs.way_;
126    value_=rhs.value_;
127    numberBranchesLeft_=rhs.numberBranchesLeft_;
128  }
129  return *this;
130}
131
132// Destructor
133CbcBranchingObject::~CbcBranchingObject ()
134{
135}
136// Default Constructor
137CbcBranchDecision::CbcBranchDecision ()
138{
139}
140
141CbcBranchDecision::~CbcBranchDecision()
142{
143}
144/* Compare N branching objects. Return index of best
145   and sets way of branching in chosen object.
146   
147   This routine is used only after strong branching.
148   This is reccommended version as it can be more sophisticated
149*/
150
151int
152CbcBranchDecision::bestBranch (CbcBranchingObject ** objects, int numberObjects,
153                               int numberUnsatisfied,
154                               double * changeUp, int * numberInfeasibilitiesUp,
155                               double * changeDown, int * numberInfeasibilitiesDown,
156                               double objectiveValue) 
157{
158  int bestWay=0;
159  int whichObject = -1;
160  if (numberObjects) {
161    initialize(objects[0]->model()); 
162    CbcBranchingObject * bestObject = NULL;
163    for (int i = 0 ; i < numberObjects ; i++) {
164      int betterWay = betterBranch(objects[i],
165                                   bestObject,
166                                   changeUp[i],
167                                   numberInfeasibilitiesUp [i],
168                                   changeDown[i],
169                                   numberInfeasibilitiesDown[i] );
170      if (betterWay) {
171        bestObject = objects[i];
172        bestWay = betterWay;
173        whichObject=i;
174      }
175    }
176    // set way in best
177    if (whichObject>=0)
178      objects[whichObject]->way(bestWay);
179    else
180      printf("debug\n");
181  }
182  return whichObject;
183}
184
185 
Note: See TracBrowser for help on using the repository browser.