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 |
---|
19 | CbcObject::CbcObject() |
---|
20 | :model_(NULL), |
---|
21 | id_(-1), |
---|
22 | priority_(1000), |
---|
23 | preferredWay_(0) |
---|
24 | { |
---|
25 | } |
---|
26 | |
---|
27 | // Constructor from model |
---|
28 | CbcObject::CbcObject(CbcModel * model) |
---|
29 | : |
---|
30 | model_(model), |
---|
31 | id_(-1), |
---|
32 | priority_(1000), |
---|
33 | preferredWay_(0) |
---|
34 | { |
---|
35 | } |
---|
36 | |
---|
37 | |
---|
38 | // Destructor |
---|
39 | CbcObject::~CbcObject () |
---|
40 | { |
---|
41 | } |
---|
42 | |
---|
43 | // Copy constructor |
---|
44 | CbcObject::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 |
---|
53 | CbcObject & |
---|
54 | CbcObject::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 | */ |
---|
67 | void |
---|
68 | CbcObject::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) |
---|
79 | double |
---|
80 | CbcObject::upEstimate() const |
---|
81 | { |
---|
82 | return 1.0e-5; |
---|
83 | } |
---|
84 | // Return "down" estimate (default 1.0e-5) |
---|
85 | double |
---|
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; |
---|
96 | } |
---|
97 | /* Create an OsiSolverBranch object |
---|
98 | |
---|
99 | This returns NULL if branch not represented by bound changes |
---|
100 | */ |
---|
101 | OsiSolverBranch * |
---|
102 | CbcObject::solverBranch() const |
---|
103 | { |
---|
104 | return NULL; |
---|
105 | } |
---|
106 | |
---|
107 | // Default Constructor |
---|
108 | CbcBranchingObject::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 |
---|
119 | CbcBranchingObject::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 |
---|
130 | CbcBranchingObject::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 |
---|
141 | CbcBranchingObject & |
---|
142 | CbcBranchingObject::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 |
---|
156 | CbcBranchingObject::~CbcBranchingObject () |
---|
157 | { |
---|
158 | } |
---|
159 | // Default Constructor |
---|
160 | CbcBranchDecision::CbcBranchDecision () |
---|
161 | : object_(NULL) |
---|
162 | { |
---|
163 | } |
---|
164 | |
---|
165 | CbcBranchDecision::~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 | |
---|
176 | int |
---|
177 | CbcBranchDecision::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 |
---|
209 | CbcConsequence::CbcConsequence() |
---|
210 | { |
---|
211 | } |
---|
212 | |
---|
213 | |
---|
214 | // Destructor |
---|
215 | CbcConsequence::~CbcConsequence () |
---|
216 | { |
---|
217 | } |
---|
218 | |
---|
219 | // Copy constructor |
---|
220 | CbcConsequence::CbcConsequence ( const CbcConsequence & rhs) |
---|
221 | { |
---|
222 | } |
---|
223 | |
---|
224 | // Assignment operator |
---|
225 | CbcConsequence & |
---|
226 | CbcConsequence::operator=( const CbcConsequence& rhs) |
---|
227 | { |
---|
228 | if (this!=&rhs) { |
---|
229 | } |
---|
230 | return *this; |
---|
231 | } |
---|
232 | |
---|
233 | |
---|