~verifydtapn-contributers/verifydtapn/trunk

« back to all changes in this revision

Viewing changes to src/DiscreteVerification/Util/IntervalOps.cpp

  • Committer: Jiri Srba
  • Date: 2017-09-18 13:43:37 UTC
  • mfrom: (334.1.8 verifydtapn)
  • Revision ID: srba.jiri@gmail.com-20170918134337-fi97wtwg1i1689kt
merged in branch lp:~verifydtapn-contributers/verifydtapn/win-compile 
allowing to cross compile to windows (min mac version is 10.9)

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
namespace Util {
13
13
 
14
14
using namespace std;
15
 
using namespace boost::numeric;
16
15
 
17
16
vector<interval > setIntersection(const vector<interval >& first, const vector<interval >& second){
18
17
        vector<interval > result;
29
28
 
30
29
                interval intersection = intersect(first.at(i), second.at(j));
31
30
 
32
 
                if(!empty(intersection)){
 
31
                if(!intersection.empty()){
33
32
                        result.push_back(intersection);
34
33
                }
35
34
 
44
43
        return result;
45
44
}
46
45
 
 
46
interval intersect(const interval& l, const interval r)
 
47
{
 
48
    if(l.empty()) return l;
 
49
    if(r.empty()) return r;
 
50
    interval n(std::max(l.low, r.low), std::min(l.high, r.high));
 
51
    return n;
 
52
}
 
53
 
 
54
interval hull(const interval& l, const interval r)
 
55
{
 
56
    return interval(std::min(l.low, r.low), std::max(l.high, r.high));
 
57
}
 
58
 
 
59
bool overlap(const interval& l, const interval r)
 
60
{
 
61
    auto i = intersect(l, r);
 
62
    return !i.empty();
 
63
}
 
64
 
47
65
void setAdd(vector< interval >& first, const interval& element){
48
66
 
49
67
        for(unsigned int i = 0; i < first.size(); i++){
55
73
                } else if(overlap(element, first.at(i))){
56
74
                        interval u = hull(element, first.at(i));
57
75
                        // Merge with node
58
 
                        first.at(i).assign(u.lower(), u.upper());
 
76
                        first[i] = u;
59
77
                        // Clean up
60
78
                        for(i++; i < first.size(); i++){
61
79
                                if(first.at(i).lower() <= u.upper()){
62
80
                                        // Merge items
63
81
                                        if(first.at(i).upper() > u.upper()){
64
 
                                                first.at(i-1).assign(first.at(i-1).lower(), first.at(i).upper());
 
82
                                                first[i-1] = interval(first.at(i-1).lower(), first.at(i).upper());
65
83
                                        }
66
84
                                        first.erase(first.begin()+i);
67
85
                                        i--;