1 | // Copyright (C) 2006, International Business Machines |
---|
2 | // Corporation and others. All Rights Reserved. |
---|
3 | #ifndef OsiBranchLink_H |
---|
4 | #define OsiBranchLink_H |
---|
5 | |
---|
6 | #include "OsiBranchingObject.hpp" |
---|
7 | |
---|
8 | /** Define Special Linked Ordered Sets. |
---|
9 | |
---|
10 | */ |
---|
11 | class CoinWarmStartBasis; |
---|
12 | |
---|
13 | class OsiOldLink : public OsiSOS { |
---|
14 | |
---|
15 | public: |
---|
16 | |
---|
17 | // Default Constructor |
---|
18 | OsiOldLink (); |
---|
19 | |
---|
20 | /** Useful constructor - A valid solution is if all variables are zero |
---|
21 | apart from k*numberLink to (k+1)*numberLink-1 where k is 0 through |
---|
22 | numberInSet-1. The length of weights array is numberInSet. |
---|
23 | For this constructor the variables in matrix are the numberInSet*numberLink |
---|
24 | starting at first. If weights null then 0,1,2.. |
---|
25 | */ |
---|
26 | OsiOldLink (const OsiSolverInterface * solver, int numberMembers, |
---|
27 | int numberLinks, int first, |
---|
28 | const double * weights, int setNumber); |
---|
29 | /** Useful constructor - A valid solution is if all variables are zero |
---|
30 | apart from k*numberLink to (k+1)*numberLink-1 where k is 0 through |
---|
31 | numberInSet-1. The length of weights array is numberInSet. |
---|
32 | For this constructor the variables are given by list - grouped. |
---|
33 | If weights null then 0,1,2.. |
---|
34 | */ |
---|
35 | OsiOldLink (const OsiSolverInterface * solver, int numberMembers, |
---|
36 | int numberLinks, int typeSOS, const int * which, |
---|
37 | const double * weights, int setNumber); |
---|
38 | |
---|
39 | // Copy constructor |
---|
40 | OsiOldLink ( const OsiOldLink &); |
---|
41 | |
---|
42 | /// Clone |
---|
43 | virtual OsiObject * clone() const; |
---|
44 | |
---|
45 | // Assignment operator |
---|
46 | OsiOldLink & operator=( const OsiOldLink& rhs); |
---|
47 | |
---|
48 | // Destructor |
---|
49 | virtual ~OsiOldLink (); |
---|
50 | |
---|
51 | /// Infeasibility - large is 0.5 |
---|
52 | virtual double infeasibility(const OsiBranchingInformation * info,int & whichWay) const; |
---|
53 | |
---|
54 | /** Set bounds to fix the variable at the current (integer) value. |
---|
55 | |
---|
56 | Given an integer value, set the lower and upper bounds to fix the |
---|
57 | variable. Returns amount it had to move variable. |
---|
58 | */ |
---|
59 | virtual double feasibleRegion(OsiSolverInterface * solver, const OsiBranchingInformation * info) const; |
---|
60 | |
---|
61 | /** Creates a branching object |
---|
62 | |
---|
63 | The preferred direction is set by \p way, 0 for down, 1 for up. |
---|
64 | */ |
---|
65 | virtual OsiBranchingObject * createBranch(OsiSolverInterface * solver, const OsiBranchingInformation * info, int way) const; |
---|
66 | |
---|
67 | /// Redoes data when sequence numbers change |
---|
68 | virtual void resetSequenceEtc(int numberColumns, const int * originalColumns); |
---|
69 | |
---|
70 | /// Number of links for each member |
---|
71 | inline int numberLinks() const |
---|
72 | {return numberLinks_;}; |
---|
73 | |
---|
74 | /** \brief Return true if object can take part in normal heuristics |
---|
75 | */ |
---|
76 | virtual bool canDoHeuristics() const |
---|
77 | {return false;}; |
---|
78 | /** \brief Return true if branch should only bound variables |
---|
79 | */ |
---|
80 | virtual bool boundBranch() const |
---|
81 | {return false;}; |
---|
82 | |
---|
83 | private: |
---|
84 | /// data |
---|
85 | |
---|
86 | /// Number of links |
---|
87 | int numberLinks_; |
---|
88 | }; |
---|
89 | /** Branching object for Linked ordered sets |
---|
90 | |
---|
91 | */ |
---|
92 | class OsiOldLinkBranchingObject : public OsiSOSBranchingObject { |
---|
93 | |
---|
94 | public: |
---|
95 | |
---|
96 | // Default Constructor |
---|
97 | OsiOldLinkBranchingObject (); |
---|
98 | |
---|
99 | // Useful constructor |
---|
100 | OsiOldLinkBranchingObject (OsiSolverInterface * solver, const OsiOldLink * originalObject, |
---|
101 | int way, |
---|
102 | double separator); |
---|
103 | |
---|
104 | // Copy constructor |
---|
105 | OsiOldLinkBranchingObject ( const OsiOldLinkBranchingObject &); |
---|
106 | |
---|
107 | // Assignment operator |
---|
108 | OsiOldLinkBranchingObject & operator=( const OsiOldLinkBranchingObject& rhs); |
---|
109 | |
---|
110 | /// Clone |
---|
111 | virtual OsiBranchingObject * clone() const; |
---|
112 | |
---|
113 | // Destructor |
---|
114 | virtual ~OsiOldLinkBranchingObject (); |
---|
115 | |
---|
116 | /// Does next branch and updates state |
---|
117 | virtual double branch(OsiSolverInterface * solver); |
---|
118 | |
---|
119 | /** \brief Print something about branch - only if log level high |
---|
120 | */ |
---|
121 | virtual void print(const OsiSolverInterface * solver=NULL); |
---|
122 | private: |
---|
123 | /// data |
---|
124 | }; |
---|
125 | /** Define data for one link |
---|
126 | |
---|
127 | */ |
---|
128 | |
---|
129 | |
---|
130 | class OsiOneLink { |
---|
131 | |
---|
132 | public: |
---|
133 | |
---|
134 | // Default Constructor |
---|
135 | OsiOneLink (); |
---|
136 | |
---|
137 | /** Useful constructor - |
---|
138 | |
---|
139 | */ |
---|
140 | OsiOneLink (const OsiSolverInterface * solver, int xRow, int xColumn, int xyRow, |
---|
141 | const char * functionString); |
---|
142 | |
---|
143 | // Copy constructor |
---|
144 | OsiOneLink ( const OsiOneLink &); |
---|
145 | |
---|
146 | // Assignment operator |
---|
147 | OsiOneLink & operator=( const OsiOneLink& rhs); |
---|
148 | |
---|
149 | // Destructor |
---|
150 | virtual ~OsiOneLink (); |
---|
151 | |
---|
152 | /// data |
---|
153 | |
---|
154 | /// Row which defines x (if -1 then no x) |
---|
155 | int xRow_; |
---|
156 | /// Column which defines x |
---|
157 | int xColumn_; |
---|
158 | /// Output row |
---|
159 | int xyRow; |
---|
160 | /// Function |
---|
161 | std::string function_; |
---|
162 | }; |
---|
163 | /** Define Special Linked Ordered Sets. New style |
---|
164 | |
---|
165 | members and weights may be stored in SOS object |
---|
166 | |
---|
167 | This is for y and x*f(y) and z*g(y) etc |
---|
168 | |
---|
169 | */ |
---|
170 | |
---|
171 | |
---|
172 | class OsiLink : public OsiSOS { |
---|
173 | |
---|
174 | public: |
---|
175 | |
---|
176 | // Default Constructor |
---|
177 | OsiLink (); |
---|
178 | |
---|
179 | /** Useful constructor - |
---|
180 | |
---|
181 | */ |
---|
182 | OsiLink (const OsiSolverInterface * solver, int yRow, |
---|
183 | int yColumn, double meshSize); |
---|
184 | |
---|
185 | // Copy constructor |
---|
186 | OsiLink ( const OsiLink &); |
---|
187 | |
---|
188 | /// Clone |
---|
189 | virtual OsiObject * clone() const; |
---|
190 | |
---|
191 | // Assignment operator |
---|
192 | OsiLink & operator=( const OsiLink& rhs); |
---|
193 | |
---|
194 | // Destructor |
---|
195 | virtual ~OsiLink (); |
---|
196 | |
---|
197 | /// Infeasibility - large is 0.5 |
---|
198 | virtual double infeasibility(const OsiBranchingInformation * info,int & whichWay) const; |
---|
199 | |
---|
200 | /** Set bounds to fix the variable at the current (integer) value. |
---|
201 | |
---|
202 | Given an integer value, set the lower and upper bounds to fix the |
---|
203 | variable. Returns amount it had to move variable. |
---|
204 | */ |
---|
205 | virtual double feasibleRegion(OsiSolverInterface * solver, const OsiBranchingInformation * info) const; |
---|
206 | |
---|
207 | /** Creates a branching object |
---|
208 | |
---|
209 | The preferred direction is set by \p way, 0 for down, 1 for up. |
---|
210 | */ |
---|
211 | virtual OsiBranchingObject * createBranch(OsiSolverInterface * solver, const OsiBranchingInformation * info, int way) const; |
---|
212 | |
---|
213 | /// Redoes data when sequence numbers change |
---|
214 | virtual void resetSequenceEtc(int numberColumns, const int * originalColumns); |
---|
215 | |
---|
216 | /// Number of links for each member |
---|
217 | inline int numberLinks() const |
---|
218 | {return numberLinks_;}; |
---|
219 | |
---|
220 | /** \brief Return true if object can take part in normal heuristics |
---|
221 | */ |
---|
222 | virtual bool canDoHeuristics() const |
---|
223 | {return false;}; |
---|
224 | /** \brief Return true if branch should only bound variables |
---|
225 | */ |
---|
226 | virtual bool boundBranch() const |
---|
227 | {return false;}; |
---|
228 | |
---|
229 | private: |
---|
230 | /// data |
---|
231 | /// Current increment for y points |
---|
232 | double meshSize_; |
---|
233 | /// Links |
---|
234 | OsiOneLink * data_; |
---|
235 | /// Number of links |
---|
236 | int numberLinks_; |
---|
237 | /// Row which defines y |
---|
238 | int yRow_; |
---|
239 | /// Column which defines y |
---|
240 | int yColumn_; |
---|
241 | }; |
---|
242 | /** Branching object for Linked ordered sets |
---|
243 | |
---|
244 | */ |
---|
245 | class OsiLinkBranchingObject : public OsiTwoWayBranchingObject { |
---|
246 | |
---|
247 | public: |
---|
248 | |
---|
249 | // Default Constructor |
---|
250 | OsiLinkBranchingObject (); |
---|
251 | |
---|
252 | // Useful constructor |
---|
253 | OsiLinkBranchingObject (OsiSolverInterface * solver, const OsiLink * originalObject, |
---|
254 | int way, |
---|
255 | double separator); |
---|
256 | |
---|
257 | // Copy constructor |
---|
258 | OsiLinkBranchingObject ( const OsiLinkBranchingObject &); |
---|
259 | |
---|
260 | // Assignment operator |
---|
261 | OsiLinkBranchingObject & operator=( const OsiLinkBranchingObject& rhs); |
---|
262 | |
---|
263 | /// Clone |
---|
264 | virtual OsiBranchingObject * clone() const; |
---|
265 | |
---|
266 | // Destructor |
---|
267 | virtual ~OsiLinkBranchingObject (); |
---|
268 | |
---|
269 | /// Does next branch and updates state |
---|
270 | virtual double branch(OsiSolverInterface * solver); |
---|
271 | |
---|
272 | /** \brief Print something about branch - only if log level high |
---|
273 | */ |
---|
274 | virtual void print(const OsiSolverInterface * solver=NULL); |
---|
275 | private: |
---|
276 | /// data |
---|
277 | }; |
---|
278 | /** Define BiLinear objects |
---|
279 | |
---|
280 | This models x*y where one or both are integer |
---|
281 | |
---|
282 | */ |
---|
283 | |
---|
284 | |
---|
285 | class OsiBiLinear : public OsiObject2 { |
---|
286 | |
---|
287 | public: |
---|
288 | |
---|
289 | // Default Constructor |
---|
290 | OsiBiLinear (); |
---|
291 | |
---|
292 | /** Useful constructor - |
---|
293 | This Adds in rows and variables to construct valid Linked Ordered Set |
---|
294 | Adds extra constraints to match other x/y |
---|
295 | So note not const solver |
---|
296 | */ |
---|
297 | OsiBiLinear (OsiSolverInterface * solver, int xColumn, |
---|
298 | int yColumn, int xyRow, double coefficient, |
---|
299 | double xMesh, double yMesh, |
---|
300 | int numberExistingObjects=0,const OsiObject ** objects=NULL ); |
---|
301 | |
---|
302 | // Copy constructor |
---|
303 | OsiBiLinear ( const OsiBiLinear &); |
---|
304 | |
---|
305 | /// Clone |
---|
306 | virtual OsiObject * clone() const; |
---|
307 | |
---|
308 | // Assignment operator |
---|
309 | OsiBiLinear & operator=( const OsiBiLinear& rhs); |
---|
310 | |
---|
311 | // Destructor |
---|
312 | virtual ~OsiBiLinear (); |
---|
313 | |
---|
314 | /// Infeasibility - large is 0.5 |
---|
315 | virtual double infeasibility(const OsiBranchingInformation * info,int & whichWay) const; |
---|
316 | |
---|
317 | /** Set bounds to fix the variable at the current (integer) value. |
---|
318 | |
---|
319 | Given an integer value, set the lower and upper bounds to fix the |
---|
320 | variable. Returns amount it had to move variable. |
---|
321 | */ |
---|
322 | virtual double feasibleRegion(OsiSolverInterface * solver, const OsiBranchingInformation * info) const; |
---|
323 | |
---|
324 | /** Creates a branching object |
---|
325 | |
---|
326 | The preferred direction is set by \p way, 0 for down, 1 for up. |
---|
327 | */ |
---|
328 | virtual OsiBranchingObject * createBranch(OsiSolverInterface * solver, const OsiBranchingInformation * info, int way) const; |
---|
329 | |
---|
330 | /// Redoes data when sequence numbers change |
---|
331 | virtual void resetSequenceEtc(int numberColumns, const int * originalColumns); |
---|
332 | |
---|
333 | // This does NOT set mutable stuff |
---|
334 | virtual double checkInfeasibility(const OsiBranchingInformation * info) const; |
---|
335 | |
---|
336 | /** \brief Return true if object can take part in normal heuristics |
---|
337 | */ |
---|
338 | virtual bool canDoHeuristics() const |
---|
339 | {return false;}; |
---|
340 | /** \brief Return true if branch should only bound variables |
---|
341 | */ |
---|
342 | virtual bool boundBranch() const |
---|
343 | { return false;}; |
---|
344 | /// X column |
---|
345 | inline int xColumn() const |
---|
346 | { return xColumn_;}; |
---|
347 | /// Y column |
---|
348 | inline int yColumn() const |
---|
349 | { return yColumn_;}; |
---|
350 | /// X satisfied if less than this away from mesh |
---|
351 | inline double xSatisfied() const |
---|
352 | { return xSatisfied_;}; |
---|
353 | inline void setXSatisfied(double value) |
---|
354 | { xSatisfied_=value;}; |
---|
355 | /// Y satisfied if less than this away from mesh |
---|
356 | inline double ySatisfied() const |
---|
357 | { return ySatisfied_;}; |
---|
358 | inline void setYSatisfied(double value) |
---|
359 | { ySatisfied_=value;}; |
---|
360 | /// XY satisfied if two version differ by less than this |
---|
361 | inline double xySatisfied() const |
---|
362 | { return xySatisfied_;}; |
---|
363 | inline void setXYSatisfied(double value) |
---|
364 | { xySatisfied_=value;}; |
---|
365 | /// 0 branch on either, 1 branch on x, 2 branch on y |
---|
366 | inline int branchingStrategy() const |
---|
367 | { return branchingStrategy_;}; |
---|
368 | inline void setBranchingStrategy(int value) |
---|
369 | { branchingStrategy_=value;}; |
---|
370 | /// Does work of branching |
---|
371 | void newBounds(OsiSolverInterface * solver, int way, short xOrY, double separator) const; |
---|
372 | /// Updates coefficients |
---|
373 | void updateCoefficients(const double * lower, const double * upper, |
---|
374 | CoinPackedMatrix * matrix, CoinWarmStartBasis * basis) const; |
---|
375 | |
---|
376 | |
---|
377 | private: |
---|
378 | /// data |
---|
379 | |
---|
380 | /// Coefficient |
---|
381 | double coefficient_; |
---|
382 | /// x mesh |
---|
383 | double xMeshSize_; |
---|
384 | /// y mesh |
---|
385 | double yMeshSize_; |
---|
386 | /// x satisfied if less than this away from mesh |
---|
387 | double xSatisfied_; |
---|
388 | /// y satisfied if less than this away from mesh |
---|
389 | double ySatisfied_; |
---|
390 | /// xy satisfied if less than this away from true |
---|
391 | double xySatisfied_; |
---|
392 | /// value of x or y to branch about |
---|
393 | mutable double xyBranchValue_; |
---|
394 | /// x column |
---|
395 | int xColumn_; |
---|
396 | /// y column |
---|
397 | int yColumn_; |
---|
398 | /// First lambda (of 4) |
---|
399 | int firstLambda_; |
---|
400 | /// 0 branch on either, 1 branch on x, 2 branch on y |
---|
401 | int branchingStrategy_; |
---|
402 | /// x row |
---|
403 | int xRow_; |
---|
404 | /// y row (-1 if x*x) |
---|
405 | int yRow_; |
---|
406 | /// Output row |
---|
407 | int xyRow_; |
---|
408 | /// Convexity row |
---|
409 | int convexity_; |
---|
410 | /// Which chosen -1 none, 0 x, 1 y |
---|
411 | mutable short chosen_; |
---|
412 | }; |
---|
413 | /** Branching object for BiLinear objects |
---|
414 | |
---|
415 | */ |
---|
416 | class OsiBiLinearBranchingObject : public OsiTwoWayBranchingObject { |
---|
417 | |
---|
418 | public: |
---|
419 | |
---|
420 | // Default Constructor |
---|
421 | OsiBiLinearBranchingObject (); |
---|
422 | |
---|
423 | // Useful constructor |
---|
424 | OsiBiLinearBranchingObject (OsiSolverInterface * solver, const OsiBiLinear * originalObject, |
---|
425 | int way, |
---|
426 | double separator, int chosen); |
---|
427 | |
---|
428 | // Copy constructor |
---|
429 | OsiBiLinearBranchingObject ( const OsiBiLinearBranchingObject &); |
---|
430 | |
---|
431 | // Assignment operator |
---|
432 | OsiBiLinearBranchingObject & operator=( const OsiBiLinearBranchingObject& rhs); |
---|
433 | |
---|
434 | /// Clone |
---|
435 | virtual OsiBranchingObject * clone() const; |
---|
436 | |
---|
437 | // Destructor |
---|
438 | virtual ~OsiBiLinearBranchingObject (); |
---|
439 | |
---|
440 | /// Does next branch and updates state |
---|
441 | virtual double branch(OsiSolverInterface * solver); |
---|
442 | |
---|
443 | /** \brief Print something about branch - only if log level high |
---|
444 | */ |
---|
445 | virtual void print(const OsiSolverInterface * solver=NULL); |
---|
446 | /** \brief Return true if branch should only bound variables |
---|
447 | */ |
---|
448 | virtual bool boundBranch() const |
---|
449 | { return false;}; |
---|
450 | private: |
---|
451 | /// data |
---|
452 | /// 1 means branch on x, 2 branch on y |
---|
453 | short chosen_; |
---|
454 | }; |
---|
455 | /// Define a single integer class - but one where you kep branching until fixed even if satsified |
---|
456 | |
---|
457 | |
---|
458 | class OsiSimpleFixedInteger : public OsiSimpleInteger { |
---|
459 | |
---|
460 | public: |
---|
461 | |
---|
462 | /// Default Constructor |
---|
463 | OsiSimpleFixedInteger (); |
---|
464 | |
---|
465 | /// Useful constructor - passed solver index |
---|
466 | OsiSimpleFixedInteger (const OsiSolverInterface * solver, int iColumn); |
---|
467 | |
---|
468 | /// Useful constructor - passed solver index and original bounds |
---|
469 | OsiSimpleFixedInteger (int iColumn, double lower, double upper); |
---|
470 | |
---|
471 | /// Useful constructor - passed simple integer |
---|
472 | OsiSimpleFixedInteger (const OsiSimpleInteger &); |
---|
473 | |
---|
474 | /// Copy constructor |
---|
475 | OsiSimpleFixedInteger ( const OsiSimpleFixedInteger &); |
---|
476 | |
---|
477 | /// Clone |
---|
478 | virtual OsiObject * clone() const; |
---|
479 | |
---|
480 | /// Assignment operator |
---|
481 | OsiSimpleFixedInteger & operator=( const OsiSimpleFixedInteger& rhs); |
---|
482 | |
---|
483 | /// Destructor |
---|
484 | virtual ~OsiSimpleFixedInteger (); |
---|
485 | |
---|
486 | /// Infeasibility - large is 0.5 |
---|
487 | virtual double infeasibility(const OsiBranchingInformation * info, int & whichWay) const; |
---|
488 | /** Creates a branching object |
---|
489 | |
---|
490 | The preferred direction is set by \p way, 0 for down, 1 for up. |
---|
491 | */ |
---|
492 | virtual OsiBranchingObject * createBranch(OsiSolverInterface * solver, const OsiBranchingInformation * info, int way) const; |
---|
493 | protected: |
---|
494 | /// data |
---|
495 | |
---|
496 | }; |
---|
497 | #endif |
---|