-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathudbm_int.h
162 lines (138 loc) · 4.57 KB
/
udbm_int.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/* Copyright 2011 Peter Bulychev
#
# This file is part of Python binding to the UPPAAL DBM library.
#
# This binding is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This binding is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this binding. If not, see <http://www.gnu.org/licenses/>.
*/
#include "dbm/gen.h"
#include "dbm/fed.h"
#include "dbm/mingraph.h"
#include "dbm/ClockAccessor.h"
#include "hash/tables.h"
#include "hash/compute.h"
#include <string.h>
#include <map>
#include <iostream>
#include <vector>
using namespace dbm;
using namespace std;
class VarNamesAccessor: public ClockAccessor {
map<int, string> names_map;
public:
void setClockName(int index, std::string name) {
names_map[index] = string(name);
}
virtual const std::string getClockName(cindex_t i) const {
map<int, string>::const_iterator iterator = this->names_map.find(i);
return iterator->second;
}
bool hasClockName(cindex_t i) const {
map<int, string>::const_iterator iterator = this->names_map.find(i);
return (iterator != names_map.end());
}
};
class Constraint {
friend class Federation;
constraint_t constraint;
public:
Constraint (int i, int j, int d, bool isStrict) :
constraint(cindex_t(i), cindex_t(j), int32_t(d), isStrict) {
}
};
class IntClockValuation {
friend class Federation;
IntValuation val;
public:
IntClockValuation(int size):
val(size) {}
void setClockValue(int index, int value) {
val[index] = value;
}
};
class DoubleClockValuation {
friend class Federation;
DoubleValuation val;
public:
DoubleClockValuation(int size):
val(size) {}
void setClockValue(int index, double value) {
val[index] = value;
}
};
class IntVector {
// for some reason it's impossible to use this http://www.swig.org/Doc1.3/Library.html#Library_nn15
public:
vector<int> v;
IntVector(int i) : v(i) {}
int getElement(int i) {
return v[i];
}
void setElement(int i, int val) {
v[i] = val;
}
};
class Federation : public fed_t {
public:
Federation(int dim) : fed_t(dim) {}
Federation(int dim, Constraint &c) : fed_t(dim) {
dbm_t dbm(dim);
dbm.setInit();
dbm &= c.constraint;
add(dbm);
};
Federation(fed_t f): fed_t(f) {};
std::string toStr(const VarNamesAccessor &a) {
VarNamesAccessor b = a;
for (unsigned int i=1; i<getDimension(); i++) {
if (!b.hasClockName(i)) {
std::ostringstream stream;
stream << "c" << i;
b.setClockName(i, stream.str());
}
}
return toString(b);
}
Federation andOp (const Federation &arg) {
VarNamesAccessor a;
return Federation((*this) & arg);
}
Federation orOp (const Federation &arg) {
return Federation((*this) | arg);
}
Federation addOp (const Federation &arg) {
return Federation((*this) + arg);
}
Federation minusOp (const Federation &arg) {
return Federation((*this) - arg);
}
void opFreeClock(int i) {
this->freeClock(i);
}
bool containsIntValuation(IntClockValuation v) {
return this->contains(v.val);
}
bool containsDoubleValuation(DoubleClockValuation v) {
return this->contains(v.val);
}
void myExtrapolateMaxBounds(IntVector v) {
int dimension = getDimension();
int32_t *ia = (int32_t *)malloc(sizeof (int32_t) * dimension);
for (int i=0; i<dimension; i++) {
ia[i] = v.v[i];
}
extrapolateMaxBounds(ia);
free(ia);
}
}
;