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