source: trunk/Cbc/src/CbcBranchBase.hpp @ 2464

Last change on this file since 2464 was 2464, checked in by unxusr, 8 months ago

.clang-format with proposal for formatting code

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.2 KB
Line 
1/* $Id: CbcBranchBase.hpp 2464 2019-01-03 19:03:23Z unxusr $ */
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
13enum 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*/
35static inline CbcRangeCompare
36CbcCompareRanges(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
Note: See TracBrowser for help on using the repository browser.