1 /* $Id$ */
2 // Copyright (C) 2002, International Business Machines
3 // Corporation and others.  All Rights Reserved.
4 // This code is licensed under the terms of the Eclipse Public License (EPL).
5 
6 #ifndef CbcBranchBase_H
7 #define CbcBranchBase_H
8 
9 #include <string>
10 #include <vector>
11 #include "OsiBranchingObject.hpp"
12 
13 enum CbcRangeCompare {
14   CbcRangeSame,
15   CbcRangeDisjoint,
16   CbcRangeSubset,
17   CbcRangeSuperset,
18   CbcRangeOverlap
19 };
20 
21 #include "CbcObject.hpp"
22 #include "CbcBranchingObject.hpp"
23 #include "CbcBranchDecision.hpp"
24 #include "CbcConsequence.hpp"
25 #include "CbcObjectUpdateData.hpp"
26 
27 //##############################################################################
28 
29 /** Compare two ranges. The two bounds arrays are both of size two and
30     describe closed intervals. Return the appropriate CbcRangeCompare value
31     (first argument being the sub/superset if that's the case). In case of
32     overlap (and if \c replaceIfOverlap is true) replace the content of thisBd
33     with the intersection of the ranges.
34 */
35 static inline CbcRangeCompare
CbcCompareRanges(double * thisBd,const double * otherBd,const bool replaceIfOverlap)36 CbcCompareRanges(double *thisBd, const double *otherBd,
37   const bool replaceIfOverlap)
38 {
39   const double lbDiff = thisBd[0] - otherBd[0];
40   if (lbDiff < 0) { // lb of this < lb of other
41     if (thisBd[1] >= otherBd[1]) { // ub of this >= ub of other
42       return CbcRangeSuperset;
43     } else if (thisBd[1] < otherBd[0]) {
44       return CbcRangeDisjoint;
45     } else {
46       // overlap
47       if (replaceIfOverlap) {
48         thisBd[0] = otherBd[0];
49       }
50       return CbcRangeOverlap;
51     }
52   } else if (lbDiff > 0) { // lb of this > lb of other
53     if (thisBd[1] <= otherBd[1]) { // ub of this <= ub of other
54       return CbcRangeSubset;
55     } else if (thisBd[0] > otherBd[1]) {
56       return CbcRangeDisjoint;
57     } else {
58       // overlap
59       if (replaceIfOverlap) {
60         thisBd[1] = otherBd[1];
61       }
62       return CbcRangeOverlap;
63     }
64   } else { // lb of this == lb of other
65     if (thisBd[1] == otherBd[1]) {
66       return CbcRangeSame;
67     }
68     return thisBd[1] < otherBd[1] ? CbcRangeSubset : CbcRangeSuperset;
69   }
70 
71   return CbcRangeSame; // fake return
72 }
73 
74 //#############################################################################
75 
76 #endif
77 
78 /* vi: softtabstop=2 shiftwidth=2 expandtab tabstop=2
79 */
80