source: releases/2.7.1/Cbc/src/CbcBranchBase.hpp @ 1995

Last change on this file since 1995 was 1573, checked in by lou, 8 years ago

Change to EPL license notice.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.3 KB
Line 
1/* $Id: CbcBranchBase.hpp 1573 2011-01-05 01:12:36Z tkr $ */
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
77#endif
78
Note: See TracBrowser for help on using the repository browser.