Merge lp:~tapaal-contributor/verifypn/update-parser into lp:verifypn
- update-parser
- Merge into new-trunk
Status: | Merged |
---|---|
Approved by: | Jiri Srba |
Approved revision: | 296 |
Merged at revision: | 243 |
Proposed branch: | lp:~tapaal-contributor/verifypn/update-parser |
Merge into: | lp:verifypn |
Diff against target: |
9294 lines (+3374/-2414) 37 files modified
include/PetriEngine/AbstractPetriNetBuilder.h (+4/-4) include/PetriEngine/Colored/ArcIntervals.h (+11/-58) include/PetriEngine/Colored/BindingGenerator.h (+32/-25) include/PetriEngine/Colored/ColoredNetStructures.h (+4/-2) include/PetriEngine/Colored/ColoredPetriNetBuilder.h (+30/-27) include/PetriEngine/Colored/Colors.h (+101/-192) include/PetriEngine/Colored/EquivalenceClass.h (+26/-54) include/PetriEngine/Colored/EquivalenceVec.h (+69/-0) include/PetriEngine/Colored/Expressions.h (+341/-385) include/PetriEngine/Colored/GuardRestrictor.h (+86/-67) include/PetriEngine/Colored/IntervalGenerator.h (+22/-172) include/PetriEngine/Colored/Intervals.h (+204/-257) include/PetriEngine/Colored/Multiset.h (+9/-9) include/PetriEngine/Colored/PartitionBuilder.h (+46/-29) include/PetriEngine/PQL/Expressions.h (+37/-1) include/PetriEngine/PQL/PQL.h (+2/-0) include/PetriEngine/PetriNetBuilder.h (+2/-2) include/PetriEngine/Reducer.h (+4/-5) include/PetriEngine/TAR/range.h (+7/-3) include/PetriEngine/options.h (+5/-1) include/PetriParse/PNMLParser.h (+4/-4) src/LTL/LTLMain.cpp (+1/-3) src/PetriEngine/Colored/BindingGenerator.cpp (+134/-76) src/PetriEngine/Colored/CMakeLists.txt (+3/-1) src/PetriEngine/Colored/ColoredPetriNetBuilder.cpp (+444/-180) src/PetriEngine/Colored/Colors.cpp (+53/-78) src/PetriEngine/Colored/EquivalenceClass.cpp (+50/-58) src/PetriEngine/Colored/EquivalenceVec.cpp (+86/-0) src/PetriEngine/Colored/GuardRestrictor.cpp (+301/-177) src/PetriEngine/Colored/IntervalGenerator.cpp (+197/-0) src/PetriEngine/Colored/Multiset.cpp (+34/-34) src/PetriEngine/Colored/PartitionBuilder.cpp (+304/-225) src/PetriEngine/PQL/Expressions.cpp (+373/-5) src/PetriEngine/PetriNetBuilder.cpp (+1/-2) src/PetriEngine/Reducer.cpp (+4/-27) src/PetriParse/PNMLParser.cpp (+107/-110) src/VerifyPN.cpp (+236/-141) |
To merge this branch: | bzr merge lp:~tapaal-contributor/verifypn/update-parser |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Jiri Srba | Approve | ||
Peter Gjøl Jensen | Approve | ||
Review via email: mp+402747@code.launchpad.net |
Commit message
Small changes made for the interaction with the colored GUI:
Handle passing and unfolding of inhibitor arcs.
Add options for retrieving the unfolded net and queries before reductions.
Fix scalar products, such that the scalar is applied.
This branch also contains the latest version of the unfolding techniques.
Description of the change
- 245. By Peter Haahr Taankvist
-
Merge in parser fix from optimize unfolding
- 246. By Peter Haahr Taankvist
-
Delete commented out code
- 247. By Thomas Pedersen <email address hidden>
-
Fix comments, split up functions and add typedefs
Thomas Pedersen (tpede16) wrote : | # |
We have tried to fix the comments and we left a few of our own where we could not fix it.
- 248. By Peter G. Jensen <email address hidden>
-
less moving, more const
- 249. By Peter G. Jensen <email address hidden>
-
finishing comment
- 250. By Thomas Pedersen <email address hidden>
-
Improve arguments in color.h
- 251. By Thomas Pedersen <email address hidden>
-
Handle inhibitor arcs in color stripping
- 252. By Thomas Pedersen <email address hidden>
-
Fix color stripping query marking
- 253. By Peter Haahr Taankvist
-
Remove unused functions
- 254. By Thomas Pedersen <email address hidden>
-
Update arguments in guardRestrictor
- 255. By Thomas Pedersen <email address hidden>
-
Refactor IntervalGenerator
- 256. By Thomas Pedersen <email address hidden>
-
Fix some return types
- 257. By Thomas Pedersen <email address hidden>
-
Finish fixing return types
- 258. By Thomas Pedersen <email address hidden>
-
Handle guard vars not on in arcs
- 259. By Thomas Pedersen <email address hidden>
-
Fix creation of equivalence classes
- 260. By Peter G. Jensen <email address hidden>
-
fixing use of dealloc
- 261. By Thomas Pedersen <email address hidden>
-
Refactor arguments in colored expressions
- 262. By Thomas Pedersen <email address hidden>
-
Fix adding tokens to color fixpoint
- 263. By Thomas Pedersen <email address hidden>
-
Move EquivalenceVec to class
- 264. By Thomas Pedersen <email address hidden>
-
Fix partitionbuilder constructor and errors added in refactoring
- 265. By Thomas Pedersen <email address hidden>
-
Update partitionBuilder arguments and equivalenceVec functions
- 266. By Thomas Pedersen <email address hidden>
-
Update arguments in ColoredPetriNet
Builder - 267. By Thomas Pedersen <email address hidden>
-
Make multiset iterator const
- 268. By Thomas Pedersen <email address hidden>
-
Add some more const references
- 269. By Thomas Pedersen <email address hidden>
-
Include erase operation in simplify loop
- 270. By Peter G. Jensen <email address hidden>
-
more const-ref, in particular in loops. Removed some pointers also
- 271. By Peter G. Jensen <email address hidden>
-
cleaning up types & refactoring
- 272. By Peter G. Jensen <email address hidden>
-
Merged removal of debug output
- 273. By Peter G. Jensen <email address hidden>
-
cleanup
- 274. By Thomas Pedersen <email address hidden>
-
Remove side effect of static function
- 275. By Thomas Pedersen <email address hidden>
-
Implement var resrictions for inequality
- 276. By Thomas Pedersen <email address hidden>
-
Remove unused notExpression
- 277. By Thomas Pedersen <email address hidden>
-
Disable stable places check when fixpoint has not been computed
- 278. By Thomas Pedersen <email address hidden>
-
Attempt to fix dot constant colortype assignment
- 279. By Peter G. Jensen <email address hidden>
-
removing funky static, fixing types, more const
- 280. By Peter G. Jensen <email address hidden>
-
removing unused method
- 281. By Peter G. Jensen <email address hidden>
-
no need for casting
- 282. By Peter G. Jensen <email address hidden>
-
remember to deallocate
- 283. By Peter G. Jensen <email address hidden>
-
unused field removed
- 284. By Peter G. Jensen <email address hidden>
-
fixed deallocation
- 285. By Thomas Pedersen <email address hidden>
-
Remove unused loop and old comment
- 286. By Thomas Pedersen <email address hidden>
-
Re-add relevant comment
- 287. By Thomas Pedersen <email address hidden>
-
Fix inequality implementation to not just invert the varmap
- 288. By Peter G. Jensen <email address hidden>
-
making destructor virtual
- 289. By Peter G. Jensen <email address hidden>
-
fixing off-by-one when reducing, leading to segfault
- 290. By Peter G. Jensen <email address hidden>
-
removing unused code, initializing variable
- 291. By Peter G. Jensen <email address hidden>
-
fixing simplify again
- 292. By Peter G. Jensen <email address hidden>
-
remove unused variable
- 293. By Peter G. Jensen <email address hidden>
-
fixing type
- 294. By Peter G. Jensen <email address hidden>
-
fixing loop guard
- 295. By Thomas Pedersen <email address hidden>
-
Reset both sides in inequality after equality fails
- 296. By Peter G. Jensen <email address hidden>
-
updated text in help
Peter Gjøl Jensen (peter-gjoel) : | # |
Preview Diff
1 | === modified file 'include/PetriEngine/AbstractPetriNetBuilder.h' |
2 | --- include/PetriEngine/AbstractPetriNetBuilder.h 2020-03-02 21:03:24 +0000 |
3 | +++ include/PetriEngine/AbstractPetriNetBuilder.h 2021-07-07 08:15:00 +0000 |
4 | @@ -27,7 +27,6 @@ |
5 | #include "Colored/Expressions.h" |
6 | |
7 | namespace PetriEngine { |
8 | - |
9 | /** Abstract builder for petri nets */ |
10 | class AbstractPetriNetBuilder { |
11 | protected: |
12 | @@ -41,7 +40,7 @@ |
13 | double y = 0) = 0; |
14 | /** Add a new colored place with a unique name */ |
15 | virtual void addPlace(const std::string& name, |
16 | - Colored::ColorType* type, |
17 | + const Colored::ColorType* type, |
18 | Colored::Multiset&& tokens, |
19 | double x = 0, |
20 | double y = 0) |
21 | @@ -70,7 +69,8 @@ |
22 | /** Add colored input arc with given arc expression */ |
23 | virtual void addInputArc(const std::string& place, |
24 | const std::string& transition, |
25 | - const Colored::ArcExpression_ptr& expr) |
26 | + const Colored::ArcExpression_ptr& expr, |
27 | + bool inhibitor, int weight) |
28 | { |
29 | std::cerr << "Colored input arcs are not supported in standard P/T nets" << std::endl; |
30 | exit(ErrorCode); |
31 | @@ -89,7 +89,7 @@ |
32 | } |
33 | /** Add color types with id */ |
34 | virtual void addColorType(const std::string& id, |
35 | - Colored::ColorType* type) |
36 | + const Colored::ColorType* type) |
37 | { |
38 | std::cerr << "Color types are not supported in standard P/T nets" << std::endl; |
39 | exit(ErrorCode); |
40 | |
41 | === modified file 'include/PetriEngine/Colored/ArcIntervals.h' |
42 | --- include/PetriEngine/Colored/ArcIntervals.h 2021-03-15 10:04:47 +0000 |
43 | +++ include/PetriEngine/Colored/ArcIntervals.h 2021-07-07 08:15:00 +0000 |
44 | @@ -25,69 +25,22 @@ |
45 | namespace Colored { |
46 | |
47 | struct ArcIntervals { |
48 | - std::unordered_map<const Colored::Variable *, std::vector<std::unordered_map<uint32_t, int32_t>>> _varIndexModMap; |
49 | - std::vector<Colored::intervalTuple_t> _intervalTupleVec; |
50 | - Colored::ColorFixpoint * _source; |
51 | + VariableModifierMap _varIndexModMap; |
52 | + std::vector<Colored::interval_vector_t> _intervalTupleVec; |
53 | + const Colored::ColorFixpoint * _source; |
54 | |
55 | ~ArcIntervals() {_varIndexModMap.clear();} |
56 | ArcIntervals() { |
57 | } |
58 | |
59 | - ArcIntervals(Colored::ColorFixpoint * source) : _source(source){ |
60 | - } |
61 | - |
62 | - ArcIntervals(Colored::ColorFixpoint * source, std::unordered_map<const Colored::Variable *, std::vector<std::unordered_map<uint32_t, int32_t>>> varIndexModMap) : _varIndexModMap(varIndexModMap), _source(source) { |
63 | - }; |
64 | - |
65 | - ArcIntervals(Colored::ColorFixpoint * source, std::unordered_map<const Colored::Variable *, std::vector<std::unordered_map<uint32_t, int32_t>>> varIndexModMap, std::vector<Colored::intervalTuple_t> ranges) : _varIndexModMap(varIndexModMap), _intervalTupleVec(ranges), _source(source) { |
66 | - }; |
67 | - |
68 | - size_t size() { |
69 | - return _intervalTupleVec.size(); |
70 | - } |
71 | - |
72 | - Colored::intervalTuple_t& operator[] (size_t index) { |
73 | - return _intervalTupleVec[index]; |
74 | - } |
75 | - |
76 | - Colored::intervalTuple_t& operator[] (int index) { |
77 | - return _intervalTupleVec[index]; |
78 | - } |
79 | - |
80 | - Colored::intervalTuple_t& operator[] (uint32_t index) { |
81 | - assert(index < _intervalTupleVec.size()); |
82 | - return _intervalTupleVec[index]; |
83 | - } |
84 | - |
85 | - Colored::intervalTuple_t& back(){ |
86 | - return _intervalTupleVec.back(); |
87 | - } |
88 | - |
89 | - bool hasValidIntervals(){ |
90 | - for(auto intervalTuple : _intervalTupleVec){ |
91 | - if (intervalTuple.hasValidIntervals()){ |
92 | - return true; |
93 | - } |
94 | - } |
95 | - return false; |
96 | - } |
97 | - |
98 | - bool containsVariable(Colored::Variable * var){ |
99 | - for (auto varModPair : _varIndexModMap){ |
100 | - if(varModPair.first == var){ |
101 | - return true; |
102 | - } |
103 | - } |
104 | - return false; |
105 | - } |
106 | - |
107 | - std::set<const Colored::Variable *> getVariables(){ |
108 | - std::set<const Colored::Variable *> res; |
109 | - for (auto varModPair : _varIndexModMap){ |
110 | - res.insert(varModPair.first); |
111 | - } |
112 | - return res; |
113 | - } |
114 | + ArcIntervals(const Colored::ColorFixpoint * source) : _source(source){ |
115 | + } |
116 | + |
117 | + ArcIntervals(const Colored::ColorFixpoint * source, VariableModifierMap varIndexModMap) : _varIndexModMap(varIndexModMap), _source(source) { |
118 | + }; |
119 | + |
120 | + ArcIntervals(const Colored::ColorFixpoint * source, VariableModifierMap varIndexModMap, std::vector<Colored::interval_vector_t> ranges) : _varIndexModMap(varIndexModMap), _intervalTupleVec(ranges), _source(source) { |
121 | + }; |
122 | |
123 | void print() { |
124 | std::cout << "[ "; |
125 | |
126 | === modified file 'include/PetriEngine/Colored/BindingGenerator.h' |
127 | --- include/PetriEngine/Colored/BindingGenerator.h 2021-04-14 10:41:18 +0000 |
128 | +++ include/PetriEngine/Colored/BindingGenerator.h 2021-07-07 08:15:00 +0000 |
129 | @@ -25,8 +25,6 @@ |
130 | |
131 | namespace PetriEngine { |
132 | |
133 | - typedef std::unordered_map<std::string, Colored::ColorType*> ColorTypeMap; |
134 | - |
135 | class NaiveBindingGenerator { |
136 | public: |
137 | class Iterator { |
138 | @@ -39,22 +37,21 @@ |
139 | bool operator==(Iterator& other); |
140 | bool operator!=(Iterator& other); |
141 | Iterator& operator++(); |
142 | - const Colored::ExpressionContext::BindingMap operator++(int); |
143 | - Colored::ExpressionContext::BindingMap& operator*(); |
144 | + const Colored::BindingMap& operator*() const; |
145 | }; |
146 | private: |
147 | Colored::GuardExpression_ptr _expr; |
148 | - Colored::ExpressionContext::BindingMap _bindings; |
149 | - ColorTypeMap& _colorTypes; |
150 | + Colored::BindingMap _bindings; |
151 | + Colored::ColorTypeMap& _colorTypes; |
152 | |
153 | - bool eval(); |
154 | + bool eval() const; |
155 | |
156 | public: |
157 | - NaiveBindingGenerator(Colored::Transition& transition, |
158 | - ColorTypeMap& colorTypes); |
159 | + NaiveBindingGenerator(const Colored::Transition& transition, |
160 | + Colored::ColorTypeMap& colorTypes); |
161 | |
162 | - Colored::ExpressionContext::BindingMap& nextBinding(); |
163 | - Colored::ExpressionContext::BindingMap& currentBinding(); |
164 | + const Colored::BindingMap& nextBinding(); |
165 | + const Colored::BindingMap& currentBinding() const; |
166 | bool isInitial() const; |
167 | Iterator begin(); |
168 | Iterator end(); |
169 | @@ -73,32 +70,42 @@ |
170 | bool operator==(Iterator& other); |
171 | bool operator!=(Iterator& other); |
172 | Iterator& operator++(); |
173 | - const Colored::ExpressionContext::BindingMap operator++(int); |
174 | - Colored::ExpressionContext::BindingMap& operator*(); |
175 | + const Colored::BindingMap operator++(int); |
176 | + const Colored::BindingMap& operator*() const; |
177 | }; |
178 | private: |
179 | - Colored::GuardExpression_ptr _expr; |
180 | - Colored::ExpressionContext::BindingMap _bindings; |
181 | - ColorTypeMap& _colorTypes; |
182 | - Colored::Transition &_transition; |
183 | + const Colored::GuardExpression_ptr &_expr; |
184 | + Colored::BindingMap _bindings; |
185 | + std::vector<std::vector<std::vector<uint32_t>>> _symmetric_var_combinations; |
186 | + const Colored::ColorTypeMap& _colorTypes; |
187 | + const Colored::Transition &_transition; |
188 | + const std::vector<std::set<const Colored::Variable *>>& _symmetric_vars; |
189 | + Colored::BindingMap::iterator _bindingIterator; |
190 | bool _isDone; |
191 | bool _noValidBindings; |
192 | uint32_t _nextIndex = 0; |
193 | + uint32_t _currentOuterId = 0; |
194 | + uint32_t _currentInnerId = 0; |
195 | + uint32_t _symmetric_vars_set = 0; |
196 | |
197 | - bool eval(); |
198 | + bool eval() const; |
199 | + bool assignSymmetricVars(); |
200 | + void generateCombinations( |
201 | + uint32_t options, |
202 | + uint32_t samples, |
203 | + std::vector<std::vector<uint32_t>> &result, |
204 | + std::vector<uint32_t> ¤t) const; |
205 | |
206 | public: |
207 | - FixpointBindingGenerator(Colored::Transition& transition, |
208 | - ColorTypeMap& colorTypes); |
209 | + FixpointBindingGenerator(const Colored::Transition &transition, |
210 | + const Colored::ColorTypeMap& colorTypes, const std::vector<std::set<const Colored::Variable *>>& symmetric_vars); |
211 | |
212 | FixpointBindingGenerator(const FixpointBindingGenerator& ) = default; |
213 | |
214 | - FixpointBindingGenerator operator= (const FixpointBindingGenerator& b) { |
215 | - return FixpointBindingGenerator(b); |
216 | - } |
217 | + FixpointBindingGenerator& operator= (const FixpointBindingGenerator& b) = default; |
218 | |
219 | - Colored::ExpressionContext::BindingMap& nextBinding(); |
220 | - Colored::ExpressionContext::BindingMap& currentBinding(); |
221 | + const Colored::BindingMap& nextBinding(); |
222 | + const Colored::BindingMap& currentBinding() const; |
223 | bool isInitial() const; |
224 | Iterator begin(); |
225 | Iterator end(); |
226 | |
227 | === modified file 'include/PetriEngine/Colored/ColoredNetStructures.h' |
228 | --- include/PetriEngine/Colored/ColoredNetStructures.h 2021-04-29 09:42:52 +0000 |
229 | +++ include/PetriEngine/Colored/ColoredNetStructures.h 2021-07-07 08:15:00 +0000 |
230 | @@ -35,6 +35,7 @@ |
231 | uint32_t transition; |
232 | ArcExpression_ptr expr; |
233 | bool input; |
234 | + uint32_t weight; |
235 | }; |
236 | |
237 | struct Transition { |
238 | @@ -42,14 +43,15 @@ |
239 | GuardExpression_ptr guard; |
240 | std::vector<Arc> input_arcs; |
241 | std::vector<Arc> output_arcs; |
242 | - std::vector<std::unordered_map<const Colored::Variable *, Colored::intervalTuple_t>> variableMaps; |
243 | + std::vector<std::unordered_map<const Variable *, interval_vector_t>> variableMaps; |
244 | bool considered; |
245 | }; |
246 | |
247 | struct Place { |
248 | std::string name; |
249 | - ColorType* type; |
250 | + const ColorType* type; |
251 | Multiset marking; |
252 | + bool inhibitor; |
253 | bool stable = true; |
254 | }; |
255 | } |
256 | |
257 | === modified file 'include/PetriEngine/Colored/ColoredPetriNetBuilder.h' |
258 | --- include/PetriEngine/Colored/ColoredPetriNetBuilder.h 2021-04-29 09:42:52 +0000 |
259 | +++ include/PetriEngine/Colored/ColoredPetriNetBuilder.h 2021-07-07 08:15:00 +0000 |
260 | @@ -47,7 +47,7 @@ |
261 | double x = 0, |
262 | double y = 0) override ; |
263 | void addPlace(const std::string& name, |
264 | - Colored::ColorType* type, |
265 | + const Colored::ColorType* type, |
266 | Colored::Multiset&& tokens, |
267 | double x = 0, |
268 | double y = 0) override; |
269 | @@ -64,7 +64,8 @@ |
270 | int) override; |
271 | void addInputArc(const std::string& place, |
272 | const std::string& transition, |
273 | - const Colored::ArcExpression_ptr& expr) override; |
274 | + const Colored::ArcExpression_ptr& expr, |
275 | + bool inhibitor, int weight) override; |
276 | void addOutputArc(const std::string& transition, |
277 | const std::string& place, |
278 | int weight = 1) override; |
279 | @@ -72,7 +73,7 @@ |
280 | const std::string& place, |
281 | const Colored::ArcExpression_ptr& expr) override; |
282 | void addColorType(const std::string& id, |
283 | - Colored::ColorType* type) override; |
284 | + const Colored::ColorType* type) override; |
285 | |
286 | |
287 | void sort() override; |
288 | @@ -85,10 +86,6 @@ |
289 | return _partitionTimer; |
290 | } |
291 | |
292 | - double getPartitionVarMapTime() const { |
293 | - return _partitionVarMapTimer; |
294 | - } |
295 | - |
296 | double getFixpointTime() const { |
297 | return _fixPointCreationTime; |
298 | } |
299 | @@ -115,7 +112,6 @@ |
300 | } |
301 | |
302 | uint32_t getUnfoldedPlaceCount() const { |
303 | - //return _nptplaces; |
304 | return _ptBuilder.numberOfPlaces(); |
305 | } |
306 | |
307 | @@ -142,7 +138,9 @@ |
308 | PetriNetBuilder& unfold(); |
309 | PetriNetBuilder& stripColors(); |
310 | void computePlaceColorFixpoint(uint32_t max_intervals, uint32_t max_intervals_reduced, int32_t timeout); |
311 | - void computePartition(); |
312 | + void computePartition(int32_t timeout); |
313 | + void computeSymmetricVariables(); |
314 | + void printSymmetricVariables() const; |
315 | |
316 | private: |
317 | std::unordered_map<std::string,uint32_t> _placenames; |
318 | @@ -153,16 +151,19 @@ |
319 | std::unordered_map<uint32_t,FixpointBindingGenerator> _bindings; |
320 | PTPlaceMap _ptplacenames; |
321 | PTTransitionMap _pttransitionnames; |
322 | - uint32_t _nptplaces = 0; |
323 | - uint32_t _npttransitions = 0; |
324 | uint32_t _nptarcs = 0; |
325 | uint32_t _maxIntervals = 0; |
326 | - PetriEngine::IntervalGenerator intervalGenerator; |
327 | + const Colored::IntervalGenerator intervalGenerator = Colored::IntervalGenerator(); |
328 | |
329 | std::vector<Colored::Place> _places; |
330 | std::vector<Colored::Transition> _transitions; |
331 | + std::vector<Colored::Arc> _inhibitorArcs; |
332 | std::vector<Colored::ColorFixpoint> _placeColorFixpoints; |
333 | - ColorTypeMap _colors; |
334 | + //transition id to vector of vectors of variables, where variable in vector are symmetric |
335 | + std::unordered_map<uint32_t, std::vector<std::set<const Colored::Variable *>>> symmetric_var_map; |
336 | + |
337 | + std::unordered_map<uint32_t, std::string> _sumPlacesNames; |
338 | + Colored::ColorTypeMap _colors; |
339 | PetriNetBuilder _ptBuilder; |
340 | bool _unfolded = false; |
341 | bool _stripped = false; |
342 | @@ -177,33 +178,35 @@ |
343 | |
344 | double _partitionTimer = 0; |
345 | |
346 | - double _partitionVarMapTimer = 0; |
347 | - |
348 | - std::string arcToString(Colored::Arc& arc) const ; |
349 | - |
350 | - void printPlaceTable(); |
351 | - |
352 | - |
353 | - |
354 | - std::unordered_map<uint32_t, Colored::ArcIntervals> setupTransitionVars(Colored::Transition transition); |
355 | + std::string arcToString(const Colored::Arc& arc) const ; |
356 | + |
357 | + void printPlaceTable() const; |
358 | + |
359 | + void checkSymmetricVarsInArcs(const Colored::Transition &transition, const Colored::Arc &inArc, const std::set<const Colored::Variable*> &inArcVars, bool &isEligible ) const; |
360 | + void checkSymmetricVarsOutArcs(const Colored::Transition &transition, const std::set<const Colored::Variable*> &inArcVars, bool &isEligible) const; |
361 | + void removeInvalidVarmaps(Colored::Transition& transition) const; |
362 | + void addTransitionVars(Colored::Transition& transition) const; |
363 | + |
364 | + std::unordered_map<uint32_t, Colored::ArcIntervals> setupTransitionVars(const Colored::Transition &transition) const; |
365 | |
366 | void addArc(const std::string& place, |
367 | const std::string& transition, |
368 | const Colored::ArcExpression_ptr& expr, |
369 | - bool input); |
370 | + bool input, bool inhibitor, int weight); |
371 | |
372 | void findStablePlaces(); |
373 | |
374 | - void getArcIntervals(Colored::Transition& transition, bool &transitionActivated, uint32_t max_intervals, uint32_t transitionId); |
375 | + void getArcIntervals(const Colored::Transition& transition, bool &transitionActivated, uint32_t max_intervals, uint32_t transitionId); |
376 | void processInputArcs(Colored::Transition& transition, uint32_t currentPlaceId, uint32_t transitionId, bool &transitionActivated, uint32_t max_intervals); |
377 | void processOutputArcs(Colored::Transition& transition); |
378 | |
379 | void unfoldPlace(const Colored::Place* place, const PetriEngine::Colored::Color *color, uint32_t unfoldPlace, uint32_t id); |
380 | - void unfoldTransition(Colored::Transition& transition); |
381 | - void handleOrphanPlace(Colored::Place& place, std::unordered_map<std::string, uint32_t> unfoldedPlaceMap); |
382 | + void unfoldTransition(uint32_t transitionId); |
383 | + void handleOrphanPlace(const Colored::Place& place, const std::unordered_map<std::string, uint32_t> &unfoldedPlaceMap); |
384 | void createPartionVarmaps(); |
385 | + void unfoldInhibitorArc(const std::string &oldname, const std::string &newname); |
386 | |
387 | - void unfoldArc(Colored::Arc& arc, Colored::ExpressionContext::BindingMap& binding, std::string& name); |
388 | + void unfoldArc(const Colored::Arc& arc, const Colored::BindingMap& binding, const std::string& name); |
389 | }; |
390 | |
391 | //Used for checking if a variable is inside either a succ or pred expression |
392 | |
393 | === modified file 'include/PetriEngine/Colored/Colors.h' |
394 | --- include/PetriEngine/Colored/Colors.h 2021-04-22 12:43:03 +0000 |
395 | +++ include/PetriEngine/Colored/Colors.h 2021-07-07 08:15:00 +0000 |
396 | @@ -35,33 +35,38 @@ |
397 | namespace PetriEngine { |
398 | namespace Colored { |
399 | class ColorType; |
400 | + class Variable; |
401 | + class Color; |
402 | + |
403 | + typedef std::unordered_map<std::string, const ColorType*> ColorTypeMap; |
404 | + typedef std::unordered_map<const Variable *, const Color *> BindingMap; |
405 | |
406 | - class Color { |
407 | + class Color final { |
408 | public: |
409 | friend std::ostream& operator<< (std::ostream& stream, const Color& color); |
410 | |
411 | protected: |
412 | const std::vector<const Color*> _tuple; |
413 | - ColorType* _colorType; |
414 | + const ColorType * const _colorType; |
415 | std::string _colorName; |
416 | uint32_t _id; |
417 | |
418 | public: |
419 | - Color(ColorType* colorType, uint32_t id, std::vector<const Color*>& colors); |
420 | - Color(ColorType* colorType, uint32_t id, const char* color); |
421 | + Color(const ColorType* colorType, uint32_t id, std::vector<const Color*>& colors); |
422 | + Color(const ColorType* colorType, uint32_t id, const char* color); |
423 | ~Color() {} |
424 | |
425 | bool isTuple() const { |
426 | return _tuple.size() > 1; |
427 | } |
428 | |
429 | - void getColorConstraints(Colored::interval_t *constraintsVector, uint32_t *index) const; |
430 | + void getColorConstraints(Colored::interval_t& constraintsVector, uint32_t& index) const; |
431 | |
432 | - std::vector<const Color*> getTupleColors() const { |
433 | + const std::vector<const Color*>& getTupleColors() const { |
434 | return _tuple; |
435 | } |
436 | |
437 | - void getTupleId(std::vector<uint32_t> *idVector) const; |
438 | + void getTupleId(std::vector<uint32_t>& idVector) const; |
439 | |
440 | const std::string& getColorName() const { |
441 | if (this->isTuple()) { |
442 | @@ -70,7 +75,7 @@ |
443 | return _colorName; |
444 | } |
445 | |
446 | - ColorType* getColorType() const { |
447 | + const ColorType* getColorType() const { |
448 | return _colorType; |
449 | } |
450 | |
451 | @@ -99,226 +104,156 @@ |
452 | static std::string toString(const std::vector<const Color*>& colors); |
453 | }; |
454 | |
455 | - /* |
456 | - * Singleton pattern from: |
457 | - * https://stackoverflow.com/questions/1008019/c-singleton-design-pattern |
458 | - */ |
459 | - class DotConstant : public Color { |
460 | - private: |
461 | - DotConstant(); |
462 | - |
463 | - public: |
464 | - static const Color* dotConstant(ColorType *ct) { |
465 | - static DotConstant _instance; |
466 | - if(ct != nullptr){ |
467 | - _instance._colorType = ct; |
468 | - } |
469 | - return &_instance; |
470 | - } |
471 | - |
472 | - DotConstant(DotConstant const&) = delete; |
473 | - void operator=(DotConstant const&) = delete; |
474 | - |
475 | - bool operator== (const DotConstant& other) { |
476 | - return true; |
477 | - } |
478 | - }; |
479 | - |
480 | class ColorType { |
481 | - public: |
482 | - class iterator { |
483 | - private: |
484 | - ColorType& type; |
485 | - size_t index; |
486 | - |
487 | - public: |
488 | - iterator(ColorType& type, size_t index) : type(type), index(index) {} |
489 | - |
490 | - const Color& operator++() { |
491 | - return type[++index]; |
492 | - } |
493 | - |
494 | - const Color& operator++(int) { |
495 | - return type[index++]; |
496 | - } |
497 | - |
498 | - const Color& operator--() { |
499 | - return type[--index]; |
500 | - } |
501 | - const Color& operator--(int) { |
502 | - return type[index--]; |
503 | - } |
504 | - |
505 | - const Color& operator*() { |
506 | - return type[index]; |
507 | - } |
508 | - |
509 | - const Color* operator->() { |
510 | - return &type[index]; |
511 | - } |
512 | - |
513 | - bool operator==(iterator& other) { |
514 | - return type == other.type && index == other.index; |
515 | - } |
516 | - |
517 | - bool operator!=(iterator& other) { |
518 | - return !(type == other.type) || index != other.index; |
519 | - } |
520 | - }; |
521 | - |
522 | private: |
523 | std::vector<Color> _colors; |
524 | - uintptr_t _id; |
525 | - std::string _name; |
526 | + std::string _name; |
527 | + public: |
528 | |
529 | - public: |
530 | - ColorType(std::vector<ColorType*> elements); |
531 | ColorType(std::string name = "Undefined") : _colors(), _name(std::move(name)) { |
532 | - _id = (uintptr_t)this; |
533 | } |
534 | + |
535 | + virtual ~ColorType() = default; |
536 | |
537 | + static const ColorType* dotInstance(); |
538 | virtual void addColor(const char* colorName); |
539 | - virtual void addColor(std::vector<const Color*>& colors); |
540 | - virtual void addDot() { |
541 | - _colors.push_back(*DotConstant::dotConstant(this)); |
542 | - } |
543 | - |
544 | + |
545 | virtual size_t size() const { |
546 | return _colors.size(); |
547 | } |
548 | |
549 | - virtual size_t productSize() { |
550 | + virtual size_t size(const std::vector<bool> &excludedFields) const { |
551 | + return _colors.size(); |
552 | + } |
553 | + |
554 | + virtual size_t productSize() const { |
555 | return 1; |
556 | } |
557 | |
558 | - virtual std::vector<size_t> getConstituentsSizes(){ |
559 | + virtual std::vector<size_t> getConstituentsSizes() const{ |
560 | std::vector<size_t> result; |
561 | result.push_back(_colors.size()); |
562 | |
563 | return result; |
564 | } |
565 | |
566 | - virtual Colored::interval_t getFullInterval(){ |
567 | + virtual Colored::interval_t getFullInterval() const{ |
568 | Colored::interval_t interval; |
569 | - interval.addRange(Reachability::range_t(0, size()-1)); |
570 | + interval.addRange(0, size()-1); |
571 | return interval; |
572 | } |
573 | |
574 | - virtual void getColortypes(std::vector<ColorType *> &colorTypes){ |
575 | - colorTypes.push_back(this); |
576 | - } |
577 | - |
578 | - virtual void printConstituents(){ |
579 | - std::cout << _name << std::endl; |
580 | - } |
581 | - |
582 | - virtual const Color& operator[] (size_t index) { |
583 | - return _colors[index]; |
584 | - } |
585 | - |
586 | - virtual const Color& operator[] (int index) { |
587 | - return _colors[index]; |
588 | - } |
589 | - |
590 | - virtual const Color& operator[] (uint32_t index) { |
591 | + virtual void getColortypes(std::vector<const ColorType *> &colorTypes) const{ |
592 | + colorTypes.emplace_back(this); |
593 | + } |
594 | + |
595 | + virtual const Color& operator[] (size_t index) const { |
596 | + return _colors[index]; |
597 | + } |
598 | + |
599 | + virtual const Color& operator[] (int index) const { |
600 | + return _colors[index]; |
601 | + } |
602 | + |
603 | + virtual const Color& operator[] (uint32_t index) const { |
604 | assert(index < _colors.size()); |
605 | return _colors[index]; |
606 | } |
607 | |
608 | - virtual const Color* operator[] (const char* index); |
609 | + virtual const Color* operator[] (const char* index) const; |
610 | |
611 | - virtual const Color* operator[] (const std::string& index) { |
612 | + virtual const Color* operator[] (const std::string& index) const { |
613 | return (*this)[index.c_str()]; |
614 | } |
615 | |
616 | - virtual const Color* getColor(std::vector<uint32_t> ids){ |
617 | + virtual const Color* getColor(const std::vector<uint32_t> &ids) const { |
618 | assert(ids.size() == 1); |
619 | return &_colors[ids[0]]; |
620 | } |
621 | |
622 | - bool operator== (const ColorType& other) const { |
623 | - return _id == other._id; |
624 | - } |
625 | - |
626 | - uintptr_t getId() { |
627 | - return _id; |
628 | - } |
629 | - |
630 | const std::string& getName() const { |
631 | return _name; |
632 | } |
633 | |
634 | - iterator begin() { |
635 | - return {*this, 0}; |
636 | + std::vector<Color>::const_iterator begin() const { |
637 | + return _colors.begin(); |
638 | } |
639 | |
640 | - iterator end() { |
641 | - return {*this, size()}; |
642 | + std::vector<Color>::const_iterator end() const { |
643 | + return _colors.end(); |
644 | } |
645 | }; |
646 | - |
647 | + |
648 | class ProductType : public ColorType { |
649 | private: |
650 | - std::vector<ColorType*> constituents; |
651 | - std::unordered_map<size_t,Color> cache; |
652 | + std::vector<const ColorType*> _constituents; |
653 | + mutable std::unordered_map<size_t,Color> _cache; |
654 | |
655 | public: |
656 | ProductType(const std::string& name = "Undefined") : ColorType(name) {} |
657 | ~ProductType() { |
658 | - cache.clear(); |
659 | + _cache.clear(); |
660 | } |
661 | |
662 | - void addType(ColorType* type) { |
663 | - constituents.push_back(type); |
664 | + void addType(const ColorType* type) { |
665 | + _constituents.push_back(type); |
666 | } |
667 | |
668 | void addColor(const char* colorName) override {} |
669 | - void addColor(std::vector<const Color*>& colors) override {} |
670 | - void addDot() override {} |
671 | |
672 | size_t size() const override { |
673 | size_t product = 1; |
674 | - for (auto ct : constituents) { |
675 | + for (auto* ct : _constituents) { |
676 | product *= ct->size(); |
677 | } |
678 | return product; |
679 | } |
680 | |
681 | - virtual size_t productSize() { |
682 | + size_t size(const std::vector<bool> &excludedFields) const override { |
683 | + size_t product = 1; |
684 | + for (uint32_t i = 0; i < _constituents.size(); i++) { |
685 | + if(!excludedFields[i]){ |
686 | + product *= _constituents[i]->size(); |
687 | + } |
688 | + } |
689 | + return product; |
690 | + } |
691 | + |
692 | + virtual size_t productSize() const{ |
693 | size_t size = 0; |
694 | - for (auto ct : constituents){ |
695 | + for (auto* ct : _constituents){ |
696 | size += ct->productSize(); |
697 | } |
698 | return size; |
699 | } |
700 | |
701 | - std::vector<size_t> getConstituentsSizes() override{ |
702 | + std::vector<size_t> getConstituentsSizes() const override{ |
703 | std::vector<size_t> result; |
704 | - for (auto ct : constituents) { |
705 | + for (auto* ct : _constituents) { |
706 | result.push_back(ct->size()); |
707 | } |
708 | return result; |
709 | } |
710 | |
711 | - Colored::interval_t getFullInterval() override{ |
712 | + Colored::interval_t getFullInterval() const override{ |
713 | Colored::interval_t interval; |
714 | - for(auto ct : constituents) { |
715 | + for(auto ct : _constituents) { |
716 | interval.addRange(Reachability::range_t(0, ct->size()-1)); |
717 | } |
718 | return interval; |
719 | } |
720 | |
721 | - void getColortypes(std::vector<ColorType *> &colorTypes) override{ |
722 | - for(auto ct : constituents){ |
723 | + void getColortypes(std::vector<const ColorType *> &colorTypes) const override{ |
724 | + for(auto ct : _constituents){ |
725 | ct->getColortypes(colorTypes); |
726 | } |
727 | } |
728 | |
729 | bool containsTypes(const std::vector<const ColorType*>& types) const { |
730 | - if (constituents.size() != types.size()) return false; |
731 | + if (_constituents.size() != types.size()) return false; |
732 | |
733 | - for (size_t i = 0; i < constituents.size(); ++i) { |
734 | - if (!(*constituents[i] == *types[i])) { |
735 | + for (size_t i = 0; i < _constituents.size(); ++i) { |
736 | + if (!(_constituents[i] == types[i])) { |
737 | return false; |
738 | } |
739 | } |
740 | @@ -326,72 +261,46 @@ |
741 | return true; |
742 | } |
743 | |
744 | - void printConstituents() override{ |
745 | - for(auto ct : constituents){ |
746 | - ct->printConstituents(); |
747 | - } |
748 | - } |
749 | - |
750 | - const ColorType* getNestedColorType(size_t index) { |
751 | - return constituents[index]; |
752 | - } |
753 | - |
754 | - const Color* getColor(std::vector<uint32_t> ids){ |
755 | - assert(ids.size() == constituents.size()); |
756 | - std::vector<const Color *> colors; |
757 | - for(uint32_t i = 0; i < ids.size(); i++){ |
758 | - colors.push_back(&constituents[i]->operator[](i)); |
759 | - } |
760 | - return getColor(colors); |
761 | - } |
762 | - |
763 | - const Color* getColor(const std::vector<const Color*>& colors); |
764 | - |
765 | - const Color& operator[](size_t index) override; |
766 | - const Color& operator[](int index) override { |
767 | - return operator[]((size_t)index); |
768 | - } |
769 | - const Color& operator[](uint32_t index) override { |
770 | - return operator[]((size_t)index); |
771 | - } |
772 | - |
773 | - const Color* operator[](const char* index) override; |
774 | - const Color* operator[](const std::string& index) override; |
775 | + const ColorType* getNestedColorType(size_t index) const { |
776 | + return _constituents[index]; |
777 | + } |
778 | + |
779 | + const Color* getColor(const std::vector<uint32_t> &ids) const override; |
780 | + |
781 | + const Color* getColor(const std::vector<const Color*>& colors) const; |
782 | + |
783 | + const Color& operator[](size_t index) const override; |
784 | + const Color& operator[](int index) const override { |
785 | + return operator[]((size_t)index); |
786 | + } |
787 | + const Color& operator[](uint32_t index) const override { |
788 | + return operator[]((size_t)index); |
789 | + } |
790 | + |
791 | + const Color* operator[](const char* index) const override; |
792 | + const Color* operator[](const std::string& index) const override; |
793 | }; |
794 | |
795 | struct Variable { |
796 | std::string name; |
797 | - ColorType* colorType; |
798 | + const ColorType* colorType; |
799 | }; |
800 | |
801 | struct ColorFixpoint { |
802 | - Colored::intervalTuple_t constraints; |
803 | + Colored::interval_vector_t constraints; |
804 | bool inQueue; |
805 | - |
806 | - bool constainsColor(std::pair<const PetriEngine::Colored::Color *const, std::vector<uint32_t>> constPair) { |
807 | - std::unordered_map<uint32_t, bool> contained; |
808 | - for(auto interval : constraints._intervals) { |
809 | - for(uint32_t id : constPair.second){ |
810 | - |
811 | - if(contained[id] != true){ |
812 | - contained[id] = interval[id].contains(constPair.first->getId()); |
813 | - } |
814 | - } |
815 | - } |
816 | - |
817 | - for(auto pair : contained){ |
818 | - if (!pair.second){ |
819 | - return false; |
820 | - } |
821 | - } |
822 | - return true; |
823 | - } |
824 | }; |
825 | |
826 | struct ColorTypePartition { |
827 | std::vector<const Color *> colors; |
828 | std::string name; |
829 | }; |
830 | + |
831 | + typedef std::unordered_map<uint32_t, const Colored::Variable *> PositionVariableMap; |
832 | + //Map from variables to a vector of maps from variable positions to the modifiers applied to the variable in that position |
833 | + typedef std::unordered_map<const Colored::Variable *,std::vector<std::unordered_map<uint32_t, int32_t>>> VariableModifierMap; |
834 | + typedef std::unordered_map<const PetriEngine::Colored::Variable *, PetriEngine::Colored::interval_vector_t> VariableIntervalMap; |
835 | + typedef std::unordered_map<uint32_t, std::vector<const Color*>> PositionColorsMap; |
836 | } |
837 | } |
838 | |
839 | |
840 | === modified file 'include/PetriEngine/Colored/EquivalenceClass.h' |
841 | --- include/PetriEngine/Colored/EquivalenceClass.h 2021-04-14 10:41:18 +0000 |
842 | +++ include/PetriEngine/Colored/EquivalenceClass.h 2021-07-07 08:15:00 +0000 |
843 | @@ -1,5 +1,5 @@ |
844 | -#ifndef PARTITION_H |
845 | -#define PARTITION_H |
846 | +#ifndef EQUIVALENCECLASS_H |
847 | +#define EQUIVALENCECLASS_H |
848 | |
849 | #include "Intervals.h" |
850 | #include "Colors.h" |
851 | @@ -9,71 +9,43 @@ |
852 | namespace Colored { |
853 | class EquivalenceClass { |
854 | public: |
855 | - EquivalenceClass(); |
856 | - EquivalenceClass(ColorType *colorType); |
857 | - EquivalenceClass(ColorType *colorType, intervalTuple_t colorIntervals); |
858 | + EquivalenceClass(uint32_t id); |
859 | + EquivalenceClass(uint32_t id, const ColorType *colorType); |
860 | + EquivalenceClass(uint32_t id, const ColorType *colorType, interval_vector_t&& colorIntervals); |
861 | ~EquivalenceClass() {} |
862 | - std::string toString(){ |
863 | - std::cout << "Id: " << _id << std::endl; |
864 | + std::string toString() const{ |
865 | return _colorIntervals.toString(); |
866 | } |
867 | |
868 | - bool isEmpty(){ |
869 | - if(_colorIntervals.size() < 1 || _colorIntervals.getFirst().size() < 1){ |
870 | + bool isEmpty() const{ |
871 | + if(_colorIntervals.size() < 1 || _colorIntervals.front().size() < 1){ |
872 | return true; |
873 | } |
874 | return false; |
875 | } |
876 | |
877 | - bool containsColor(std::vector<uint32_t> ids); |
878 | - |
879 | - size_t size(); |
880 | - |
881 | - EquivalenceClass intersect(EquivalenceClass other); |
882 | - |
883 | - EquivalenceClass subtract(EquivalenceClass other, bool print); |
884 | - |
885 | - static uint32_t idCounter; |
886 | + bool containsColor(const std::vector<uint32_t> &ids, const std::vector<bool> &diagonalPositions) const; |
887 | + |
888 | + size_t size() const; |
889 | + |
890 | + EquivalenceClass intersect(uint32_t id, const EquivalenceClass &other) const; |
891 | + |
892 | + EquivalenceClass subtract(uint32_t id, const EquivalenceClass &other, const std::vector<bool> &diagonalPositions) const; |
893 | + |
894 | + uint32_t id() const { return _id; } |
895 | + const ColorType* type() const { return _colorType; } |
896 | + const interval_vector_t& intervals() const { return _colorIntervals; } |
897 | + void clear() { _colorIntervals.clear(); } |
898 | + void setIntervalVector(const interval_vector_t& interval) { _colorIntervals = interval; } |
899 | + void addInterval(interval_t&& interval) { _colorIntervals.addInterval(interval); } |
900 | + private: |
901 | uint32_t _id; |
902 | - ColorType *_colorType; |
903 | - intervalTuple_t _colorIntervals; |
904 | - |
905 | - private: |
906 | + const ColorType *_colorType; |
907 | + interval_vector_t _colorIntervals; |
908 | |
909 | |
910 | }; |
911 | - |
912 | - struct EquivalenceVec{ |
913 | - std::vector<EquivalenceClass> _equivalenceClasses; |
914 | - std::unordered_map<const Colored::Color *, EquivalenceClass *> colorEQClassMap; |
915 | - bool diagonal = false; |
916 | - |
917 | - void applyPartition(Colored::ArcIntervals& arcInterval){ |
918 | - if(diagonal){ |
919 | - return; |
920 | - } |
921 | - std::vector<Colored::intervalTuple_t> newTupleVec; |
922 | - for(auto intervalTuple : arcInterval._intervalTupleVec){ |
923 | - intervalTuple.combineNeighbours(); |
924 | - intervalTuple_t newIntervalTuple; |
925 | - for(auto interval : intervalTuple._intervals){ |
926 | - for(auto EQClass : _equivalenceClasses){ |
927 | - for(auto EQinterval : EQClass._colorIntervals._intervals){ |
928 | - auto overlap = interval.getOverlap(EQinterval); |
929 | - if(overlap.isSound()){ |
930 | - newIntervalTuple.addInterval(EQinterval.getSingleColorInterval()); |
931 | - continue; |
932 | - } |
933 | - } |
934 | - } |
935 | - } |
936 | - newTupleVec.push_back(std::move(newIntervalTuple)); |
937 | - } |
938 | - arcInterval._intervalTupleVec = std::move(newTupleVec); |
939 | - } |
940 | - }; |
941 | - |
942 | } |
943 | } |
944 | |
945 | -#endif /* PARTITION_H */ |
946 | \ No newline at end of file |
947 | +#endif /* EQUIVALENCECLASS_H */ |
948 | \ No newline at end of file |
949 | |
950 | === added file 'include/PetriEngine/Colored/EquivalenceVec.h' |
951 | --- include/PetriEngine/Colored/EquivalenceVec.h 1970-01-01 00:00:00 +0000 |
952 | +++ include/PetriEngine/Colored/EquivalenceVec.h 2021-07-07 08:15:00 +0000 |
953 | @@ -0,0 +1,69 @@ |
954 | +#ifndef EQUIVALENCEVEC_H |
955 | +#define EQUIVALENCEVEC_H |
956 | + |
957 | +#include "Intervals.h" |
958 | +#include "Colors.h" |
959 | +#include "ArcIntervals.h" |
960 | +#include "EquivalenceClass.h" |
961 | + |
962 | +namespace PetriEngine { |
963 | + namespace Colored { |
964 | + class EquivalenceVec{ |
965 | + public: |
966 | + void applyPartition(Colored::ArcIntervals& arcInterval) const; |
967 | + void mergeEqClasses(); |
968 | + void applyPartition(std::vector<uint32_t> &colorIds) const; |
969 | + |
970 | + bool isDiagonal() const{ |
971 | + return _diagonal; |
972 | + } |
973 | + |
974 | + void setDiagonal(bool diagonal) { |
975 | + _diagonal = diagonal; |
976 | + } |
977 | + |
978 | + const std::vector<EquivalenceClass> & getEquivalenceClasses() const{ |
979 | + return _equivalenceClasses; |
980 | + } |
981 | + |
982 | + |
983 | + const std::vector<bool> & getDiagonalTuplePositions() const{ |
984 | + return _diagonalTuplePositions; |
985 | + } |
986 | + |
987 | + void push_back_Eqclass(const EquivalenceClass &Eqclass){ |
988 | + _equivalenceClasses.push_back(Eqclass); |
989 | + } |
990 | + |
991 | + void erase_Eqclass(uint32_t position){ |
992 | + _equivalenceClasses.erase(_equivalenceClasses.begin() + position); |
993 | + } |
994 | + |
995 | + void push_back_diagonalTuplePos(bool val){ |
996 | + _diagonalTuplePositions.push_back(val); |
997 | + } |
998 | + |
999 | + void addColorToEqClassMap(const Color *color); |
1000 | + |
1001 | + void setDiagonalTuplePosition(uint32_t position, bool value){ |
1002 | + _diagonalTuplePositions[position] = value; |
1003 | + } |
1004 | + |
1005 | + void setDiagonalTuplePositions(const std::vector<bool> &diagonalPositions){ |
1006 | + _diagonalTuplePositions = diagonalPositions; |
1007 | + } |
1008 | + |
1009 | + const std::unordered_map<const Colored::Color *, EquivalenceClass *> &getColorEqClassMap() const{ |
1010 | + return _colorEQClassMap; |
1011 | + } |
1012 | + |
1013 | + private: |
1014 | + std::vector<EquivalenceClass> _equivalenceClasses; |
1015 | + std::unordered_map<const Colored::Color *, EquivalenceClass *> _colorEQClassMap; |
1016 | + std::vector<bool> _diagonalTuplePositions; |
1017 | + bool _diagonal = false; |
1018 | + }; |
1019 | + } |
1020 | +} |
1021 | + |
1022 | +#endif /* EQUIVALENCEVEC_H */ |
1023 | \ No newline at end of file |
1024 | |
1025 | === modified file 'include/PetriEngine/Colored/Expressions.h' |
1026 | --- include/PetriEngine/Colored/Expressions.h 2021-04-22 12:43:03 +0000 |
1027 | +++ include/PetriEngine/Colored/Expressions.h 2021-07-07 08:15:00 +0000 |
1028 | @@ -27,11 +27,12 @@ |
1029 | #include <iostream> |
1030 | #include <cassert> |
1031 | #include <memory> |
1032 | +#include <typeinfo> |
1033 | |
1034 | |
1035 | #include "Colors.h" |
1036 | #include "Multiset.h" |
1037 | -#include "EquivalenceClass.h" |
1038 | +#include "EquivalenceVec.h" |
1039 | #include "ArcIntervals.h" |
1040 | #include "GuardRestrictor.h" |
1041 | #include "../errorcodes.h" |
1042 | @@ -41,15 +42,13 @@ |
1043 | |
1044 | namespace Colored { |
1045 | struct ExpressionContext { |
1046 | - typedef std::unordered_map<const Colored::Variable *, const PetriEngine::Colored::Color *> BindingMap; |
1047 | + |
1048 | |
1049 | - BindingMap& binding; |
1050 | - std::unordered_map<std::string, ColorType*>& colorTypes; |
1051 | - Colored::EquivalenceVec& placePartition; |
1052 | + const BindingMap& binding; |
1053 | + const ColorTypeMap& colorTypes; |
1054 | + const Colored::EquivalenceVec& placePartition; |
1055 | |
1056 | const Color* findColor(const std::string& color) const { |
1057 | - if (color.compare("dot") == 0) |
1058 | - return DotConstant::dotConstant(nullptr); |
1059 | for (auto& elem : colorTypes) { |
1060 | auto col = (*elem.second)[color]; |
1061 | if (col) |
1062 | @@ -59,9 +58,9 @@ |
1063 | exit(ErrorCode); |
1064 | } |
1065 | |
1066 | - ProductType* findProductColorType(const std::vector<const ColorType*>& types) const { |
1067 | + const ProductType* findProductColorType(const std::vector<const ColorType*>& types) const { |
1068 | for (auto& elem : colorTypes) { |
1069 | - auto* pt = dynamic_cast<ProductType*>(elem.second); |
1070 | + auto* pt = dynamic_cast<const ProductType*>(elem.second); |
1071 | |
1072 | if (pt && pt->containsTypes(types)) { |
1073 | return pt; |
1074 | @@ -70,6 +69,8 @@ |
1075 | return nullptr; |
1076 | } |
1077 | }; |
1078 | + |
1079 | + |
1080 | |
1081 | class WeightException : public std::exception { |
1082 | private: |
1083 | @@ -81,38 +82,46 @@ |
1084 | return ("Undefined weight: " + _message).c_str(); |
1085 | } |
1086 | }; |
1087 | + |
1088 | + template<typename Base, typename T> |
1089 | + inline bool instanceof(const T*) { |
1090 | + return std::is_base_of<Base, T>::value; |
1091 | + } |
1092 | |
1093 | class Expression { |
1094 | public: |
1095 | Expression() {} |
1096 | |
1097 | - virtual void getVariables(std::set<const Colored::Variable*>& variables, std::unordered_map<uint32_t, const Colored::Variable *>& varPositions, std::unordered_map<const Variable *,std::vector<std::unordered_map<uint32_t, int32_t>>>& varModifierMap, uint32_t *index) const {} |
1098 | - |
1099 | - virtual void getVariables(std::set<const Colored::Variable*>& variables, std::unordered_map<uint32_t, const Colored::Variable *>& varPositions, std::unordered_map<const Variable *,std::vector<std::unordered_map<uint32_t, int32_t>>>& varModifierMap) const { |
1100 | - uint32_t index = 0; |
1101 | - getVariables(variables, varPositions, varModifierMap, &index); |
1102 | - } |
1103 | - |
1104 | - virtual void getVariables(std::set<const Colored::Variable*>& variables, std::unordered_map<uint32_t, const Colored::Variable *>& varPositions) const { |
1105 | - std::unordered_map<const Colored::Variable *,std::vector<std::unordered_map<uint32_t, int32_t>>> varModifierMap; |
1106 | - uint32_t index = 0; |
1107 | - getVariables(variables, varPositions, varModifierMap, &index); |
1108 | + virtual void getVariables(std::set<const Colored::Variable*>& variables, PositionVariableMap& varPositions, VariableModifierMap& varModifierMap, bool includeSubtracts, uint32_t& index) const {} |
1109 | + |
1110 | + virtual void getVariables(std::set<const Colored::Variable*>& variables, PositionVariableMap& varPositions, VariableModifierMap& varModifierMap, bool includeSubtracts) const { |
1111 | + uint32_t index = 0; |
1112 | + getVariables(variables, varPositions, varModifierMap, includeSubtracts, index); |
1113 | + } |
1114 | + |
1115 | + virtual void getVariables(std::set<const Colored::Variable*>& variables, PositionVariableMap& varPositions) const { |
1116 | + VariableModifierMap varModifierMap; |
1117 | + uint32_t index = 0; |
1118 | + getVariables(variables, varPositions, varModifierMap, false, index); |
1119 | + } |
1120 | + |
1121 | + virtual void getVariables(std::set<const Colored::Variable*>& variables) const { |
1122 | + PositionVariableMap varPositions; |
1123 | + VariableModifierMap varModifierMap; |
1124 | + uint32_t index = 0; |
1125 | + |
1126 | + getVariables(variables, varPositions, varModifierMap, false, index); |
1127 | } |
1128 | |
1129 | virtual bool isTuple() const { |
1130 | return false; |
1131 | } |
1132 | |
1133 | - virtual void getVariables(std::set<const Colored::Variable*>& variables) const { |
1134 | - std::unordered_map<uint32_t, const Colored::Variable *> varPositions; |
1135 | - std::unordered_map<const Variable *,std::vector<std::unordered_map<uint32_t, int32_t>>> varModifierMap; |
1136 | + virtual bool isEligibleForSymmetry(std::vector<uint32_t>& numbers) const{ |
1137 | + return false; |
1138 | + } |
1139 | |
1140 | - getVariables(variables, varPositions, varModifierMap); |
1141 | - } |
1142 | |
1143 | - virtual void expressionType() { |
1144 | - std::cout << "Expression" << std::endl; |
1145 | - } |
1146 | |
1147 | virtual std::string toString() const { |
1148 | return "Unsupported"; |
1149 | @@ -124,40 +133,40 @@ |
1150 | ColorExpression() {} |
1151 | virtual ~ColorExpression() {} |
1152 | |
1153 | - virtual const Color* eval(ExpressionContext& context) const = 0; |
1154 | + virtual const Color* eval(const ExpressionContext& context) const = 0; |
1155 | |
1156 | virtual void getConstants(std::unordered_map<uint32_t, const Color*> &constantMap, uint32_t &index) const = 0; |
1157 | |
1158 | - virtual bool getArcIntervals(Colored::ArcIntervals& arcIntervals, PetriEngine::Colored::ColorFixpoint& cfp, uint32_t *index, int32_t modifier) const = 0; |
1159 | - |
1160 | - virtual ColorType* getColorType(std::unordered_map<std::string, Colored::ColorType*>& colorTypes) const = 0; |
1161 | - |
1162 | - virtual Colored::intervalTuple_t getOutputIntervals(std::unordered_map<const PetriEngine::Colored::Variable *, PetriEngine::Colored::intervalTuple_t>& varMap, std::vector<const Colored::ColorType *> *colortypes) const { |
1163 | - return Colored::intervalTuple_t(); |
1164 | + virtual bool getArcIntervals(Colored::ArcIntervals& arcIntervals, const PetriEngine::Colored::ColorFixpoint& cfp, uint32_t& index, int32_t modifier) const = 0; |
1165 | + |
1166 | + virtual const ColorType* getColorType(const ColorTypeMap& colorTypes) const = 0; |
1167 | + |
1168 | + virtual Colored::interval_vector_t getOutputIntervals(const VariableIntervalMap& varMap, std::vector<const Colored::ColorType *> &colortypes) const { |
1169 | + return Colored::interval_vector_t(); |
1170 | } |
1171 | |
1172 | }; |
1173 | |
1174 | class DotConstantExpression : public ColorExpression { |
1175 | public: |
1176 | - const Color* eval(ExpressionContext& context) const override { |
1177 | - return DotConstant::dotConstant(nullptr); |
1178 | + const Color* eval(const ExpressionContext& context) const override { |
1179 | + return &(*ColorType::dotInstance()->begin()); |
1180 | } |
1181 | |
1182 | - bool getArcIntervals(Colored::ArcIntervals& arcIntervals, PetriEngine::Colored::ColorFixpoint& cfp, uint32_t *index, int32_t modifier) const override { |
1183 | + bool getArcIntervals(Colored::ArcIntervals& arcIntervals,const PetriEngine::Colored::ColorFixpoint& cfp, uint32_t& index, int32_t modifier) const override { |
1184 | if (arcIntervals._intervalTupleVec.empty()) { |
1185 | //We can add all place tokens when considering the dot constant as, that must be present |
1186 | arcIntervals._intervalTupleVec.push_back(cfp.constraints); |
1187 | } |
1188 | - return !cfp.constraints._intervals.empty(); |
1189 | + return !cfp.constraints.empty(); |
1190 | } |
1191 | |
1192 | - Colored::intervalTuple_t getOutputIntervals(std::unordered_map<const PetriEngine::Colored::Variable *, PetriEngine::Colored::intervalTuple_t>& varMap, std::vector<const Colored::ColorType *> *colortypes) const override { |
1193 | + Colored::interval_vector_t getOutputIntervals(const VariableIntervalMap& varMap, std::vector<const Colored::ColorType *> &colortypes) const override { |
1194 | Colored::interval_t interval; |
1195 | - Colored::intervalTuple_t tupleInterval; |
1196 | - const Color *dotColor = DotConstant::dotConstant(nullptr); |
1197 | + Colored::interval_vector_t tupleInterval; |
1198 | + const Color *dotColor = &(*ColorType::dotInstance()->begin()); |
1199 | |
1200 | - colortypes->push_back(dotColor->getColorType()); |
1201 | + colortypes.emplace_back(dotColor->getColorType()); |
1202 | |
1203 | interval.addRange(dotColor->getId(), dotColor->getId()); |
1204 | tupleInterval.addInterval(interval); |
1205 | @@ -165,11 +174,12 @@ |
1206 | } |
1207 | |
1208 | void getConstants(std::unordered_map<uint32_t, const Color*> &constantMap, uint32_t &index) const override { |
1209 | - const Color *dotColor = DotConstant::dotConstant(nullptr); |
1210 | + const Color *dotColor = &(*ColorType::dotInstance()->begin()); |
1211 | constantMap[index] = dotColor; |
1212 | } |
1213 | - ColorType* getColorType(std::unordered_map<std::string, Colored::ColorType*>& colorTypes) const override{ |
1214 | - return DotConstant::dotConstant(nullptr)->getColorType(); |
1215 | + |
1216 | + const ColorType* getColorType(const ColorTypeMap& colorTypes) const override{ |
1217 | + return ColorType::dotInstance(); |
1218 | } |
1219 | |
1220 | std::string toString() const override { |
1221 | @@ -181,16 +191,16 @@ |
1222 | |
1223 | class VariableExpression : public ColorExpression { |
1224 | private: |
1225 | - Variable* _variable; |
1226 | + const Variable* _variable; |
1227 | |
1228 | public: |
1229 | - const Color* eval(ExpressionContext& context) const override { |
1230 | - return context.binding[_variable]; |
1231 | + const Color* eval(const ExpressionContext& context) const override { |
1232 | + return context.binding.find(_variable)->second; |
1233 | } |
1234 | |
1235 | - void getVariables(std::set<const Colored::Variable*>& variables, std::unordered_map<uint32_t, const Colored::Variable *>& varPositions, std::unordered_map<const Colored::Variable *, std::vector<std::unordered_map<uint32_t, int32_t>>>& varModifierMap, uint32_t *index) const override { |
1236 | + void getVariables(std::set<const Colored::Variable*>& variables, PositionVariableMap& varPositions, VariableModifierMap& varModifierMap, bool includeSubtracts, uint32_t& index) const override { |
1237 | variables.insert(_variable); |
1238 | - varPositions[*index] = _variable; |
1239 | + varPositions[index] = _variable; |
1240 | if(varModifierMap.count(_variable) == 0){ |
1241 | std::vector<std::unordered_map<uint32_t, int32_t>> newVec; |
1242 | |
1243 | @@ -202,44 +212,42 @@ |
1244 | break; |
1245 | } |
1246 | std::unordered_map<uint32_t, int32_t> newMap; |
1247 | - newMap[*index] = 0; |
1248 | + newMap[index] = 0; |
1249 | newVec.push_back(newMap); |
1250 | varModifierMap[_variable] = newVec; |
1251 | } else { |
1252 | - varModifierMap[_variable].back()[*index] = 0; |
1253 | + varModifierMap[_variable].back()[index] = 0; |
1254 | } |
1255 | } |
1256 | |
1257 | - Colored::intervalTuple_t getOutputIntervals(std::unordered_map<const PetriEngine::Colored::Variable *, PetriEngine::Colored::intervalTuple_t>& varMap, std::vector<const Colored::ColorType *> *colortypes) const override { |
1258 | - Colored::intervalTuple_t varInterval; |
1259 | + Colored::interval_vector_t getOutputIntervals(const VariableIntervalMap& varMap, std::vector<const Colored::ColorType *> &colortypes) const override { |
1260 | + Colored::interval_vector_t varInterval; |
1261 | |
1262 | // If we see a new variable on an out arc, it gets its full interval |
1263 | if (varMap.count(_variable) == 0){ |
1264 | - Colored::intervalTuple_t intervalTuple; |
1265 | - intervalTuple.addInterval(_variable->colorType->getFullInterval()); |
1266 | - varMap[_variable] = intervalTuple; |
1267 | - } |
1268 | - |
1269 | - for(auto interval : varMap[_variable]._intervals){ |
1270 | - varInterval.addInterval(interval); |
1271 | - } |
1272 | + varInterval.addInterval(_variable->colorType->getFullInterval()); |
1273 | + } else { |
1274 | + for(const auto& interval : varMap.find(_variable)->second){ |
1275 | + varInterval.addInterval(interval); |
1276 | + } |
1277 | + } |
1278 | |
1279 | - std::vector<ColorType*> varColorTypes; |
1280 | + std::vector<const ColorType*> varColorTypes; |
1281 | _variable->colorType->getColortypes(varColorTypes); |
1282 | |
1283 | - for(auto ct : varColorTypes){ |
1284 | - colortypes->push_back(ct); |
1285 | + for(auto &ct : varColorTypes){ |
1286 | + colortypes.push_back(std::move(ct)); |
1287 | } |
1288 | |
1289 | return varInterval; |
1290 | } |
1291 | |
1292 | - bool getArcIntervals(Colored::ArcIntervals& arcIntervals, PetriEngine::Colored::ColorFixpoint& cfp, uint32_t *index, int32_t modifier) const override { |
1293 | + bool getArcIntervals(Colored::ArcIntervals& arcIntervals,const PetriEngine::Colored::ColorFixpoint& cfp, uint32_t& index, int32_t modifier) const override { |
1294 | if (arcIntervals._intervalTupleVec.empty()){ |
1295 | //As variables does not restrict the values before the guard we include all tokens |
1296 | arcIntervals._intervalTupleVec.push_back(cfp.constraints); |
1297 | } |
1298 | - return !cfp.constraints._intervals.empty(); |
1299 | + return !cfp.constraints.empty(); |
1300 | } |
1301 | |
1302 | void getConstants(std::unordered_map<uint32_t, const Color*> &constantMap, uint32_t &index) const override { |
1303 | @@ -249,11 +257,11 @@ |
1304 | return _variable->name; |
1305 | } |
1306 | |
1307 | - ColorType* getColorType(std::unordered_map<std::string, Colored::ColorType*>& colorTypes) const override{ |
1308 | + const ColorType* getColorType(const ColorTypeMap& colorTypes) const override{ |
1309 | return _variable->colorType; |
1310 | } |
1311 | |
1312 | - VariableExpression(Variable* variable) |
1313 | + VariableExpression(const Variable* variable) |
1314 | : _variable(variable) {} |
1315 | }; |
1316 | |
1317 | @@ -262,11 +270,11 @@ |
1318 | const Color* _userOperator; |
1319 | |
1320 | public: |
1321 | - const Color* eval(ExpressionContext& context) const override { |
1322 | + const Color* eval(const ExpressionContext& context) const override { |
1323 | return _userOperator; |
1324 | } |
1325 | |
1326 | - bool getArcIntervals(Colored::ArcIntervals& arcIntervals, PetriEngine::Colored::ColorFixpoint& cfp, uint32_t *index, int32_t modifier) const override { |
1327 | + bool getArcIntervals(Colored::ArcIntervals& arcIntervals,const PetriEngine::Colored::ColorFixpoint& cfp, uint32_t& index, int32_t modifier) const override { |
1328 | uint32_t colorId = _userOperator->getId() + modifier; |
1329 | while(colorId < 0){ |
1330 | colorId += _userOperator->getColorType()->size(); |
1331 | @@ -274,10 +282,10 @@ |
1332 | colorId = colorId % _userOperator->getColorType()->size(); |
1333 | |
1334 | if(arcIntervals._intervalTupleVec.empty()){ |
1335 | - Colored::intervalTuple_t newIntervalTuple; |
1336 | + Colored::interval_vector_t newIntervalTuple; |
1337 | bool colorInFixpoint = false; |
1338 | - for (auto interval : cfp.constraints._intervals){ |
1339 | - if(interval[*index].contains(colorId)){ |
1340 | + for (const auto& interval : cfp.constraints){ |
1341 | + if(interval[index].contains(colorId)){ |
1342 | newIntervalTuple.addInterval(interval); |
1343 | colorInFixpoint = true; |
1344 | } |
1345 | @@ -287,8 +295,8 @@ |
1346 | } else { |
1347 | std::vector<uint32_t> intervalsToRemove; |
1348 | for(auto& intervalTuple : arcIntervals._intervalTupleVec){ |
1349 | - for (uint32_t i = 0; i < intervalTuple._intervals.size(); i++){ |
1350 | - if(!intervalTuple[i][*index].contains(colorId)){ |
1351 | + for (uint32_t i = 0; i < intervalTuple.size(); i++){ |
1352 | + if(!intervalTuple[i][index].contains(colorId)){ |
1353 | intervalsToRemove.push_back(i); |
1354 | } |
1355 | } |
1356 | @@ -297,7 +305,7 @@ |
1357 | intervalTuple.removeInterval(*i); |
1358 | } |
1359 | } |
1360 | - return !arcIntervals._intervalTupleVec[0]._intervals.empty(); |
1361 | + return !arcIntervals._intervalTupleVec[0].empty(); |
1362 | } |
1363 | } |
1364 | |
1365 | @@ -308,15 +316,16 @@ |
1366 | void getConstants(std::unordered_map<uint32_t, const Color*> &constantMap, uint32_t &index) const override { |
1367 | constantMap[index] = _userOperator; |
1368 | } |
1369 | - ColorType* getColorType(std::unordered_map<std::string, Colored::ColorType*>& colorTypes) const override{ |
1370 | + |
1371 | + const ColorType* getColorType(const ColorTypeMap& colorTypes) const override { |
1372 | return _userOperator->getColorType(); |
1373 | } |
1374 | |
1375 | - Colored::intervalTuple_t getOutputIntervals(std::unordered_map<const PetriEngine::Colored::Variable *, PetriEngine::Colored::intervalTuple_t>& varMap, std::vector<const Colored::ColorType *> *colortypes) const override { |
1376 | + Colored::interval_vector_t getOutputIntervals(const VariableIntervalMap& varMap, std::vector<const Colored::ColorType *> &colortypes) const override { |
1377 | Colored::interval_t interval; |
1378 | - Colored::intervalTuple_t tupleInterval; |
1379 | + Colored::interval_vector_t tupleInterval; |
1380 | |
1381 | - colortypes->push_back(_userOperator->getColorType()); |
1382 | + colortypes.emplace_back(_userOperator->getColorType()); |
1383 | |
1384 | interval.addRange(_userOperator->getId(), _userOperator->getId()); |
1385 | tupleInterval.addInterval(interval); |
1386 | @@ -327,46 +336,12 @@ |
1387 | : _userOperator(userOperator) {} |
1388 | }; |
1389 | |
1390 | - class UserSortExpression : public Expression { |
1391 | - private: |
1392 | - ColorType* _userSort; |
1393 | - |
1394 | - public: |
1395 | - ColorType* eval(ExpressionContext& context) const { |
1396 | - return _userSort; |
1397 | - } |
1398 | - |
1399 | - std::string toString() const override { |
1400 | - return _userSort->getName(); |
1401 | - } |
1402 | - |
1403 | - UserSortExpression(ColorType* userSort) |
1404 | - : _userSort(userSort) {} |
1405 | - }; |
1406 | - |
1407 | - typedef std::shared_ptr<UserSortExpression> UserSortExpression_ptr; |
1408 | - |
1409 | - class NumberConstantExpression : public Expression { |
1410 | - private: |
1411 | - uint32_t _number; |
1412 | - |
1413 | - public: |
1414 | - uint32_t eval(ExpressionContext& context) const { |
1415 | - return _number; |
1416 | - } |
1417 | - |
1418 | - NumberConstantExpression(uint32_t number) |
1419 | - : _number(number) {} |
1420 | - }; |
1421 | - |
1422 | - typedef std::shared_ptr<NumberConstantExpression> NumberConstantExpression_ptr; |
1423 | - |
1424 | class SuccessorExpression : public ColorExpression { |
1425 | private: |
1426 | ColorExpression_ptr _color; |
1427 | |
1428 | public: |
1429 | - const Color* eval(ExpressionContext& context) const override { |
1430 | + const Color* eval(const ExpressionContext& context) const override { |
1431 | return &++(*_color->eval(context)); |
1432 | } |
1433 | |
1434 | @@ -374,30 +349,30 @@ |
1435 | return _color->isTuple(); |
1436 | } |
1437 | |
1438 | - void getVariables(std::set<const Colored::Variable*>& variables, std::unordered_map<uint32_t, const Colored::Variable *>& varPositions, std::unordered_map<const Colored::Variable *, std::vector<std::unordered_map<uint32_t, int32_t>>>& varModifierMap, uint32_t *index) const override { |
1439 | + void getVariables(std::set<const Colored::Variable*>& variables, PositionVariableMap& varPositions, VariableModifierMap& varModifierMap, bool includeSubtracts, uint32_t& index) const override { |
1440 | //save index before evaluating nested expression to decrease all the correct modifiers |
1441 | - uint32_t indexBefore = *index; |
1442 | - _color->getVariables(variables, varPositions, varModifierMap, index); |
1443 | + uint32_t indexBefore = index; |
1444 | + _color->getVariables(variables, varPositions, varModifierMap, includeSubtracts, index); |
1445 | for(auto& varModifierPair : varModifierMap){ |
1446 | for(auto& idModPair : varModifierPair.second.back()){ |
1447 | - if(idModPair.first <= *index && idModPair.first >= indexBefore){ |
1448 | + if(idModPair.first <= index && idModPair.first >= indexBefore){ |
1449 | idModPair.second--; |
1450 | } |
1451 | } |
1452 | } |
1453 | } |
1454 | |
1455 | - bool getArcIntervals(Colored::ArcIntervals& arcIntervals, PetriEngine::Colored::ColorFixpoint& cfp, uint32_t *index, int32_t modifier) const override { |
1456 | + bool getArcIntervals(Colored::ArcIntervals& arcIntervals,const PetriEngine::Colored::ColorFixpoint& cfp, uint32_t& index, int32_t modifier) const override { |
1457 | return _color->getArcIntervals(arcIntervals, cfp, index, modifier+1); |
1458 | } |
1459 | |
1460 | - Colored::intervalTuple_t getOutputIntervals(std::unordered_map<const PetriEngine::Colored::Variable *, PetriEngine::Colored::intervalTuple_t>& varMap, std::vector<const Colored::ColorType *> *colortypes) const override { |
1461 | + Colored::interval_vector_t getOutputIntervals(const VariableIntervalMap& varMap, std::vector<const Colored::ColorType *> &colortypes) const override { |
1462 | //store the number of colortyps already in colortypes vector and use that as offset when indexing it |
1463 | - auto colortypesBefore = colortypes->size(); |
1464 | + auto colortypesBefore = colortypes.size(); |
1465 | |
1466 | auto nestedInterval = _color->getOutputIntervals(varMap, colortypes); |
1467 | Colored::GuardRestrictor guardRestrictor = Colored::GuardRestrictor(); |
1468 | - return guardRestrictor.shiftIntervals(varMap, colortypes, &nestedInterval, 1, colortypesBefore); |
1469 | + return guardRestrictor.shiftIntervals(varMap, colortypes, nestedInterval, 1, colortypesBefore); |
1470 | } |
1471 | |
1472 | void getConstants(std::unordered_map<uint32_t, const Color*> &constantMap, uint32_t &index) const override { |
1473 | @@ -411,7 +386,7 @@ |
1474 | return _color->toString() + "++"; |
1475 | } |
1476 | |
1477 | - ColorType* getColorType(std::unordered_map<std::string, Colored::ColorType*>& colorTypes) const override{ |
1478 | + const ColorType* getColorType(const ColorTypeMap& colorTypes) const override{ |
1479 | return _color->getColorType(colorTypes); |
1480 | } |
1481 | |
1482 | @@ -424,7 +399,7 @@ |
1483 | ColorExpression_ptr _color; |
1484 | |
1485 | public: |
1486 | - const Color* eval(ExpressionContext& context) const override { |
1487 | + const Color* eval(const ExpressionContext& context) const override { |
1488 | return &--(*_color->eval(context)); |
1489 | } |
1490 | |
1491 | @@ -432,30 +407,30 @@ |
1492 | return _color->isTuple(); |
1493 | } |
1494 | |
1495 | - void getVariables(std::set<const Colored::Variable*>& variables, std::unordered_map<uint32_t, const Colored::Variable *>& varPositions, std::unordered_map<const Colored::Variable *, std::vector<std::unordered_map<uint32_t, int32_t>>>& varModifierMap, uint32_t *index) const override { |
1496 | + void getVariables(std::set<const Colored::Variable*>& variables, PositionVariableMap& varPositions, VariableModifierMap& varModifierMap, bool includeSubtracts, uint32_t& index) const override { |
1497 | //save index before evaluating nested expression to decrease all the correct modifiers |
1498 | - uint32_t indexBefore = *index; |
1499 | - _color->getVariables(variables, varPositions, varModifierMap, index); |
1500 | + uint32_t indexBefore = index; |
1501 | + _color->getVariables(variables, varPositions, varModifierMap, includeSubtracts, index); |
1502 | for(auto& varModifierPair : varModifierMap){ |
1503 | for(auto& idModPair : varModifierPair.second.back()){ |
1504 | - if(idModPair.first <= *index && idModPair.first >= indexBefore){ |
1505 | + if(idModPair.first <= index && idModPair.first >= indexBefore){ |
1506 | idModPair.second++; |
1507 | } |
1508 | } |
1509 | } |
1510 | } |
1511 | |
1512 | - bool getArcIntervals(Colored::ArcIntervals& arcIntervals, PetriEngine::Colored::ColorFixpoint& cfp, uint32_t *index, int32_t modifier) const override { |
1513 | + bool getArcIntervals(Colored::ArcIntervals& arcIntervals,const PetriEngine::Colored::ColorFixpoint& cfp, uint32_t& index, int32_t modifier) const override { |
1514 | return _color->getArcIntervals(arcIntervals, cfp, index, modifier-1); |
1515 | } |
1516 | |
1517 | - Colored::intervalTuple_t getOutputIntervals(std::unordered_map<const PetriEngine::Colored::Variable *, PetriEngine::Colored::intervalTuple_t>& varMap, std::vector<const Colored::ColorType *> *colortypes) const override { |
1518 | + Colored::interval_vector_t getOutputIntervals(const VariableIntervalMap& varMap, std::vector<const Colored::ColorType *> &colortypes) const override { |
1519 | //store the number of colortyps already in colortypes vector and use that as offset when indexing it |
1520 | - auto colortypesBefore = colortypes->size(); |
1521 | + auto colortypesBefore = colortypes.size(); |
1522 | |
1523 | auto nestedInterval = _color->getOutputIntervals(varMap, colortypes); |
1524 | Colored::GuardRestrictor guardRestrictor; |
1525 | - return guardRestrictor.shiftIntervals(varMap, colortypes, &nestedInterval, -1, colortypesBefore); |
1526 | + return guardRestrictor.shiftIntervals(varMap, colortypes, nestedInterval, -1, colortypesBefore); |
1527 | } |
1528 | |
1529 | void getConstants(std::unordered_map<uint32_t, const Color*> &constantMap, uint32_t &index) const override { |
1530 | @@ -469,7 +444,7 @@ |
1531 | return _color->toString() + "--"; |
1532 | } |
1533 | |
1534 | - ColorType* getColorType(std::unordered_map<std::string, Colored::ColorType*>& colorTypes) const override{ |
1535 | + const ColorType* getColorType(const ColorTypeMap& colorTypes) const override{ |
1536 | return _color->getColorType(colorTypes); |
1537 | } |
1538 | |
1539 | @@ -480,17 +455,17 @@ |
1540 | class TupleExpression : public ColorExpression { |
1541 | private: |
1542 | std::vector<ColorExpression_ptr> _colors; |
1543 | - ColorType* _colorType; |
1544 | + const ColorType* _colorType = nullptr; |
1545 | |
1546 | public: |
1547 | - const Color* eval(ExpressionContext& context) const override { |
1548 | + const Color* eval(const ExpressionContext& context) const override { |
1549 | std::vector<const Color*> colors; |
1550 | std::vector<const ColorType*> types; |
1551 | - for (auto color : _colors) { |
1552 | + for (const auto& color : _colors) { |
1553 | colors.push_back(color->eval(context)); |
1554 | types.push_back(colors.back()->getColorType()); |
1555 | } |
1556 | - ProductType* pt = context.findProductColorType(types); |
1557 | + const ProductType* pt = context.findProductColorType(types); |
1558 | assert(pt != nullptr); |
1559 | const Color* col = pt->getColor(colors); |
1560 | assert(col != nullptr); |
1561 | @@ -501,26 +476,25 @@ |
1562 | return true; |
1563 | } |
1564 | |
1565 | - Colored::intervalTuple_t getOutputIntervals(std::unordered_map<const PetriEngine::Colored::Variable *, PetriEngine::Colored::intervalTuple_t>& varMap, std::vector<const Colored::ColorType *> *colortypes) const override { |
1566 | - Colored::intervalTuple_t intervals; |
1567 | - Colored::intervalTuple_t intervalHolder; |
1568 | + Colored::interval_vector_t getOutputIntervals(const VariableIntervalMap& varMap, std::vector<const Colored::ColorType *> &colortypes) const override { |
1569 | + Colored::interval_vector_t intervals; |
1570 | |
1571 | - for(auto colorExp : _colors) { |
1572 | - Colored::intervalTuple_t intervalHolder; |
1573 | + for(const auto& colorExp : _colors) { |
1574 | + Colored::interval_vector_t intervalHolder; |
1575 | auto nested_intervals = colorExp->getOutputIntervals(varMap, colortypes); |
1576 | |
1577 | - if(intervals._intervals.empty()){ |
1578 | + if(intervals.empty()){ |
1579 | intervals = nested_intervals; |
1580 | } else { |
1581 | - for(auto nested_interval : nested_intervals._intervals){ |
1582 | - Colored::intervalTuple_t newIntervals; |
1583 | - for(auto interval : intervals._intervals){ |
1584 | - for(auto nestedRange : nested_interval._ranges) { |
1585 | + for(const auto& nested_interval : nested_intervals){ |
1586 | + Colored::interval_vector_t newIntervals; |
1587 | + for(auto interval : intervals){ |
1588 | + for(const auto& nestedRange : nested_interval._ranges) { |
1589 | interval.addRange(nestedRange); |
1590 | } |
1591 | newIntervals.addInterval(interval); |
1592 | } |
1593 | - for(auto newInterval : newIntervals._intervals){ |
1594 | + for(const auto& newInterval : newIntervals){ |
1595 | intervalHolder.addInterval(newInterval); |
1596 | } |
1597 | } |
1598 | @@ -530,37 +504,37 @@ |
1599 | return intervals; |
1600 | } |
1601 | |
1602 | - bool getArcIntervals(Colored::ArcIntervals& arcIntervals, PetriEngine::Colored::ColorFixpoint& cfp, uint32_t *index, int32_t modifier) const override { |
1603 | - for (auto expr : _colors) { |
1604 | + bool getArcIntervals(Colored::ArcIntervals& arcIntervals,const PetriEngine::Colored::ColorFixpoint& cfp, uint32_t& index, int32_t modifier) const override { |
1605 | + for (const auto& expr : _colors) { |
1606 | bool res = expr->getArcIntervals(arcIntervals, cfp, index, modifier); |
1607 | if(!res){ |
1608 | return false; |
1609 | } |
1610 | - (*index)++; |
1611 | + ++index; |
1612 | } |
1613 | return true; |
1614 | } |
1615 | |
1616 | - void getVariables(std::set<const Colored::Variable*>& variables, std::unordered_map<uint32_t, const Colored::Variable *>& varPositions, std::unordered_map<const Colored::Variable *, std::vector<std::unordered_map<uint32_t, int32_t>>>& varModifierMap, uint32_t *index) const override { |
1617 | - for (auto elem : _colors) { |
1618 | - elem->getVariables(variables, varPositions, varModifierMap, index); |
1619 | - (*index)++; |
1620 | + void getVariables(std::set<const Colored::Variable*>& variables, PositionVariableMap& varPositions, VariableModifierMap& varModifierMap, bool includeSubtracts, uint32_t& index) const override { |
1621 | + for (const auto& elem : _colors) { |
1622 | + elem->getVariables(variables, varPositions, varModifierMap, includeSubtracts, index); |
1623 | + ++index; |
1624 | } |
1625 | } |
1626 | |
1627 | - ColorType* getColorType(std::unordered_map<std::string, Colored::ColorType*>& colorTypes) const override{ |
1628 | + const ColorType* getColorType(const ColorTypeMap& colorTypes) const override{ |
1629 | |
1630 | std::vector<const ColorType*> types; |
1631 | if(_colorType != nullptr){ |
1632 | return _colorType; |
1633 | } |
1634 | |
1635 | - for (auto color : _colors) { |
1636 | + for (const auto& color : _colors) { |
1637 | types.push_back(color->getColorType(colorTypes)); |
1638 | } |
1639 | |
1640 | for (auto elem : colorTypes) { |
1641 | - auto* pt = dynamic_cast<ProductType*>(elem.second); |
1642 | + auto* pt = dynamic_cast<const ProductType*>(elem.second); |
1643 | if (pt && pt->containsTypes(types)) { |
1644 | return pt; |
1645 | } |
1646 | @@ -571,7 +545,7 @@ |
1647 | } |
1648 | |
1649 | void getConstants(std::unordered_map<uint32_t, const Color*> &constantMap, uint32_t &index) const override { |
1650 | - for (auto elem : _colors) { |
1651 | + for (const auto& elem : _colors) { |
1652 | elem->getConstants(constantMap, index); |
1653 | index++; |
1654 | } |
1655 | @@ -586,7 +560,7 @@ |
1656 | return res; |
1657 | } |
1658 | |
1659 | - void setColorType(ColorType* ct){ |
1660 | + void setColorType(const ColorType* ct){ |
1661 | _colorType = ct; |
1662 | } |
1663 | |
1664 | @@ -599,11 +573,11 @@ |
1665 | GuardExpression() {} |
1666 | virtual ~GuardExpression() {} |
1667 | |
1668 | - virtual bool eval(ExpressionContext& context) const = 0; |
1669 | - |
1670 | - virtual void restrictVars(std::vector<std::unordered_map<const Colored::Variable *, Colored::intervalTuple_t>>& variableMap, std::set<const Colored::Variable*> &diagonalVars) const = 0; |
1671 | - |
1672 | - virtual void restrictVars(std::vector<std::unordered_map<const Colored::Variable *, Colored::intervalTuple_t>>& variableMap) const { |
1673 | + virtual bool eval(const ExpressionContext& context) const = 0; |
1674 | + |
1675 | + virtual void restrictVars(std::vector<VariableIntervalMap>& variableMap, std::set<const Colored::Variable*> &diagonalVars) const = 0; |
1676 | + |
1677 | + virtual void restrictVars(std::vector<VariableIntervalMap>& variableMap) const { |
1678 | std::set<const Colored::Variable*> diagonalVars; |
1679 | restrictVars(variableMap, diagonalVars); |
1680 | } |
1681 | @@ -617,31 +591,31 @@ |
1682 | ColorExpression_ptr _right; |
1683 | |
1684 | public: |
1685 | - bool eval(ExpressionContext& context) const override { |
1686 | + bool eval(const ExpressionContext& context) const override { |
1687 | return _left->eval(context) < _right->eval(context); |
1688 | } |
1689 | |
1690 | - void getVariables(std::set<const Colored::Variable*>& variables, std::unordered_map<uint32_t, const Colored::Variable *>& varPositions, std::unordered_map<const Colored::Variable *, std::vector<std::unordered_map<uint32_t, int32_t>>>& varModifierMap, uint32_t *index) const override { |
1691 | - _left->getVariables(variables, varPositions, varModifierMap); |
1692 | - _right->getVariables(variables, varPositions, varModifierMap); |
1693 | + void getVariables(std::set<const Colored::Variable*>& variables, PositionVariableMap& varPositions, VariableModifierMap& varModifierMap, bool includeSubtracts, uint32_t& index) const override { |
1694 | + _left->getVariables(variables, varPositions, varModifierMap, includeSubtracts); |
1695 | + _right->getVariables(variables, varPositions, varModifierMap, includeSubtracts); |
1696 | } |
1697 | |
1698 | bool isTuple() const override { |
1699 | return _left->isTuple() || _right->isTuple(); |
1700 | } |
1701 | |
1702 | - void restrictVars(std::vector<std::unordered_map<const Colored::Variable *, Colored::intervalTuple_t>>& variableMap, std::set<const Colored::Variable*> &diagonalVars) const override { |
1703 | - std::unordered_map<const Colored::Variable *,std::vector<std::unordered_map<uint32_t, int32_t>>> varModifierMapL; |
1704 | - std::unordered_map<const Colored::Variable *,std::vector<std::unordered_map<uint32_t, int32_t>>> varModifierMapR; |
1705 | - std::unordered_map<uint32_t, const Colored::Variable *> varPositionsL; |
1706 | - std::unordered_map<uint32_t, const Colored::Variable *> varPositionsR; |
1707 | + void restrictVars(std::vector<VariableIntervalMap>& variableMap, std::set<const Colored::Variable*> &diagonalVars) const override { |
1708 | + VariableModifierMap varModifierMapL; |
1709 | + VariableModifierMap varModifierMapR; |
1710 | + PositionVariableMap varPositionsL; |
1711 | + PositionVariableMap varPositionsR; |
1712 | std::unordered_map<uint32_t, const Color*> constantMapL; |
1713 | std::unordered_map<uint32_t, const Color*> constantMapR; |
1714 | std::set<const Variable *> leftVars; |
1715 | std::set<const Variable *> rightVars; |
1716 | uint32_t index = 0; |
1717 | - _left->getVariables(leftVars, varPositionsL, varModifierMapL); |
1718 | - _right->getVariables(rightVars, varPositionsR, varModifierMapR); |
1719 | + _left->getVariables(leftVars, varPositionsL, varModifierMapL, false); |
1720 | + _right->getVariables(rightVars, varPositionsR, varModifierMapR, false); |
1721 | _left->getConstants(constantMapL, index); |
1722 | index = 0; |
1723 | _right->getConstants(constantMapR, index); |
1724 | @@ -650,7 +624,7 @@ |
1725 | return; |
1726 | } |
1727 | Colored::GuardRestrictor guardRestrictor; |
1728 | - guardRestrictor.restrictVars(variableMap, &varModifierMapL, &varModifierMapR, &varPositionsL, &varPositionsR, &constantMapL, &constantMapR, diagonalVars, true, true); |
1729 | + guardRestrictor.restrictVars(variableMap, varModifierMapL, varModifierMapR, varPositionsL, varPositionsR, constantMapL, constantMapR, diagonalVars, true, true); |
1730 | } |
1731 | |
1732 | std::string toString() const override { |
1733 | @@ -669,7 +643,7 @@ |
1734 | ColorExpression_ptr _right; |
1735 | |
1736 | public: |
1737 | - bool eval(ExpressionContext& context) const override { |
1738 | + bool eval(const ExpressionContext& context) const override { |
1739 | return _left->eval(context) > _right->eval(context); |
1740 | } |
1741 | |
1742 | @@ -677,23 +651,23 @@ |
1743 | return _left->isTuple() || _right->isTuple(); |
1744 | } |
1745 | |
1746 | - void getVariables(std::set<const Colored::Variable*>& variables, std::unordered_map<uint32_t, const Colored::Variable *>& varPositions, std::unordered_map<const Colored::Variable *, std::vector<std::unordered_map<uint32_t, int32_t>>>& varModifierMap, uint32_t *index) const override { |
1747 | - _left->getVariables(variables, varPositions, varModifierMap); |
1748 | - _right->getVariables(variables, varPositions, varModifierMap); |
1749 | + void getVariables(std::set<const Colored::Variable*>& variables, PositionVariableMap& varPositions, VariableModifierMap& varModifierMap, bool includeSubtracts, uint32_t& index) const override { |
1750 | + _left->getVariables(variables, varPositions, varModifierMap, includeSubtracts); |
1751 | + _right->getVariables(variables, varPositions, varModifierMap, includeSubtracts); |
1752 | } |
1753 | |
1754 | - void restrictVars(std::vector<std::unordered_map<const Colored::Variable *, Colored::intervalTuple_t>>& variableMap, std::set<const Colored::Variable*> &diagonalVars) const override { |
1755 | - std::unordered_map<const Colored::Variable *,std::vector<std::unordered_map<uint32_t, int32_t>>> varModifierMapL; |
1756 | - std::unordered_map<const Colored::Variable *,std::vector<std::unordered_map<uint32_t, int32_t>>> varModifierMapR; |
1757 | - std::unordered_map<uint32_t, const Colored::Variable *> varPositionsL; |
1758 | - std::unordered_map<uint32_t, const Colored::Variable *> varPositionsR; |
1759 | + void restrictVars(std::vector<VariableIntervalMap>& variableMap, std::set<const Colored::Variable*> &diagonalVars) const override { |
1760 | + VariableModifierMap varModifierMapL; |
1761 | + VariableModifierMap varModifierMapR; |
1762 | + PositionVariableMap varPositionsL; |
1763 | + PositionVariableMap varPositionsR; |
1764 | std::unordered_map<uint32_t, const Color*> constantMapL; |
1765 | std::unordered_map<uint32_t, const Color*> constantMapR; |
1766 | std::set<const Colored::Variable *> leftVars; |
1767 | std::set<const Colored::Variable *> rightVars; |
1768 | uint32_t index = 0; |
1769 | - _left->getVariables(leftVars, varPositionsL, varModifierMapL); |
1770 | - _right->getVariables(rightVars, varPositionsR, varModifierMapR); |
1771 | + _left->getVariables(leftVars, varPositionsL, varModifierMapL, false); |
1772 | + _right->getVariables(rightVars, varPositionsR, varModifierMapR, false); |
1773 | _left->getConstants(constantMapL, index); |
1774 | index = 0; |
1775 | _right->getConstants(constantMapR, index); |
1776 | @@ -703,7 +677,7 @@ |
1777 | } |
1778 | |
1779 | Colored::GuardRestrictor guardRestrictor; |
1780 | - guardRestrictor.restrictVars(variableMap, &varModifierMapL, &varModifierMapR, &varPositionsL, &varPositionsR, &constantMapL, &constantMapR, diagonalVars, false, true); |
1781 | + guardRestrictor.restrictVars(variableMap, varModifierMapL, varModifierMapR, varPositionsL, varPositionsR, constantMapL, constantMapR, diagonalVars, false, true); |
1782 | } |
1783 | |
1784 | std::string toString() const override { |
1785 | @@ -721,7 +695,7 @@ |
1786 | ColorExpression_ptr _right; |
1787 | |
1788 | public: |
1789 | - bool eval(ExpressionContext& context) const override { |
1790 | + bool eval(const ExpressionContext& context) const override { |
1791 | return _left->eval(context) <= _right->eval(context); |
1792 | } |
1793 | |
1794 | @@ -729,23 +703,23 @@ |
1795 | return _left->isTuple() || _right->isTuple(); |
1796 | } |
1797 | |
1798 | - void getVariables(std::set<const Colored::Variable*>& variables, std::unordered_map<uint32_t, const Colored::Variable *>& varPositions, std::unordered_map<const Colored::Variable *, std::vector<std::unordered_map<uint32_t, int32_t>>>& varModifierMap, uint32_t *index) const override { |
1799 | - _left->getVariables(variables, varPositions, varModifierMap); |
1800 | - _right->getVariables(variables, varPositions, varModifierMap); |
1801 | + void getVariables(std::set<const Colored::Variable*>& variables, PositionVariableMap& varPositions, VariableModifierMap& varModifierMap, bool includeSubtracts, uint32_t& index) const override { |
1802 | + _left->getVariables(variables, varPositions, varModifierMap, includeSubtracts); |
1803 | + _right->getVariables(variables, varPositions, varModifierMap, includeSubtracts); |
1804 | } |
1805 | |
1806 | - void restrictVars(std::vector<std::unordered_map<const Colored::Variable *, Colored::intervalTuple_t>>& variableMap, std::set<const Colored::Variable*> &diagonalVars) const override { |
1807 | - std::unordered_map<const Colored::Variable *,std::vector<std::unordered_map<uint32_t, int32_t>>> varModifierMapL; |
1808 | - std::unordered_map<const Colored::Variable *,std::vector<std::unordered_map<uint32_t, int32_t>>> varModifierMapR; |
1809 | - std::unordered_map<uint32_t, const Colored::Variable *> varPositionsL; |
1810 | - std::unordered_map<uint32_t, const Colored::Variable *> varPositionsR; |
1811 | + void restrictVars(std::vector<VariableIntervalMap>& variableMap, std::set<const Colored::Variable*> &diagonalVars) const override { |
1812 | + VariableModifierMap varModifierMapL; |
1813 | + VariableModifierMap varModifierMapR; |
1814 | + PositionVariableMap varPositionsL; |
1815 | + PositionVariableMap varPositionsR; |
1816 | std::unordered_map<uint32_t, const Color*> constantMapL; |
1817 | std::unordered_map<uint32_t, const Color*> constantMapR; |
1818 | std::set<const Colored::Variable *> leftVars; |
1819 | std::set<const Colored::Variable *> rightVars; |
1820 | uint32_t index = 0; |
1821 | - _left->getVariables(leftVars, varPositionsL, varModifierMapL); |
1822 | - _right->getVariables(rightVars, varPositionsR, varModifierMapR); |
1823 | + _left->getVariables(leftVars, varPositionsL, varModifierMapL, false); |
1824 | + _right->getVariables(rightVars, varPositionsR, varModifierMapR, false); |
1825 | _left->getConstants(constantMapL, index); |
1826 | index = 0; |
1827 | _right->getConstants(constantMapR, index); |
1828 | @@ -755,7 +729,7 @@ |
1829 | } |
1830 | |
1831 | Colored::GuardRestrictor guardRestrictor; |
1832 | - guardRestrictor.restrictVars(variableMap, &varModifierMapL, &varModifierMapR, &varPositionsL, &varPositionsR, &constantMapL, &constantMapR, diagonalVars, true, false); |
1833 | + guardRestrictor.restrictVars(variableMap, varModifierMapL, varModifierMapR, varPositionsL, varPositionsR, constantMapL, constantMapR, diagonalVars, true, false); |
1834 | } |
1835 | |
1836 | std::string toString() const override { |
1837 | @@ -774,7 +748,7 @@ |
1838 | ColorExpression_ptr _right; |
1839 | |
1840 | public: |
1841 | - bool eval(ExpressionContext& context) const override { |
1842 | + bool eval(const ExpressionContext& context) const override { |
1843 | return _left->eval(context) >= _right->eval(context); |
1844 | } |
1845 | |
1846 | @@ -782,23 +756,23 @@ |
1847 | return _left->isTuple() || _right->isTuple(); |
1848 | } |
1849 | |
1850 | - void getVariables(std::set<const Colored::Variable*>& variables, std::unordered_map<uint32_t, const Colored::Variable *>& varPositions, std::unordered_map<const Colored::Variable *, std::vector<std::unordered_map<uint32_t, int32_t>>>& varModifierMap, uint32_t *index) const override { |
1851 | - _left->getVariables(variables, varPositions, varModifierMap); |
1852 | - _right->getVariables(variables, varPositions, varModifierMap); |
1853 | + void getVariables(std::set<const Colored::Variable*>& variables, PositionVariableMap& varPositions, VariableModifierMap& varModifierMap, bool includeSubtracts, uint32_t& index) const override { |
1854 | + _left->getVariables(variables, varPositions, varModifierMap, includeSubtracts); |
1855 | + _right->getVariables(variables, varPositions, varModifierMap, includeSubtracts); |
1856 | } |
1857 | |
1858 | - void restrictVars(std::vector<std::unordered_map<const Colored::Variable *, Colored::intervalTuple_t>>& variableMap, std::set<const Colored::Variable*> &diagonalVars) const override { |
1859 | - std::unordered_map<const Colored::Variable *,std::vector<std::unordered_map<uint32_t, int32_t>>> varModifierMapL; |
1860 | - std::unordered_map<const Colored::Variable *,std::vector<std::unordered_map<uint32_t, int32_t>>> varModifierMapR; |
1861 | - std::unordered_map<uint32_t, const Colored::Variable *> varPositionsL; |
1862 | - std::unordered_map<uint32_t, const Colored::Variable *> varPositionsR; |
1863 | + void restrictVars(std::vector<VariableIntervalMap>& variableMap, std::set<const Colored::Variable*> &diagonalVars) const override { |
1864 | + VariableModifierMap varModifierMapL; |
1865 | + VariableModifierMap varModifierMapR; |
1866 | + PositionVariableMap varPositionsL; |
1867 | + PositionVariableMap varPositionsR; |
1868 | std::unordered_map<uint32_t, const Color*> constantMapL; |
1869 | std::unordered_map<uint32_t, const Color*> constantMapR; |
1870 | std::set<const Colored::Variable *> leftVars; |
1871 | std::set<const Colored::Variable *> rightVars; |
1872 | uint32_t index = 0; |
1873 | - _left->getVariables(leftVars, varPositionsL, varModifierMapL); |
1874 | - _right->getVariables(rightVars, varPositionsR, varModifierMapR); |
1875 | + _left->getVariables(leftVars, varPositionsL, varModifierMapL, false); |
1876 | + _right->getVariables(rightVars, varPositionsR, varModifierMapR, false); |
1877 | _left->getConstants(constantMapL, index); |
1878 | index = 0; |
1879 | _right->getConstants(constantMapR, index); |
1880 | @@ -808,7 +782,7 @@ |
1881 | } |
1882 | |
1883 | Colored::GuardRestrictor guardRestrictor; |
1884 | - guardRestrictor.restrictVars(variableMap, &varModifierMapL, &varModifierMapR, &varPositionsL, &varPositionsR, &constantMapL, &constantMapR, diagonalVars, false, false); |
1885 | + guardRestrictor.restrictVars(variableMap, varModifierMapL, varModifierMapR, varPositionsL, varPositionsR, constantMapL, constantMapR, diagonalVars, false, false); |
1886 | } |
1887 | |
1888 | std::string toString() const override { |
1889 | @@ -826,7 +800,7 @@ |
1890 | ColorExpression_ptr _right; |
1891 | |
1892 | public: |
1893 | - bool eval(ExpressionContext& context) const override { |
1894 | + bool eval(const ExpressionContext& context) const override { |
1895 | return _left->eval(context) == _right->eval(context); |
1896 | } |
1897 | |
1898 | @@ -834,24 +808,24 @@ |
1899 | return _left->isTuple() || _right->isTuple(); |
1900 | } |
1901 | |
1902 | - void getVariables(std::set<const Colored::Variable*>& variables, std::unordered_map<uint32_t, const Colored::Variable *>& varPositions, std::unordered_map<const Colored::Variable *, std::vector<std::unordered_map<uint32_t, int32_t>>>& varModifierMap, uint32_t *index) const override { |
1903 | - _left->getVariables(variables, varPositions, varModifierMap); |
1904 | - _right->getVariables(variables, varPositions, varModifierMap); |
1905 | + void getVariables(std::set<const Colored::Variable*>& variables, PositionVariableMap& varPositions, VariableModifierMap& varModifierMap, bool includeSubtracts, uint32_t& index) const override { |
1906 | + _left->getVariables(variables, varPositions, varModifierMap, includeSubtracts); |
1907 | + _right->getVariables(variables, varPositions, varModifierMap, includeSubtracts); |
1908 | } |
1909 | |
1910 | |
1911 | - void restrictVars(std::vector<std::unordered_map<const Colored::Variable *, Colored::intervalTuple_t>>& variableMap, std::set<const Colored::Variable*> &diagonalVars) const override { |
1912 | - std::unordered_map<const Colored::Variable *,std::vector<std::unordered_map<uint32_t, int32_t>>> varModifierMapL; |
1913 | - std::unordered_map<const Colored::Variable *,std::vector<std::unordered_map<uint32_t, int32_t>>> varModifierMapR; |
1914 | - std::unordered_map<uint32_t, const Colored::Variable *> varPositionsL; |
1915 | - std::unordered_map<uint32_t, const Colored::Variable *> varPositionsR; |
1916 | + void restrictVars(std::vector<VariableIntervalMap>& variableMap, std::set<const Colored::Variable*> &diagonalVars) const override { |
1917 | + VariableModifierMap varModifierMapL; |
1918 | + VariableModifierMap varModifierMapR; |
1919 | + PositionVariableMap varPositionsL; |
1920 | + PositionVariableMap varPositionsR; |
1921 | std::unordered_map<uint32_t, const Color*> constantMapL; |
1922 | std::unordered_map<uint32_t, const Color*> constantMapR; |
1923 | std::set<const Colored::Variable *> leftVars; |
1924 | std::set<const Colored::Variable *> rightVars; |
1925 | uint32_t index = 0; |
1926 | - _left->getVariables(leftVars, varPositionsL, varModifierMapL); |
1927 | - _right->getVariables(rightVars, varPositionsR, varModifierMapR); |
1928 | + _left->getVariables(leftVars, varPositionsL, varModifierMapL, false); |
1929 | + _right->getVariables(rightVars, varPositionsR, varModifierMapR, false); |
1930 | _left->getConstants(constantMapL, index); |
1931 | index = 0; |
1932 | _right->getConstants(constantMapR, index); |
1933 | @@ -861,7 +835,7 @@ |
1934 | } |
1935 | |
1936 | Colored::GuardRestrictor guardRestrictor; |
1937 | - guardRestrictor.restrictEquality(variableMap, &varModifierMapL, &varModifierMapR, &varPositionsL, &varPositionsR, &constantMapL, &constantMapR, diagonalVars); |
1938 | + guardRestrictor.restrictEquality(variableMap, varModifierMapL, varModifierMapR, varPositionsL, varPositionsR, constantMapL, constantMapR, diagonalVars); |
1939 | } |
1940 | |
1941 | std::string toString() const override { |
1942 | @@ -879,7 +853,7 @@ |
1943 | ColorExpression_ptr _right; |
1944 | |
1945 | public: |
1946 | - bool eval(ExpressionContext& context) const override { |
1947 | + bool eval(const ExpressionContext& context) const override { |
1948 | return _left->eval(context) != _right->eval(context); |
1949 | } |
1950 | |
1951 | @@ -887,13 +861,32 @@ |
1952 | return _left->isTuple() || _right->isTuple(); |
1953 | } |
1954 | |
1955 | - void getVariables(std::set<const Colored::Variable*>& variables, std::unordered_map<uint32_t, const Colored::Variable *>& varPositions, std::unordered_map<const Colored::Variable *, std::vector<std::unordered_map<uint32_t, int32_t>>>& varModifierMap, uint32_t *index) const override { |
1956 | - _left->getVariables(variables, varPositions, varModifierMap); |
1957 | - _right->getVariables(variables, varPositions, varModifierMap); |
1958 | + void getVariables(std::set<const Colored::Variable*>& variables, PositionVariableMap& varPositions, VariableModifierMap& varModifierMap, bool includeSubtracts, uint32_t& index) const override { |
1959 | + _left->getVariables(variables, varPositions, varModifierMap, includeSubtracts); |
1960 | + _right->getVariables(variables, varPositions, varModifierMap, includeSubtracts); |
1961 | } |
1962 | |
1963 | - void restrictVars(std::vector<std::unordered_map<const Colored::Variable *, Colored::intervalTuple_t>>& variableMap, std::set<const Colored::Variable*> &diagonalVars) const override { |
1964 | - |
1965 | + void restrictVars(std::vector<VariableIntervalMap>& variableMap, std::set<const Colored::Variable*> &diagonalVars) const override { |
1966 | + VariableModifierMap varModifierMapL; |
1967 | + VariableModifierMap varModifierMapR; |
1968 | + PositionVariableMap varPositionsL; |
1969 | + PositionVariableMap varPositionsR; |
1970 | + std::unordered_map<uint32_t, const Color*> constantMapL; |
1971 | + std::unordered_map<uint32_t, const Color*> constantMapR; |
1972 | + std::set<const Colored::Variable *> leftVars; |
1973 | + std::set<const Colored::Variable *> rightVars; |
1974 | + uint32_t index = 0; |
1975 | + _left->getVariables(leftVars, varPositionsL, varModifierMapL, false); |
1976 | + _right->getVariables(rightVars, varPositionsR, varModifierMapR, false); |
1977 | + _left->getConstants(constantMapL, index); |
1978 | + index = 0; |
1979 | + _right->getConstants(constantMapR, index); |
1980 | + |
1981 | + if(leftVars.empty() && rightVars.empty()){ |
1982 | + return; |
1983 | + } |
1984 | + Colored::GuardRestrictor guardRestrictor; |
1985 | + guardRestrictor.restrictInEquality(variableMap, varModifierMapL, varModifierMapR, varPositionsL, varPositionsR, constantMapL, constantMapR, diagonalVars); |
1986 | } |
1987 | |
1988 | std::string toString() const override { |
1989 | @@ -905,53 +898,13 @@ |
1990 | : _left(std::move(left)), _right(std::move(right)) {} |
1991 | }; |
1992 | |
1993 | - class NotExpression : public GuardExpression { |
1994 | - private: |
1995 | - GuardExpression_ptr _expr; |
1996 | - |
1997 | - public: |
1998 | - bool eval(ExpressionContext& context) const override { |
1999 | - return !_expr->eval(context); |
2000 | - } |
2001 | - |
2002 | - bool isTuple() const override { |
2003 | - return _expr->isTuple(); |
2004 | - } |
2005 | - |
2006 | - void getVariables(std::set<const Colored::Variable*>& variables, std::unordered_map<uint32_t, const Colored::Variable *>& varPositions, std::unordered_map<const Colored::Variable *, std::vector<std::unordered_map<uint32_t, int32_t>>>& varModifierMap, uint32_t *index) const override { |
2007 | - _expr->getVariables(variables, varPositions, varModifierMap, index); |
2008 | - } |
2009 | - |
2010 | - std::string toString() const override { |
2011 | - std::string res = "!" + _expr->toString(); |
2012 | - return res; |
2013 | - } |
2014 | - |
2015 | - void restrictVars(std::vector<std::unordered_map<const Colored::Variable *, Colored::intervalTuple_t>>& variableMap, std::set<const Colored::Variable*> &diagonalVars) const override { |
2016 | - std::set<const Colored::Variable *> variables; |
2017 | - _expr->getVariables(variables); |
2018 | - //TODO: invert the var intervals here instead of using the full intervals |
2019 | - |
2020 | - for(auto var : variables){ |
2021 | - auto fullInterval = var->colorType->getFullInterval(); |
2022 | - Colored::intervalTuple_t fullTuple; |
2023 | - fullTuple.addInterval(fullInterval); |
2024 | - for(auto& varMap : variableMap){ |
2025 | - varMap[var] = fullTuple; |
2026 | - } |
2027 | - } |
2028 | - } |
2029 | - |
2030 | - NotExpression(GuardExpression_ptr&& expr) : _expr(std::move(expr)) {} |
2031 | - }; |
2032 | - |
2033 | class AndExpression : public GuardExpression { |
2034 | private: |
2035 | GuardExpression_ptr _left; |
2036 | GuardExpression_ptr _right; |
2037 | |
2038 | public: |
2039 | - bool eval(ExpressionContext& context) const override { |
2040 | + bool eval(const ExpressionContext& context) const override { |
2041 | return _left->eval(context) && _right->eval(context); |
2042 | } |
2043 | |
2044 | @@ -959,12 +912,12 @@ |
2045 | return _left->isTuple() || _right->isTuple(); |
2046 | } |
2047 | |
2048 | - void getVariables(std::set<const Colored::Variable*>& variables, std::unordered_map<uint32_t, const Colored::Variable *>& varPositions, std::unordered_map<const Colored::Variable *, std::vector<std::unordered_map<uint32_t, int32_t>>>& varModifierMap, uint32_t *index) const override { |
2049 | - _left->getVariables(variables, varPositions, varModifierMap); |
2050 | - _right->getVariables(variables, varPositions, varModifierMap); |
2051 | + void getVariables(std::set<const Colored::Variable*>& variables, PositionVariableMap& varPositions, VariableModifierMap& varModifierMap, bool includeSubtracts, uint32_t& index) const override { |
2052 | + _left->getVariables(variables, varPositions, varModifierMap, includeSubtracts); |
2053 | + _right->getVariables(variables, varPositions, varModifierMap, includeSubtracts); |
2054 | } |
2055 | |
2056 | - void restrictVars(std::vector<std::unordered_map<const Colored::Variable *, Colored::intervalTuple_t>>& variableMap, std::set<const Colored::Variable*> &diagonalVars) const override { |
2057 | + void restrictVars(std::vector<VariableIntervalMap>& variableMap, std::set<const Colored::Variable*> &diagonalVars) const override { |
2058 | _left->restrictVars(variableMap, diagonalVars); |
2059 | _right->restrictVars(variableMap, diagonalVars); |
2060 | } |
2061 | @@ -984,7 +937,7 @@ |
2062 | GuardExpression_ptr _right; |
2063 | |
2064 | public: |
2065 | - bool eval(ExpressionContext& context) const override { |
2066 | + bool eval(const ExpressionContext& context) const override { |
2067 | return _left->eval(context) || _right->eval(context); |
2068 | } |
2069 | |
2070 | @@ -992,23 +945,17 @@ |
2071 | return _left->isTuple() || _right->isTuple(); |
2072 | } |
2073 | |
2074 | - void getVariables(std::set<const Colored::Variable*>& variables, std::unordered_map<uint32_t, const Colored::Variable *>& varPositions, std::unordered_map<const Colored::Variable *, std::vector<std::unordered_map<uint32_t, int32_t>>>& varModifierMap, uint32_t *index) const override { |
2075 | - _left->getVariables(variables, varPositions, varModifierMap); |
2076 | - _right->getVariables(variables, varPositions, varModifierMap); |
2077 | + void getVariables(std::set<const Colored::Variable*>& variables, PositionVariableMap& varPositions, VariableModifierMap& varModifierMap, bool includeSubtracts, uint32_t& index) const override { |
2078 | + _left->getVariables(variables, varPositions, varModifierMap, includeSubtracts); |
2079 | + _right->getVariables(variables, varPositions, varModifierMap, includeSubtracts); |
2080 | } |
2081 | |
2082 | - void restrictVars(std::vector<std::unordered_map<const Colored::Variable *, Colored::intervalTuple_t>>& variableMap, std::set<const Colored::Variable*> &diagonalVars) const override{ |
2083 | + void restrictVars(std::vector<VariableIntervalMap>& variableMap, std::set<const Colored::Variable*> &diagonalVars) const override{ |
2084 | auto varMapCopy = variableMap; |
2085 | _left->restrictVars(variableMap, diagonalVars); |
2086 | _right->restrictVars(varMapCopy, diagonalVars); |
2087 | |
2088 | - for(size_t i = 0; i < variableMap.size(); i++){ |
2089 | - for(auto& varPair : varMapCopy[i]){ |
2090 | - for(auto& interval : varPair.second._intervals){ |
2091 | - variableMap[i][varPair.first].addInterval(std::move(interval)); |
2092 | - } |
2093 | - } |
2094 | - } |
2095 | + variableMap.insert(variableMap.end(), varMapCopy.begin(), varMapCopy.end()); |
2096 | } |
2097 | |
2098 | std::string toString() const override { |
2099 | @@ -1025,25 +972,22 @@ |
2100 | ArcExpression() {} |
2101 | virtual ~ArcExpression() {} |
2102 | |
2103 | - virtual Multiset eval(ExpressionContext& context) const = 0; |
2104 | - |
2105 | - virtual void expressionType() override { |
2106 | - std::cout << "ArcExpression" << std::endl; |
2107 | - } |
2108 | - virtual void getConstants(std::unordered_map<uint32_t, std::vector<const Color*>> &constantMap, uint32_t &index) const = 0; |
2109 | - |
2110 | - virtual bool getArcIntervals(Colored::ArcIntervals& arcIntervals, PetriEngine::Colored::ColorFixpoint& cfp, uint32_t *index, int32_t modifier) const = 0; |
2111 | + virtual Multiset eval(const ExpressionContext& context) const = 0; |
2112 | + |
2113 | + virtual void getConstants(PositionColorsMap &constantMap, uint32_t &index) const = 0; |
2114 | + |
2115 | + virtual bool getArcIntervals(Colored::ArcIntervals& arcIntervals,const PetriEngine::Colored::ColorFixpoint& cfp, uint32_t& index, int32_t modifier) const = 0; |
2116 | |
2117 | virtual uint32_t weight() const = 0; |
2118 | |
2119 | - virtual Colored::intervalTuple_t getOutputIntervals(std::vector<std::unordered_map<const PetriEngine::Colored::Variable *, PetriEngine::Colored::intervalTuple_t>>& varMapVec) const { |
2120 | + virtual std::vector<Colored::interval_vector_t> getOutputIntervals(const std::vector<VariableIntervalMap>& varMapVec) const { |
2121 | std::vector<const Colored::ColorType *> colortypes; |
2122 | |
2123 | - return getOutputIntervals(varMapVec, &colortypes); |
2124 | + return getOutputIntervals(varMapVec, colortypes); |
2125 | } |
2126 | |
2127 | - virtual Colored::intervalTuple_t getOutputIntervals(std::vector<std::unordered_map<const PetriEngine::Colored::Variable *, PetriEngine::Colored::intervalTuple_t>>& varMapVec, std::vector<const Colored::ColorType *> *colortypes) const { |
2128 | - return Colored::intervalTuple_t(); |
2129 | + virtual std::vector<Colored::interval_vector_t> getOutputIntervals(const std::vector<VariableIntervalMap>& varMapVec, std::vector<const Colored::ColorType *> &colortypes) const{ |
2130 | + return std::vector<Colored::interval_vector_t>(0); |
2131 | } |
2132 | }; |
2133 | |
2134 | @@ -1051,20 +995,20 @@ |
2135 | |
2136 | class AllExpression : public Expression { |
2137 | private: |
2138 | - ColorType* _sort; |
2139 | + const ColorType* _sort; |
2140 | |
2141 | public: |
2142 | virtual ~AllExpression() {}; |
2143 | - std::vector<std::pair<const Color*,uint32_t>> eval(ExpressionContext& context) const { |
2144 | + std::vector<std::pair<const Color*,uint32_t>> eval(const ExpressionContext& context) const { |
2145 | std::vector<std::pair<const Color*,uint32_t>> colors; |
2146 | assert(_sort != nullptr); |
2147 | - if(context.placePartition.diagonal || context.placePartition._equivalenceClasses.empty()){ |
2148 | + if(context.placePartition.isDiagonal() || context.placePartition.getEquivalenceClasses().empty()){ |
2149 | for (size_t i = 0; i < _sort->size(); i++) { |
2150 | colors.push_back(std::make_pair(&(*_sort)[i], 1)); |
2151 | } |
2152 | } else { |
2153 | - for (auto EqClass : context.placePartition._equivalenceClasses){ |
2154 | - colors.push_back(std::make_pair(_sort->getColor(EqClass._colorIntervals.getLowerIds()),EqClass.size())); |
2155 | + for (const auto& eq_class : context.placePartition.getEquivalenceClasses()){ |
2156 | + colors.push_back(std::make_pair(_sort->getColor(eq_class.intervals().getLowerIds()),eq_class.size())); |
2157 | } |
2158 | } |
2159 | |
2160 | @@ -1075,34 +1019,33 @@ |
2161 | return _sort->productSize() > 1; |
2162 | } |
2163 | |
2164 | - void getConstants(std::unordered_map<uint32_t, std::vector<const Color*>> &constantMap, uint32_t &index) const { |
2165 | + void getConstants(PositionColorsMap &constantMap, uint32_t &index) const { |
2166 | for (size_t i = 0; i < _sort->size(); i++) { |
2167 | constantMap[index].push_back(&(*_sort)[i]); |
2168 | } |
2169 | } |
2170 | |
2171 | - Colored::intervalTuple_t getOutputIntervals(std::vector<std::unordered_map<const PetriEngine::Colored::Variable *, PetriEngine::Colored::intervalTuple_t>>& varMapVec, std::vector<const Colored::ColorType *> *colortypes) const { |
2172 | - Colored::intervalTuple_t newIntervalTuple; |
2173 | + Colored::interval_vector_t getOutputIntervals(const std::vector<VariableIntervalMap>& varMapVec, std::vector<const Colored::ColorType *> &colortypes) const { |
2174 | + Colored::interval_vector_t newIntervalTuple; |
2175 | newIntervalTuple.addInterval(_sort->getFullInterval()); |
2176 | return newIntervalTuple; |
2177 | } |
2178 | |
2179 | - bool getArcIntervals(Colored::ArcIntervals& arcIntervals, PetriEngine::Colored::ColorFixpoint& cfp, uint32_t *index, int32_t modifier) const { |
2180 | + bool getArcIntervals(Colored::ArcIntervals& arcIntervals,const PetriEngine::Colored::ColorFixpoint& cfp, uint32_t& index, int32_t modifier) const { |
2181 | |
2182 | if(arcIntervals._intervalTupleVec.empty()){ |
2183 | bool colorsInFixpoint = false; |
2184 | - Colored::intervalTuple_t newIntervalTuple; |
2185 | - cfp.constraints.simplify(); |
2186 | + Colored::interval_vector_t newIntervalTuple; |
2187 | if(cfp.constraints.getContainedColors() == _sort->size()){ |
2188 | colorsInFixpoint = true; |
2189 | - for(auto interval : cfp.constraints._intervals){ |
2190 | + for(const auto& interval : cfp.constraints){ |
2191 | newIntervalTuple.addInterval(interval); |
2192 | } |
2193 | } |
2194 | arcIntervals._intervalTupleVec.push_back(newIntervalTuple); |
2195 | return colorsInFixpoint; |
2196 | } else { |
2197 | - std::vector<Colored::intervalTuple_t> newIntervalTupleVec; |
2198 | + std::vector<Colored::interval_vector_t> newIntervalTupleVec; |
2199 | for(uint32_t i = 0; i < arcIntervals._intervalTupleVec.size(); i++){ |
2200 | auto& intervalTuple = arcIntervals._intervalTupleVec[i]; |
2201 | if(intervalTuple.getContainedColors() == _sort->size()){ |
2202 | @@ -1122,7 +1065,7 @@ |
2203 | return _sort->getName() + ".all"; |
2204 | } |
2205 | |
2206 | - AllExpression(ColorType* sort) : _sort(sort) |
2207 | + AllExpression(const ColorType* sort) : _sort(sort) |
2208 | { |
2209 | assert(sort != nullptr); |
2210 | } |
2211 | @@ -1137,10 +1080,10 @@ |
2212 | AllExpression_ptr _all; |
2213 | |
2214 | public: |
2215 | - Multiset eval(ExpressionContext& context) const override { |
2216 | + Multiset eval(const ExpressionContext& context) const override { |
2217 | std::vector<std::pair<const Color*,uint32_t>> col; |
2218 | if (!_color.empty()) { |
2219 | - for (auto elem : _color) { |
2220 | + for (const auto& elem : _color) { |
2221 | col.push_back(std::make_pair(elem->eval(context), _number)); |
2222 | } |
2223 | } else if (_all != nullptr) { |
2224 | @@ -1152,9 +1095,18 @@ |
2225 | |
2226 | return Multiset(col); |
2227 | } |
2228 | + bool isEligibleForSymmetry(std::vector<uint32_t>& numbers) const override{ |
2229 | + //Not entirely sure what to do if there is more than one colorExpression, but should probably return false |
2230 | + if(_color.size() > 1){ |
2231 | + return false; |
2232 | + } |
2233 | + numbers.emplace_back(_number); |
2234 | + //Maybe we need to check color expression also |
2235 | + return true; |
2236 | + } |
2237 | |
2238 | bool isTuple() const override { |
2239 | - for(auto colorExpr : _color){ |
2240 | + for(const auto& colorExpr : _color){ |
2241 | if(colorExpr->isTuple()){ |
2242 | return true; |
2243 | } |
2244 | @@ -1162,59 +1114,48 @@ |
2245 | return false; |
2246 | } |
2247 | |
2248 | - void getVariables(std::set<const Colored::Variable*>& variables, std::unordered_map<uint32_t, const Colored::Variable *>& varPositions, std::unordered_map<const Colored::Variable *, std::vector<std::unordered_map<uint32_t, int32_t>>>& varModifierMap, uint32_t *index) const override { |
2249 | + void getVariables(std::set<const Colored::Variable*>& variables, PositionVariableMap& varPositions, VariableModifierMap& varModifierMap, bool includeSubtracts, uint32_t& index) const override { |
2250 | if (_all != nullptr) |
2251 | return; |
2252 | - for (auto elem : _color) { |
2253 | + for (const auto& elem : _color) { |
2254 | //TODO: can there be more than one element in a number of expression? |
2255 | - elem->getVariables(variables, varPositions, varModifierMap, index); |
2256 | + elem->getVariables(variables, varPositions, varModifierMap, includeSubtracts, index); |
2257 | } |
2258 | } |
2259 | |
2260 | - bool getArcIntervals(Colored::ArcIntervals& arcIntervals, PetriEngine::Colored::ColorFixpoint& cfp, uint32_t *index, int32_t modifier) const override { |
2261 | + bool getArcIntervals(Colored::ArcIntervals& arcIntervals,const PetriEngine::Colored::ColorFixpoint& cfp, uint32_t& index, int32_t modifier) const override { |
2262 | if (_all != nullptr) { |
2263 | return _all->getArcIntervals(arcIntervals, cfp, index, modifier); |
2264 | } |
2265 | - //uint32_t i = 0; |
2266 | - for (auto elem : _color) { |
2267 | - //(*index) += i; |
2268 | + for (const auto& elem : _color) { |
2269 | if(!elem->getArcIntervals(arcIntervals, cfp, index, modifier)){ |
2270 | return false; |
2271 | } |
2272 | - //i++; |
2273 | } |
2274 | return true; |
2275 | } |
2276 | |
2277 | - Colored::intervalTuple_t getOutputIntervals(std::vector<std::unordered_map<const PetriEngine::Colored::Variable *, PetriEngine::Colored::intervalTuple_t>>& varMapVec, std::vector<const Colored::ColorType *> *colortypes) const override { |
2278 | - Colored::intervalTuple_t intervals; |
2279 | + std::vector<Colored::interval_vector_t> getOutputIntervals(const std::vector<VariableIntervalMap>& varMapVec, std::vector<const Colored::ColorType *> &colortypes) const override { |
2280 | + std::vector<Colored::interval_vector_t> intervalsVec; |
2281 | if (_all == nullptr) { |
2282 | - for (auto elem : _color) { |
2283 | - for(auto& varMap : varMapVec){ |
2284 | - auto nestedIntervals = elem->getOutputIntervals(varMap, colortypes); |
2285 | - |
2286 | - if (intervals._intervals.empty()) { |
2287 | - intervals = nestedIntervals; |
2288 | - } else { |
2289 | - for(auto interval : nestedIntervals._intervals) { |
2290 | - intervals.addInterval(interval); |
2291 | - } |
2292 | - } |
2293 | + for (const auto& elem : _color) { |
2294 | + for(const auto& varMap : varMapVec){ |
2295 | + intervalsVec.push_back(elem->getOutputIntervals(varMap, colortypes)); |
2296 | } |
2297 | } |
2298 | } else { |
2299 | - return _all->getOutputIntervals(varMapVec, colortypes); |
2300 | + intervalsVec.push_back(_all->getOutputIntervals(varMapVec, colortypes)); |
2301 | } |
2302 | - return intervals; |
2303 | + return intervalsVec; |
2304 | } |
2305 | |
2306 | - void getConstants(std::unordered_map<uint32_t, std::vector<const Color*>> &constantMap, uint32_t &index) const override { |
2307 | + void getConstants(PositionColorsMap &constantMap, uint32_t &index) const override { |
2308 | if (_all != nullptr) |
2309 | _all->getConstants(constantMap, index); |
2310 | - else for (auto elem : _color) { |
2311 | + else for (const auto& elem : _color) { |
2312 | std::unordered_map<uint32_t, const Color*> elemMap; |
2313 | elem->getConstants(elemMap, index); |
2314 | - for(auto pair : elemMap){ |
2315 | + for(const auto& pair : elemMap){ |
2316 | constantMap[pair.first].push_back(pair.second); |
2317 | } |
2318 | } |
2319 | @@ -1263,26 +1204,47 @@ |
2320 | std::vector<ArcExpression_ptr> _constituents; |
2321 | |
2322 | public: |
2323 | - Multiset eval(ExpressionContext& context) const override { |
2324 | + Multiset eval(const ExpressionContext& context) const override { |
2325 | Multiset ms; |
2326 | - for (auto expr : _constituents) { |
2327 | + for (const auto& expr : _constituents) { |
2328 | ms += expr->eval(context); |
2329 | } |
2330 | return ms; |
2331 | } |
2332 | + |
2333 | + bool isEligibleForSymmetry(std::vector<uint32_t>& numbers) const override{ |
2334 | + for(const auto& elem : _constituents){ |
2335 | + if(!elem->isEligibleForSymmetry(numbers)){ |
2336 | + return false; |
2337 | + } |
2338 | + } |
2339 | + |
2340 | + if(numbers.size() < 2){ |
2341 | + return false; |
2342 | + } |
2343 | + //pick a number |
2344 | + //every number has to be equal |
2345 | + uint32_t firstNumber = numbers[0]; |
2346 | + for(uint32_t number : numbers){ |
2347 | + if(firstNumber != number){ |
2348 | + return false; |
2349 | + } |
2350 | + } |
2351 | + return true; |
2352 | + } |
2353 | |
2354 | - void getVariables(std::set<const Colored::Variable*>& variables, std::unordered_map<uint32_t, const Colored::Variable *>& varPositions, std::unordered_map<const Colored::Variable *, std::vector<std::unordered_map<uint32_t, int32_t>>>& varModifierMap, uint32_t *index) const override { |
2355 | - for (auto elem : _constituents) { |
2356 | + void getVariables(std::set<const Colored::Variable*>& variables, PositionVariableMap& varPositions, VariableModifierMap& varModifierMap, bool includeSubtracts, uint32_t& index) const override { |
2357 | + for (const auto& elem : _constituents) { |
2358 | for(auto& pair : varModifierMap){ |
2359 | std::unordered_map<uint32_t, int32_t> newMap; |
2360 | pair.second.push_back(newMap); |
2361 | } |
2362 | - elem->getVariables(variables, varPositions, varModifierMap); |
2363 | + elem->getVariables(variables, varPositions, varModifierMap, includeSubtracts); |
2364 | } |
2365 | } |
2366 | |
2367 | bool isTuple() const override { |
2368 | - for(auto arcExpr : _constituents){ |
2369 | + for(const auto& arcExpr : _constituents){ |
2370 | if(arcExpr->isTuple()){ |
2371 | return true; |
2372 | } |
2373 | @@ -1290,13 +1252,13 @@ |
2374 | return false; |
2375 | } |
2376 | |
2377 | - bool getArcIntervals(Colored::ArcIntervals& arcIntervals, PetriEngine::Colored::ColorFixpoint& cfp, uint32_t *index, int32_t modifier) const override { |
2378 | - for (auto elem : _constituents) { |
2379 | + bool getArcIntervals(Colored::ArcIntervals& arcIntervals,const PetriEngine::Colored::ColorFixpoint& cfp, uint32_t& index, int32_t modifier) const override { |
2380 | + for (const auto& elem : _constituents) { |
2381 | uint32_t newIndex = 0; |
2382 | Colored::ArcIntervals newArcIntervals; |
2383 | std::vector<uint32_t> intervalsForRemoval; |
2384 | std::vector<Colored::interval_t> newIntervals; |
2385 | - if(!elem->getArcIntervals(newArcIntervals, cfp, &newIndex, modifier)){ |
2386 | + if(!elem->getArcIntervals(newArcIntervals, cfp, newIndex, modifier)){ |
2387 | return false; |
2388 | } |
2389 | |
2390 | @@ -1309,26 +1271,20 @@ |
2391 | return true; |
2392 | } |
2393 | |
2394 | - Colored::intervalTuple_t getOutputIntervals(std::vector<std::unordered_map<const PetriEngine::Colored::Variable *, PetriEngine::Colored::intervalTuple_t>>& varMapVec, std::vector<const Colored::ColorType *> *colortypes) const override { |
2395 | - Colored::intervalTuple_t intervals; |
2396 | + std::vector<Colored::interval_vector_t> getOutputIntervals(const std::vector<VariableIntervalMap>& varMapVec, std::vector<const Colored::ColorType *> &colortypes) const override { |
2397 | + std::vector<Colored::interval_vector_t> intervalsVec; |
2398 | |
2399 | - for (auto elem : _constituents) { |
2400 | + for (const auto& elem : _constituents) { |
2401 | auto nestedIntervals = elem->getOutputIntervals(varMapVec, colortypes); |
2402 | |
2403 | - if (intervals._intervals.empty()) { |
2404 | - intervals = nestedIntervals; |
2405 | - } else { |
2406 | - for(auto interval : nestedIntervals._intervals) { |
2407 | - intervals.addInterval(interval); |
2408 | - } |
2409 | - } |
2410 | + intervalsVec.insert(intervalsVec.end(), nestedIntervals.begin(), nestedIntervals.end()); |
2411 | } |
2412 | - return intervals; |
2413 | + return intervalsVec; |
2414 | } |
2415 | |
2416 | - void getConstants(std::unordered_map<uint32_t, std::vector<const Color*>> &constantMap, uint32_t &index) const override { |
2417 | + void getConstants(PositionColorsMap &constantMap, uint32_t &index) const override { |
2418 | uint32_t indexCopy = index; |
2419 | - for (auto elem : _constituents) { |
2420 | + for (const auto& elem : _constituents) { |
2421 | uint32_t localIndex = indexCopy; |
2422 | elem->getConstants(constantMap, localIndex); |
2423 | } |
2424 | @@ -1336,7 +1292,7 @@ |
2425 | |
2426 | uint32_t weight() const override { |
2427 | uint32_t res = 0; |
2428 | - for (auto expr : _constituents) { |
2429 | + for (const auto& expr : _constituents) { |
2430 | res += expr->weight(); |
2431 | } |
2432 | return res; |
2433 | @@ -1360,34 +1316,34 @@ |
2434 | ArcExpression_ptr _right; |
2435 | |
2436 | public: |
2437 | - Multiset eval(ExpressionContext& context) const override { |
2438 | + Multiset eval(const ExpressionContext& context) const override { |
2439 | return _left->eval(context) - _right->eval(context); |
2440 | } |
2441 | |
2442 | - void getVariables(std::set<const Colored::Variable*>& variables, std::unordered_map<uint32_t, const Colored::Variable *>& varPositions, std::unordered_map<const Colored::Variable *, std::vector<std::unordered_map<uint32_t, int32_t>>>& varModifierMap, uint32_t *index) const override { |
2443 | - _left->getVariables(variables, varPositions, varModifierMap); |
2444 | + void getVariables(std::set<const Colored::Variable*>& variables, PositionVariableMap& varPositions, VariableModifierMap& varModifierMap, bool includeSubtracts, uint32_t& index) const override { |
2445 | + _left->getVariables(variables, varPositions, varModifierMap, includeSubtracts); |
2446 | //We ignore the restrictions imposed by the subtraction for now |
2447 | - //_right->getVariables(variables, varPositions, varModifierMap); |
2448 | + if(includeSubtracts){ |
2449 | + _right->getVariables(variables, varPositions, varModifierMap, includeSubtracts); |
2450 | + } |
2451 | } |
2452 | |
2453 | bool isTuple() const override { |
2454 | return _left->isTuple() || _right->isTuple(); |
2455 | } |
2456 | |
2457 | - bool getArcIntervals(Colored::ArcIntervals& arcIntervals, PetriEngine::Colored::ColorFixpoint& cfp, uint32_t *index, int32_t modifier) const override { |
2458 | + bool getArcIntervals(Colored::ArcIntervals& arcIntervals, const PetriEngine::Colored::ColorFixpoint& cfp, uint32_t& index, int32_t modifier) const override { |
2459 | return _left->getArcIntervals(arcIntervals, cfp, index, modifier); |
2460 | //We ignore the restrictions imposed by the subtraction for now |
2461 | //_right->getArcIntervals(arcIntervals, cfp, &rightIndex); |
2462 | } |
2463 | |
2464 | - Colored::intervalTuple_t getOutputIntervals(std::vector<std::unordered_map<const PetriEngine::Colored::Variable *, PetriEngine::Colored::intervalTuple_t>>& varMapVec, std::vector<const Colored::ColorType *> *colortypes) const override { |
2465 | + std::vector<Colored::interval_vector_t> getOutputIntervals(const std::vector<VariableIntervalMap>& varMapVec, std::vector<const Colored::ColorType *> &colortypes) const override { |
2466 | //We could maybe reduce the intervals slightly by checking if the upper or lower bound is being subtracted |
2467 | - auto leftIntervals = _left->getOutputIntervals(varMapVec, colortypes); |
2468 | - |
2469 | - return leftIntervals; |
2470 | + return _left->getOutputIntervals(varMapVec, colortypes); |
2471 | } |
2472 | |
2473 | - void getConstants(std::unordered_map<uint32_t, std::vector<const Color*>> &constantMap, uint32_t &index) const override { |
2474 | + void getConstants(PositionColorsMap &constantMap, uint32_t &index) const override { |
2475 | uint32_t rIndex = index; |
2476 | _left->getConstants(constantMap, index); |
2477 | _right->getConstants(constantMap, rIndex); |
2478 | @@ -1421,27 +1377,27 @@ |
2479 | ArcExpression_ptr _expr; |
2480 | |
2481 | public: |
2482 | - Multiset eval(ExpressionContext& context) const override { |
2483 | + Multiset eval(const ExpressionContext& context) const override { |
2484 | return _expr->eval(context) * _scalar; |
2485 | } |
2486 | |
2487 | - void getVariables(std::set<const Colored::Variable*>& variables, std::unordered_map<uint32_t, const Colored::Variable *>& varPositions, std::unordered_map<const Colored::Variable *, std::vector<std::unordered_map<uint32_t, int32_t>>>& varModifierMap, uint32_t *index) const override { |
2488 | - _expr->getVariables(variables, varPositions,varModifierMap); |
2489 | + void getVariables(std::set<const Colored::Variable*>& variables, PositionVariableMap& varPositions, VariableModifierMap& varModifierMap, bool includeSubtracts, uint32_t& index) const override { |
2490 | + _expr->getVariables(variables, varPositions,varModifierMap, includeSubtracts); |
2491 | } |
2492 | |
2493 | bool isTuple() const override { |
2494 | return _expr->isTuple(); |
2495 | } |
2496 | |
2497 | - bool getArcIntervals(Colored::ArcIntervals& arcIntervals, PetriEngine::Colored::ColorFixpoint& cfp, uint32_t *index, int32_t modifier) const override { |
2498 | + bool getArcIntervals(Colored::ArcIntervals& arcIntervals,const PetriEngine::Colored::ColorFixpoint& cfp, uint32_t& index, int32_t modifier) const override { |
2499 | return _expr ->getArcIntervals(arcIntervals, cfp, index, modifier); |
2500 | } |
2501 | |
2502 | - Colored::intervalTuple_t getOutputIntervals(std::vector<std::unordered_map<const PetriEngine::Colored::Variable *, PetriEngine::Colored::intervalTuple_t>>& varMapVec, std::vector<const Colored::ColorType *> *colortypes) const override { |
2503 | + std::vector<Colored::interval_vector_t> getOutputIntervals(const std::vector<VariableIntervalMap>& varMapVec, std::vector<const Colored::ColorType *> &colortypes) const override { |
2504 | return _expr->getOutputIntervals(varMapVec, colortypes); |
2505 | } |
2506 | |
2507 | - void getConstants(std::unordered_map<uint32_t, std::vector<const Color*>> &constantMap, uint32_t &index) const override { |
2508 | + void getConstants(PositionColorsMap &constantMap, uint32_t &index) const override { |
2509 | _expr->getConstants(constantMap, index); |
2510 | } |
2511 | |
2512 | |
2513 | === modified file 'include/PetriEngine/Colored/GuardRestrictor.h' |
2514 | --- include/PetriEngine/Colored/GuardRestrictor.h 2021-04-14 10:41:18 +0000 |
2515 | +++ include/PetriEngine/Colored/GuardRestrictor.h 2021-07-07 08:15:00 +0000 |
2516 | @@ -33,90 +33,109 @@ |
2517 | |
2518 | GuardRestrictor(); |
2519 | |
2520 | - void restrictDiagonal(std::vector<std::unordered_map<const Colored::Variable *, Colored::intervalTuple_t>>& variableMap, |
2521 | - std::unordered_map<const Colored::Variable *,std::vector<std::unordered_map<uint32_t, int32_t>>> *varModifierMapL, |
2522 | - std::unordered_map<const Colored::Variable *,std::vector<std::unordered_map<uint32_t, int32_t>>> *varModifierMapR, |
2523 | - std::unordered_map<uint32_t, const Colored::Variable *> *varPositionsL, |
2524 | - std::unordered_map<uint32_t, const Colored::Variable *> *varPositionsR, |
2525 | - std::unordered_map<uint32_t, const Color*> *constantMapL, |
2526 | - std::unordered_map<uint32_t, const Color*> *constantMapR, |
2527 | + void restrictDiagonal(std::vector<VariableIntervalMap>& variableMap, |
2528 | + const VariableModifierMap &varModifierMapL, |
2529 | + const VariableModifierMap &varModifierMapR, |
2530 | + const PositionVariableMap &varPositionsL, |
2531 | + const PositionVariableMap &varPositionsR, |
2532 | + const std::unordered_map<uint32_t, const Color*> &constantMapL, |
2533 | + const std::unordered_map<uint32_t, const Color*> &constantMapR, |
2534 | std::set<const Colored::Variable*> &diagonalVars, |
2535 | const Colored::Variable *var, |
2536 | - uint32_t index, bool lessthan, bool strict); |
2537 | + uint32_t index, bool lessthan, bool strict) const; |
2538 | |
2539 | |
2540 | |
2541 | - void restrictEquality(std::vector<std::unordered_map<const Colored::Variable *, Colored::intervalTuple_t>>& variableMap, |
2542 | - std::unordered_map<const Colored::Variable *,std::vector<std::unordered_map<uint32_t, int32_t>>> *varModifierMapL, |
2543 | - std::unordered_map<const Colored::Variable *,std::vector<std::unordered_map<uint32_t, int32_t>>> *varModifierMapR, |
2544 | - std::unordered_map<uint32_t, const Colored::Variable *> *varPositionsL, |
2545 | - std::unordered_map<uint32_t, const Colored::Variable *> *varPositionsR, |
2546 | - std::unordered_map<uint32_t, const Color*> *constantMapL, |
2547 | - std::unordered_map<uint32_t, const Color*> *constantMapR, |
2548 | - std::set<const Colored::Variable*> &diagonalVars); |
2549 | - |
2550 | - void restrictVars(std::vector<std::unordered_map<const Colored::Variable *, Colored::intervalTuple_t>>& variableMap, |
2551 | - std::unordered_map<const Colored::Variable *,std::vector<std::unordered_map<uint32_t, int32_t>>> *varModifierMapL, |
2552 | - std::unordered_map<const Colored::Variable *,std::vector<std::unordered_map<uint32_t, int32_t>>> *varModifierMapR, |
2553 | - std::unordered_map<uint32_t, const Colored::Variable *> *varPositionsL, |
2554 | - std::unordered_map<uint32_t, const Colored::Variable *> *varPositionsR, |
2555 | - std::unordered_map<uint32_t, const Color*> *constantMapL, |
2556 | - std::unordered_map<uint32_t, const Color*> *constantMapR, |
2557 | + void restrictEquality(std::vector<VariableIntervalMap>& variableMap, |
2558 | + const VariableModifierMap &varModifierMapL, |
2559 | + const VariableModifierMap &varModifierMapR, |
2560 | + const PositionVariableMap &varPositionsL, |
2561 | + const PositionVariableMap &varPositionsR, |
2562 | + const std::unordered_map<uint32_t, const Color*> &constantMapL, |
2563 | + const std::unordered_map<uint32_t, const Color*> &constantMapR, |
2564 | + std::set<const Colored::Variable*> &diagonalVars) const; |
2565 | + |
2566 | + void restrictInEquality(std::vector<VariableIntervalMap>& variableMap, |
2567 | + const VariableModifierMap &varModifierMapL, |
2568 | + const VariableModifierMap &varModifierMapR, |
2569 | + const PositionVariableMap &varPositionsL, |
2570 | + const PositionVariableMap &varPositionsR, |
2571 | + const std::unordered_map<uint32_t, const Color*> &constantMapL, |
2572 | + const std::unordered_map<uint32_t, const Color*> &constantMapR, |
2573 | + std::set<const Colored::Variable*> &diagonalVars) const; |
2574 | + |
2575 | + void restrictVars(std::vector<VariableIntervalMap>& variableMap, |
2576 | + const VariableModifierMap &varModifierMapL, |
2577 | + const VariableModifierMap &varModifierMapR, |
2578 | + const PositionVariableMap &varPositionsL, |
2579 | + const PositionVariableMap &varPositionsR, |
2580 | + const std::unordered_map<uint32_t, const Color*> &constantMapL, |
2581 | + const std::unordered_map<uint32_t, const Color*> &constantMapR, |
2582 | std::set<const Colored::Variable*> &diagonalVars, |
2583 | - bool lessthan, bool strict); |
2584 | + bool lessthan, bool strict) const; |
2585 | |
2586 | - intervalTuple_t shiftIntervals(std::unordered_map<const Variable *, intervalTuple_t>& varMap, |
2587 | - std::vector<const ColorType *> *colortypes, intervalTuple_t *intervals, |
2588 | + interval_vector_t shiftIntervals(const VariableIntervalMap& varMap, |
2589 | + const std::vector<const ColorType *> &colortypes, interval_vector_t &intervals, |
2590 | int32_t modifier, uint32_t ctSizeBefore) const; |
2591 | |
2592 | private: |
2593 | - int32_t getVarModifier(std::unordered_map<uint32_t, int32_t> *modPairMap, uint32_t index); |
2594 | - interval_t getIntervalFromIds(std::vector<uint32_t> *idVec, uint32_t ctSize, int32_t modifier); |
2595 | - intervalTuple_t getIntervalOverlap(std::vector<Colored::interval_t> *intervals1, std::vector<Colored::interval_t> *intervals2); |
2596 | - |
2597 | - void expandIdVec(std::unordered_map<const Variable *, intervalTuple_t> *varMap, |
2598 | - std::unordered_map<const Variable *,std::vector<std::unordered_map<uint32_t, int32_t>>> *mainVarModifierMap, |
2599 | - std::unordered_map<const Variable *,std::vector<std::unordered_map<uint32_t, int32_t>>> *otherVarModifierMap, |
2600 | - std::unordered_map<uint32_t, const Variable *> *varPositions, |
2601 | - std::unordered_map<uint32_t, const Color*> *constantMap, |
2602 | - const Variable *otherVar, |
2603 | - std::vector<uint32_t> &idVec, size_t targetSize, uint32_t index); |
2604 | - |
2605 | - void expandIntervalVec(std::unordered_map<const Variable *, intervalTuple_t> varMap, |
2606 | - std::unordered_map<const Variable *,std::vector<std::unordered_map<uint32_t, int32_t>>> *mainVarModifierMap, |
2607 | - std::unordered_map<const Variable *,std::vector<std::unordered_map<uint32_t, int32_t>>> *otherVarModifierMap, |
2608 | - std::unordered_map<uint32_t, const Variable *> *varPositions, |
2609 | - std::unordered_map<uint32_t, const Color*> *constantMap, |
2610 | - const Variable *otherVar, |
2611 | - std::vector<interval_t> &intervalVec, size_t targetSize, uint32_t index); |
2612 | - |
2613 | - void restrictByConstant(std::vector<std::unordered_map<const Colored::Variable *, Colored::intervalTuple_t>>& variableMap, |
2614 | - std::unordered_map<const Colored::Variable *,std::vector<std::unordered_map<uint32_t, int32_t>>> *mainVarModifierMap, |
2615 | - std::unordered_map<const Colored::Variable *,std::vector<std::unordered_map<uint32_t, int32_t>>> *otherVarModifierMap, |
2616 | - std::unordered_map<uint32_t, const Colored::Variable *> *varPositions, |
2617 | - std::unordered_map<uint32_t, const Color*> *constantMap, |
2618 | + int32_t getVarModifier(const std::unordered_map<uint32_t, int32_t> &modPairMap, uint32_t index) const; |
2619 | + interval_t getIntervalFromIds(const std::vector<uint32_t> &idVec, uint32_t ctSize, int32_t modifier) const; |
2620 | + interval_vector_t getIntervalOverlap(const Colored::interval_vector_t &intervals1, const Colored::interval_vector_t &intervals2) const; |
2621 | + void invertIntervals(interval_vector_t &intervals, const interval_vector_t &oldIntervals, const ColorType *colorType) const; |
2622 | + |
2623 | + |
2624 | + void handleInequalityConstants(const std::vector<VariableIntervalMap> &variableMapCopy, |
2625 | + std::vector<VariableIntervalMap> &variableMap, |
2626 | + const Variable *var, uint32_t varMapIndex) const; |
2627 | + |
2628 | + void handleInequalityVars(const std::vector<VariableIntervalMap> &variableMapCopy, |
2629 | + std::vector<VariableIntervalMap> &variableMap, |
2630 | + const Variable *var1, const Variable *var2, uint32_t varMapIndex) const; |
2631 | + |
2632 | + void expandIdVec(const VariableIntervalMap &varMap, |
2633 | + const VariableModifierMap &mainVarModifierMap, |
2634 | + const VariableModifierMap &otherVarModifierMap, |
2635 | + const std::unordered_map<uint32_t, const Variable *> &varPositions, |
2636 | + const std::unordered_map<uint32_t, const Color*> &constantMap, |
2637 | + const Variable *otherVar, |
2638 | + std::vector<uint32_t> &idVec, size_t targetSize, uint32_t index) const; |
2639 | + |
2640 | + void expandIntervalVec(const VariableIntervalMap &varMap, |
2641 | + const VariableModifierMap &mainVarModifierMap, |
2642 | + const VariableModifierMap &otherVarModifierMap, |
2643 | + const std::unordered_map<uint32_t, const Variable *> &varPositions, |
2644 | + const std::unordered_map<uint32_t, const Color*> &constantMap, |
2645 | + const Variable *otherVar, |
2646 | + interval_vector_t &intervalVec, size_t targetSize, uint32_t index) const; |
2647 | + |
2648 | + void restrictByConstant(std::vector<VariableIntervalMap>& variableMap, |
2649 | + const VariableModifierMap &mainVarModifierMap, |
2650 | + const VariableModifierMap &otherVarModifierMap, |
2651 | + const PositionVariableMap &varPositions, |
2652 | + const std::unordered_map<uint32_t, const Color*> &constantMap, |
2653 | const Colored::Variable *var, |
2654 | const Colored::Variable *otherVar, |
2655 | - uint32_t index, bool lessthan, bool strict); |
2656 | + uint32_t index, bool lessthan, bool strict) const; |
2657 | |
2658 | - void restrictEqByConstant(std::vector<std::unordered_map<const Colored::Variable *, Colored::intervalTuple_t>>& variableMap, |
2659 | - std::unordered_map<const Colored::Variable *,std::vector<std::unordered_map<uint32_t, int32_t>>> *mainVarModifierMap, |
2660 | - std::unordered_map<const Colored::Variable *,std::vector<std::unordered_map<uint32_t, int32_t>>> *otherVarModifierMap, |
2661 | - std::unordered_map<uint32_t, const Colored::Variable *> *varPositions, |
2662 | - std::unordered_map<uint32_t, const Color*> *constantMap, |
2663 | + void restrictEqByConstant(std::vector<VariableIntervalMap>& variableMap, |
2664 | + const VariableModifierMap &mainVarModifierMap, |
2665 | + const VariableModifierMap &otherVarModifierMap, |
2666 | + const PositionVariableMap &varPositions, |
2667 | + const std::unordered_map<uint32_t, const Color*> &constantMap, |
2668 | const Colored::Variable *var, |
2669 | - uint32_t index); |
2670 | + uint32_t index) const; |
2671 | |
2672 | - void restrictEqDiagonal(std::vector<std::unordered_map<const Colored::Variable *, Colored::intervalTuple_t>>& variableMap, |
2673 | - std::unordered_map<const Colored::Variable *,std::vector<std::unordered_map<uint32_t, int32_t>>> *varModifierMapL, |
2674 | - std::unordered_map<const Colored::Variable *,std::vector<std::unordered_map<uint32_t, int32_t>>> *varModifierMapR, |
2675 | - std::unordered_map<uint32_t, const Colored::Variable *> *varPositionsL, |
2676 | - std::unordered_map<uint32_t, const Colored::Variable *> *varPositionsR, |
2677 | - std::unordered_map<uint32_t, const Color*> *constantMapL, |
2678 | - std::unordered_map<uint32_t, const Color*> *constantMapR, |
2679 | + void restrictEqDiagonal(std::vector<VariableIntervalMap>& variableMap, |
2680 | + const VariableModifierMap &varModifierMapL, |
2681 | + const VariableModifierMap &varModifierMapR, |
2682 | + const PositionVariableMap &varPositionsL, |
2683 | + const PositionVariableMap &varPositionsR, |
2684 | + const std::unordered_map<uint32_t, const Color*> &constantMapL, |
2685 | + const std::unordered_map<uint32_t, const Color*> &constantMapR, |
2686 | std::set<const Colored::Variable*> &diagonalVars, |
2687 | const Colored::Variable *var, |
2688 | - uint32_t index); |
2689 | + uint32_t index) const; |
2690 | }; |
2691 | } |
2692 | } |
2693 | |
2694 | === modified file 'include/PetriEngine/Colored/IntervalGenerator.h' |
2695 | --- include/PetriEngine/Colored/IntervalGenerator.h 2021-04-14 10:41:18 +0000 |
2696 | +++ include/PetriEngine/Colored/IntervalGenerator.h 2021-07-07 08:15:00 +0000 |
2697 | @@ -21,178 +21,28 @@ |
2698 | #include "ColoredNetStructures.h" |
2699 | |
2700 | namespace PetriEngine { |
2701 | - struct IntervalGenerator { |
2702 | - std::vector<Colored::interval_t> getIntervalsFromInterval(Colored::interval_t *interval, uint32_t varPosition, int32_t varModifier, std::vector<Colored::ColorType*> *varColorTypes){ |
2703 | - std::vector<Colored::interval_t> varIntervals; |
2704 | - Colored::interval_t firstVarInterval; |
2705 | - varIntervals.push_back(firstVarInterval); |
2706 | - for(uint32_t i = varPosition; i < varPosition + varColorTypes->size(); i++){ |
2707 | - auto ctSize = varColorTypes->operator[](i - varPosition)->size(); |
2708 | - int32_t lower_val = ctSize + (interval->operator[](i)._lower + varModifier); |
2709 | - int32_t upper_val = ctSize + (interval->operator[](i)._upper + varModifier); |
2710 | - uint32_t lower = lower_val % ctSize; |
2711 | - uint32_t upper = upper_val % ctSize; |
2712 | - |
2713 | - if(lower > upper ){ |
2714 | - if(lower == upper+1){ |
2715 | - for (auto& varInterval : varIntervals){ |
2716 | - varInterval.addRange(0, ctSize -1); |
2717 | - } |
2718 | - } else { |
2719 | - std::vector<Colored::interval_t> newIntervals; |
2720 | - for (auto& varInterval : varIntervals){ |
2721 | - Colored::interval_t newVarInterval = varInterval; |
2722 | - varInterval.addRange(0, upper); |
2723 | - newVarInterval.addRange(lower, ctSize -1); |
2724 | - newIntervals.push_back(newVarInterval); |
2725 | - } |
2726 | - varIntervals.insert(varIntervals.end(), newIntervals.begin(), newIntervals.end()); |
2727 | - } |
2728 | - } else { |
2729 | - for (auto& varInterval : varIntervals){ |
2730 | - varInterval.addRange(lower, upper); |
2731 | - } |
2732 | - } |
2733 | - } |
2734 | - return varIntervals; |
2735 | - } |
2736 | - |
2737 | - void getArcVarIntervals(Colored::intervalTuple_t& varIntervals, std::unordered_map<uint32_t, int32_t> *modIndexMap, Colored::interval_t *interval, std::vector<Colored::ColorType*> *varColorTypes){ |
2738 | - for(auto& posModPair : *modIndexMap){ |
2739 | - auto intervals = getIntervalsFromInterval(interval, posModPair.first, posModPair.second, varColorTypes); |
2740 | - |
2741 | - if(varIntervals._intervals.empty()){ |
2742 | - for(auto& interval : intervals){ |
2743 | - varIntervals.addInterval(std::move(interval)); |
2744 | - } |
2745 | - } else { |
2746 | - Colored::intervalTuple_t newVarIntervals; |
2747 | - for(uint32_t i = 0; i < varIntervals.size(); i++){ |
2748 | - auto varInterval = &varIntervals[i]; |
2749 | - for(auto& interval : intervals){ |
2750 | - auto overlap = varInterval->getOverlap(std::move(interval)); |
2751 | - if(overlap.isSound()){ |
2752 | - newVarIntervals.addInterval(std::move(overlap)); |
2753 | - //break; |
2754 | - } |
2755 | - } |
2756 | - } |
2757 | - varIntervals = std::move(newVarIntervals); |
2758 | - } |
2759 | - } |
2760 | - } |
2761 | - |
2762 | - void populateLocalMap(Colored::ArcIntervals *arcIntervals, |
2763 | - std::unordered_map<const PetriEngine::Colored::Variable *, PetriEngine::Colored::intervalTuple_t> &varMap, |
2764 | - std::unordered_map<const Colored::Variable *, Colored::intervalTuple_t> &localVarMap, |
2765 | - Colored::interval_t* interval, bool& allVarsAssigned, uint32_t tuplePos){ |
2766 | - for(auto& pair : arcIntervals->_varIndexModMap){ |
2767 | - Colored::intervalTuple_t varIntervals; |
2768 | - std::vector<Colored::ColorType*> varColorTypes; |
2769 | - pair.first->colorType->getColortypes(varColorTypes); |
2770 | - |
2771 | - getArcVarIntervals(varIntervals, &pair.second[tuplePos], interval, &varColorTypes); |
2772 | - |
2773 | - if (arcIntervals->_intervalTupleVec.size() > 1 && pair.second[tuplePos].empty()) { |
2774 | - //The variable is not on this side of the add expression, so we add a full interval to compare against for the other side |
2775 | - varIntervals.addInterval(pair.first->colorType->getFullInterval()); |
2776 | - } |
2777 | - |
2778 | - if(varMap.count(pair.first) == 0){ |
2779 | - localVarMap[pair.first] = std::move(varIntervals); |
2780 | - } else { |
2781 | - for(auto& varInterval : varIntervals._intervals){ |
2782 | - for(auto& interval : varMap[pair.first]._intervals){ |
2783 | - auto overlapInterval = varInterval.getOverlap(interval); |
2784 | - |
2785 | - if(overlapInterval.isSound()){ |
2786 | - localVarMap[pair.first].addInterval(overlapInterval); |
2787 | - } |
2788 | - } |
2789 | - } |
2790 | - } |
2791 | - |
2792 | - if(localVarMap[pair.first]._intervals.empty()){ |
2793 | - allVarsAssigned = false; |
2794 | - } |
2795 | - } |
2796 | - } |
2797 | - |
2798 | - void fillVarMaps(std::vector<std::unordered_map<const PetriEngine::Colored::Variable *, PetriEngine::Colored::intervalTuple_t>> &variableMaps, |
2799 | - Colored::ArcIntervals *arcIntervals, |
2800 | - uint32_t *intervalTupleSize, |
2801 | - uint32_t *tuplePos) |
2802 | - { |
2803 | - for(uint32_t i = 0; i < *intervalTupleSize; i++){ |
2804 | - std::unordered_map<const Colored::Variable *, Colored::intervalTuple_t> localVarMap; |
2805 | - bool validInterval = true; |
2806 | - auto interval = &arcIntervals->_intervalTupleVec[*tuplePos]._intervals[i]; |
2807 | - |
2808 | - for(auto pair : arcIntervals->_varIndexModMap){ |
2809 | - Colored::intervalTuple_t varIntervals; |
2810 | - std::vector<Colored::ColorType*> varColorTypes; |
2811 | - pair.first->colorType->getColortypes(varColorTypes); |
2812 | - getArcVarIntervals(varIntervals, &pair.second[*tuplePos], interval, &varColorTypes); |
2813 | - |
2814 | - if(arcIntervals->_intervalTupleVec.size() > 1 && pair.second[*tuplePos].empty()){ |
2815 | - //The variable is not on this side of the add expression, so we add a full interval to compare against for the other side |
2816 | - varIntervals.addInterval(pair.first->colorType->getFullInterval()); |
2817 | - } else if(varIntervals.size() < 1){ |
2818 | - //If any varinterval ends up empty then we were unable to use this arc interval |
2819 | - validInterval = false; |
2820 | - break; |
2821 | - } |
2822 | - localVarMap[pair.first] = varIntervals; |
2823 | - } |
2824 | - |
2825 | - if(validInterval){ |
2826 | - variableMaps.push_back(localVarMap); |
2827 | - } |
2828 | - } |
2829 | - } |
2830 | - |
2831 | - bool getVarIntervals(std::vector<std::unordered_map<const Colored::Variable *, Colored::intervalTuple_t>>& variableMaps, std::unordered_map<uint32_t, Colored::ArcIntervals> placeArcIntervals){ |
2832 | - for(auto& placeArcInterval : placeArcIntervals){ |
2833 | - for(uint32_t j = 0; j < placeArcInterval.second._intervalTupleVec.size(); j++){ |
2834 | - uint32_t intervalTupleSize = placeArcInterval.second._intervalTupleVec[j].size(); |
2835 | - //If we have not found intervals for any place yet, we fill the intervals from this place |
2836 | - //Else we restrict the intervals we already found to only keep those that can also be matched in this place |
2837 | - if(variableMaps.empty()){ |
2838 | - fillVarMaps(variableMaps, &placeArcInterval.second, &intervalTupleSize, &j); |
2839 | - } else { |
2840 | - std::vector<std::unordered_map<const Colored::Variable *, Colored::intervalTuple_t>> newVarMapVec; |
2841 | - |
2842 | - for(auto& varMap : variableMaps){ |
2843 | - for(uint32_t i = 0; i < intervalTupleSize; i++){ |
2844 | - std::unordered_map<const Colored::Variable *, Colored::intervalTuple_t> localVarMap; |
2845 | - bool allVarsAssigned = true; |
2846 | - auto interval = &placeArcInterval.second._intervalTupleVec[j]._intervals[i]; |
2847 | - |
2848 | - populateLocalMap(&placeArcInterval.second, varMap, localVarMap, interval, allVarsAssigned, j); |
2849 | - |
2850 | - for(auto& varTuplePair : varMap){ |
2851 | - if(localVarMap.count(varTuplePair.first) == 0){ |
2852 | - localVarMap[varTuplePair.first] = std::move(varTuplePair.second); |
2853 | - } |
2854 | - } |
2855 | - |
2856 | - if(allVarsAssigned){ |
2857 | - newVarMapVec.push_back(std::move(localVarMap)); |
2858 | - } |
2859 | - |
2860 | - } |
2861 | - } |
2862 | - variableMaps = std::move(newVarMapVec); |
2863 | - } |
2864 | - //If we did not find any intervals for an arc, then the transition cannot be activated |
2865 | - if(variableMaps.empty()){ |
2866 | - return false; |
2867 | - } |
2868 | - } |
2869 | - } |
2870 | - return true; |
2871 | - } |
2872 | - }; |
2873 | + namespace Colored { |
2874 | + class IntervalGenerator { |
2875 | + public: |
2876 | + IntervalGenerator(); |
2877 | + bool getVarIntervals(std::vector<VariableIntervalMap>& variableMaps, const std::unordered_map<uint32_t, ArcIntervals> &placeArcIntervals) const; |
2878 | + private: |
2879 | + |
2880 | + std::vector<interval_t> getIntervalsFromInterval(const interval_t &interval, uint32_t varPosition, int32_t varModifier, const std::vector<const ColorType*> &varColorTypes) const; |
2881 | + |
2882 | + void getArcVarIntervals(interval_vector_t& varIntervals, const std::unordered_map<uint32_t, int32_t> &modIndexMap, const interval_t &interval, const std::vector<const ColorType*> &varColorTypes) const; |
2883 | + |
2884 | + void populateLocalMap(const ArcIntervals &arcIntervals, |
2885 | + const VariableIntervalMap &varMap, |
2886 | + VariableIntervalMap &localVarMap, |
2887 | + const interval_t &interval, bool& allVarsAssigned, uint32_t tuplePos) const; |
2888 | + |
2889 | + void fillVarMaps(std::vector<VariableIntervalMap> &variableMaps, |
2890 | + const ArcIntervals &arcIntervals, |
2891 | + const uint32_t &intervalTupleSize, |
2892 | + const uint32_t &tuplePos) const; |
2893 | + }; |
2894 | + } |
2895 | } |
2896 | |
2897 | #endif /* INTERVALGENERATOR_H */ |
2898 | \ No newline at end of file |
2899 | |
2900 | === modified file 'include/PetriEngine/Colored/Intervals.h' |
2901 | --- include/PetriEngine/Colored/Intervals.h 2021-04-22 12:43:03 +0000 |
2902 | +++ include/PetriEngine/Colored/Intervals.h 2021-07-07 08:15:00 +0000 |
2903 | @@ -41,26 +41,15 @@ |
2904 | |
2905 | ~interval_t(){} |
2906 | |
2907 | - interval_t(std::vector<Reachability::range_t> ranges) : _ranges(ranges) { |
2908 | + interval_t(const std::vector<Reachability::range_t>& ranges) : _ranges(ranges) { |
2909 | } |
2910 | |
2911 | - size_t size(){ |
2912 | + size_t size() const { |
2913 | return _ranges.size(); |
2914 | } |
2915 | |
2916 | - uint32_t intervalCombinations(){ |
2917 | - uint32_t product = 1; |
2918 | - for(auto range : _ranges){ |
2919 | - product *= range.size(); |
2920 | - } |
2921 | - if(_ranges.empty()){ |
2922 | - return 0; |
2923 | - } |
2924 | - return product; |
2925 | - } |
2926 | - |
2927 | - bool isSound(){ |
2928 | - for(auto range: _ranges) { |
2929 | + bool isSound() const { |
2930 | + for(const auto& range: _ranges) { |
2931 | if(!range.isSound()){ |
2932 | return false; |
2933 | } |
2934 | @@ -68,8 +57,12 @@ |
2935 | return true; |
2936 | } |
2937 | |
2938 | - void addRange(Reachability::range_t newRange) { |
2939 | - _ranges.push_back(newRange); |
2940 | + void addRange(Reachability::range_t&& newRange) { |
2941 | + _ranges.emplace_back(newRange); |
2942 | + } |
2943 | + |
2944 | + void addRange(const Reachability::range_t& newRange) { |
2945 | + _ranges.emplace_back(newRange); |
2946 | } |
2947 | |
2948 | void addRange(Reachability::range_t newRange, uint32_t index){ |
2949 | @@ -77,59 +70,37 @@ |
2950 | } |
2951 | |
2952 | void addRange(uint32_t l, uint32_t u) { |
2953 | - _ranges.push_back(Reachability::range_t(l, u)); |
2954 | - } |
2955 | - |
2956 | - void addRange(uint32_t lower, uint32_t upper, uint32_t index){ |
2957 | - _ranges.insert(_ranges.begin() + index, Reachability::range_t(lower, upper)); |
2958 | + _ranges.emplace_back(l, u); |
2959 | } |
2960 | |
2961 | Reachability::range_t& operator[] (size_t index) { |
2962 | - return _ranges[index]; |
2963 | - } |
2964 | - |
2965 | - Reachability::range_t& operator[] (int index) { |
2966 | - return _ranges[index]; |
2967 | - } |
2968 | - |
2969 | - Reachability::range_t& operator[] (uint32_t index) { |
2970 | assert(index < _ranges.size()); |
2971 | return _ranges[index]; |
2972 | } |
2973 | - |
2974 | - Reachability::range_t& getFirst() { |
2975 | - return _ranges[0]; |
2976 | - } |
2977 | - |
2978 | - Reachability::range_t& getLast() { |
2979 | - return _ranges.back(); |
2980 | - } |
2981 | - |
2982 | - std::vector<uint32_t> getLowerIds(){ |
2983 | + |
2984 | + const Reachability::range_t& operator[] (size_t index) const { |
2985 | + |
2986 | + return _ranges[index]; |
2987 | + } |
2988 | + |
2989 | + |
2990 | + std::vector<uint32_t> getLowerIds() const { |
2991 | std::vector<uint32_t> ids; |
2992 | - for(auto range : _ranges){ |
2993 | + for(auto& range : _ranges){ |
2994 | ids.push_back(range._lower); |
2995 | } |
2996 | return ids; |
2997 | } |
2998 | |
2999 | - std::vector<uint32_t> getUpperIds(){ |
3000 | - std::vector<uint32_t> ids; |
3001 | - for(auto range : _ranges){ |
3002 | - ids.push_back(range._upper); |
3003 | - } |
3004 | - return ids; |
3005 | - } |
3006 | - |
3007 | - interval_t getSingleColorInterval(){ |
3008 | + interval_t getSingleColorInterval() const { |
3009 | interval_t newInterval; |
3010 | - for(auto id : getLowerIds()){ |
3011 | - newInterval.addRange(id,id); |
3012 | + for(auto& range : _ranges){ |
3013 | + newInterval.addRange(range._lower, range._lower); |
3014 | } |
3015 | return newInterval; |
3016 | } |
3017 | |
3018 | - bool equals(interval_t other){ |
3019 | + bool equals(const interval_t& other) const { |
3020 | if(other.size() != size()){ |
3021 | return false; |
3022 | } |
3023 | @@ -142,33 +113,27 @@ |
3024 | return true; |
3025 | } |
3026 | |
3027 | - uint32_t getContainedColors(){ |
3028 | + uint32_t getContainedColors() const { |
3029 | uint32_t colors = 1; |
3030 | - for(auto range: _ranges) { |
3031 | + for(const auto& range : _ranges) { |
3032 | colors *= 1+ range._upper - range._lower; |
3033 | } |
3034 | return colors; |
3035 | } |
3036 | |
3037 | - bool contains(interval_t other){ |
3038 | + bool contains(const interval_t &other, const std::vector<bool> &diagonalPositions) const { |
3039 | if(other.size() != size()){ |
3040 | return false; |
3041 | } |
3042 | for(uint32_t i = 0; i < size(); i++){ |
3043 | - if(!_ranges[i].compare(other[i]).first){ |
3044 | + if(!diagonalPositions[i] && !_ranges[i].compare(other[i]).first){ |
3045 | return false; |
3046 | } |
3047 | } |
3048 | return true; |
3049 | } |
3050 | |
3051 | - void constrain(interval_t other){ |
3052 | - for(uint32_t i = 0; i < _ranges.size(); i++){ |
3053 | - _ranges[i] &= other._ranges[i]; |
3054 | - } |
3055 | - } |
3056 | - |
3057 | - interval_t getOverlap(interval_t other){ |
3058 | + interval_t getOverlap(const interval_t &other) const { |
3059 | interval_t overlapInterval; |
3060 | if(size() != other.size()){ |
3061 | return overlapInterval; |
3062 | @@ -182,7 +147,43 @@ |
3063 | return overlapInterval; |
3064 | } |
3065 | |
3066 | - std::vector<interval_t> getSubtracted(interval_t other, uint32_t ctSize){ |
3067 | + interval_t getOverlap(const interval_t& other, const std::vector<bool> &diagonalPositions) const { |
3068 | + interval_t overlapInterval; |
3069 | + if(size() != other.size()){ |
3070 | + return overlapInterval; |
3071 | + } |
3072 | + |
3073 | + for(uint32_t i = 0; i < size(); i++){ |
3074 | + if(diagonalPositions[i]){ |
3075 | + overlapInterval.addRange(_ranges[i]); |
3076 | + } else { |
3077 | + auto rangeCopy = _ranges[i]; |
3078 | + overlapInterval.addRange(rangeCopy &= other[i]); |
3079 | + } |
3080 | + } |
3081 | + |
3082 | + return overlapInterval; |
3083 | + } |
3084 | + |
3085 | + interval_t& operator|=(const interval_t& other) { |
3086 | + assert(size() == other.size()); |
3087 | + for(uint32_t l = 0; l < size(); ++l) { |
3088 | + _ranges[l] |= other[l]; |
3089 | + } |
3090 | + return *this; |
3091 | + } |
3092 | + |
3093 | + bool intersects(const interval_t& otherInterval) const { |
3094 | + assert(size() == otherInterval.size()); |
3095 | + for(uint32_t k = 0; k < size(); k++) { |
3096 | + if(!_ranges[k].intersects(otherInterval[k])) { |
3097 | + return false; |
3098 | + } |
3099 | + } |
3100 | + return true; |
3101 | + } |
3102 | + |
3103 | + std::vector<interval_t> getSubtracted(const interval_t& other, const std::vector<bool> &diagonalPositions) const { |
3104 | std::vector<interval_t> result; |
3105 | |
3106 | if(size() != other.size()){ |
3107 | @@ -191,9 +192,11 @@ |
3108 | |
3109 | for(uint32_t i = 0; i < size(); i++){ |
3110 | interval_t newInterval = *this; |
3111 | + if(diagonalPositions[i]){ |
3112 | + continue; |
3113 | + } |
3114 | |
3115 | int32_t newMinUpper = std::min(((int) other[i]._lower) -1, (int)_ranges[i]._upper); |
3116 | - //uint32_t otherUpper = (other[i]._upper +1) >= ctSize? ctSize-1: other[i]._upper +1; |
3117 | uint32_t newMaxLower = std::max(other[i]._upper +1, _ranges[i]._lower); |
3118 | |
3119 | if(((int32_t) _ranges[i]._lower) <= newMinUpper && newMaxLower <= _ranges[i]._upper){ |
3120 | @@ -218,80 +221,87 @@ |
3121 | return result; |
3122 | } |
3123 | |
3124 | - void print() { |
3125 | - for(auto range : _ranges){ |
3126 | + void print() const { |
3127 | + for(const auto& range : _ranges){ |
3128 | std::cout << " " << range._lower << "-" << range._upper << " "; |
3129 | } |
3130 | } |
3131 | |
3132 | - std::string toString() { |
3133 | + std::string toString() const { |
3134 | std::ostringstream strs; |
3135 | - for(auto range : _ranges){ |
3136 | + for(const auto& range : _ranges){ |
3137 | strs << " " << range._lower << "-" << range._upper << " "; |
3138 | } |
3139 | return strs.str(); |
3140 | } |
3141 | }; |
3142 | |
3143 | - struct closestIntervals { |
3144 | + struct interval_dist_t { |
3145 | uint32_t intervalId1; |
3146 | uint32_t intervalId2; |
3147 | uint32_t distance; |
3148 | }; |
3149 | |
3150 | - struct intervalTuple_t { |
3151 | + class interval_vector_t { |
3152 | + private: |
3153 | std::vector<interval_t> _intervals; |
3154 | - double totalinputtime = 0; |
3155 | - |
3156 | - ~intervalTuple_t() { |
3157 | - } |
3158 | - |
3159 | - intervalTuple_t() { |
3160 | - } |
3161 | - |
3162 | - intervalTuple_t(std::vector<interval_t> ranges) : _intervals(ranges) { |
3163 | + public: |
3164 | + |
3165 | + ~interval_vector_t() { |
3166 | + } |
3167 | + |
3168 | + interval_vector_t() { |
3169 | + } |
3170 | + |
3171 | + interval_vector_t(const std::vector<interval_t>& ranges) : _intervals(ranges) { |
3172 | }; |
3173 | |
3174 | - interval_t& getFirst(){ |
3175 | + std::vector<interval_t>::iterator begin() { return _intervals.begin(); } |
3176 | + std::vector<interval_t>::iterator end() { return _intervals.end(); } |
3177 | + std::vector<interval_t>::const_iterator begin() const { return _intervals.begin(); } |
3178 | + std::vector<interval_t>::const_iterator end() const { return _intervals.end(); } |
3179 | + |
3180 | + |
3181 | + bool empty() const { |
3182 | + return _intervals.empty(); |
3183 | + } |
3184 | + |
3185 | + void clear() { |
3186 | + _intervals.clear(); |
3187 | + } |
3188 | + |
3189 | + const interval_t& front() const{ |
3190 | return _intervals[0]; |
3191 | } |
3192 | |
3193 | - interval_t& back() { |
3194 | + const interval_t& back() const { |
3195 | return _intervals.back(); |
3196 | } |
3197 | |
3198 | - size_t size() { |
3199 | + size_t size() const { |
3200 | return _intervals.size(); |
3201 | } |
3202 | |
3203 | - size_t tupleSize() { |
3204 | + size_t tupleSize() const { |
3205 | return _intervals[0].size(); |
3206 | } |
3207 | |
3208 | - uint32_t getContainedColors(){ |
3209 | + uint32_t getContainedColors() const { |
3210 | uint32_t colors = 0; |
3211 | - for (auto interval : _intervals) { |
3212 | + for (const auto& interval : _intervals) { |
3213 | colors += interval.getContainedColors(); |
3214 | } |
3215 | return colors; |
3216 | } |
3217 | |
3218 | - std::pair<uint32_t,uint32_t> shiftInterval(uint32_t lower, uint32_t upper, uint32_t ctSize, int32_t modifier){ |
3219 | + static std::pair<uint32_t,uint32_t> shiftInterval(uint32_t lower, uint32_t upper, uint32_t ctSize, int32_t modifier) { |
3220 | int32_t lower_val = ctSize + (lower + modifier); |
3221 | int32_t upper_val = ctSize + (upper + modifier); |
3222 | return std::make_pair(lower_val % ctSize, upper_val % ctSize); |
3223 | } |
3224 | |
3225 | - uint32_t intervalCombinations(){ |
3226 | - uint32_t res = 0; |
3227 | - for(auto interval : _intervals){ |
3228 | - res += interval.intervalCombinations(); |
3229 | - } |
3230 | - return res; |
3231 | - } |
3232 | - |
3233 | - bool hasValidIntervals(){ |
3234 | - for(auto interval : _intervals) { |
3235 | + bool hasValidIntervals() const { |
3236 | + for(const auto& interval : _intervals) { |
3237 | if(interval.isSound()){ |
3238 | return true; |
3239 | } |
3240 | @@ -299,20 +309,21 @@ |
3241 | return false; |
3242 | } |
3243 | |
3244 | + const interval_t& operator[] (size_t index) const { |
3245 | + assert(index < _intervals.size()); |
3246 | + return _intervals[index]; |
3247 | + } |
3248 | + |
3249 | interval_t& operator[] (size_t index) { |
3250 | - return _intervals[index]; |
3251 | - } |
3252 | - |
3253 | - interval_t& operator[] (int index) { |
3254 | - return _intervals[index]; |
3255 | - } |
3256 | - |
3257 | - interval_t& operator[] (uint32_t index) { |
3258 | assert(index < _intervals.size()); |
3259 | return _intervals[index]; |
3260 | } |
3261 | - |
3262 | - interval_t isRangeEnd(std::vector<uint32_t> ids) { |
3263 | + |
3264 | + void append(const interval_vector_t& other) { |
3265 | + _intervals.insert(_intervals.end(), other._intervals.begin(), other._intervals.end()); |
3266 | + } |
3267 | + |
3268 | + interval_t isRangeEnd(const std::vector<uint32_t>& ids) const { |
3269 | for (uint32_t j = 0; j < _intervals.size(); j++) { |
3270 | bool rangeEnd = true; |
3271 | for (uint32_t i = 0; i < _intervals[j].size(); i++) { |
3272 | @@ -326,16 +337,16 @@ |
3273 | if(j+1 != _intervals.size()) { |
3274 | return _intervals[j+1]; |
3275 | } else { |
3276 | - return getFirst(); |
3277 | + return front(); |
3278 | } |
3279 | } |
3280 | } |
3281 | return interval_t(); |
3282 | } |
3283 | |
3284 | - std::vector<Colored::interval_t> shrinkIntervals(uint32_t newSize){ |
3285 | + std::vector<Colored::interval_t> shrinkIntervals(uint32_t newSize) const { |
3286 | std::vector<Colored::interval_t> resizedIntervals; |
3287 | - for(auto interval : _intervals){ |
3288 | + for(auto& interval : _intervals){ |
3289 | Colored::interval_t resizedInterval; |
3290 | for(uint32_t i = 0; i < newSize; i++){ |
3291 | resizedInterval.addRange(interval[i]); |
3292 | @@ -345,7 +356,7 @@ |
3293 | return resizedIntervals; |
3294 | } |
3295 | |
3296 | - void addInterval(interval_t interval) { |
3297 | + void addInterval(const interval_t& interval) { |
3298 | uint32_t vecIndex = 0; |
3299 | |
3300 | if(!_intervals.empty()) { |
3301 | @@ -392,9 +403,9 @@ |
3302 | _intervals.insert(_intervals.begin() + vecIndex, interval); |
3303 | } |
3304 | |
3305 | - void constrainLower(std::vector<uint32_t> values, bool strict) { |
3306 | - for(uint32_t i = 0; i < _intervals.size(); i++) { |
3307 | - for(uint32_t j = 0; j < values.size(); j++){ |
3308 | + void constrainLower(const std::vector<uint32_t>& values, bool strict) { |
3309 | + for(uint32_t i = 0; i < _intervals.size(); ++i) { |
3310 | + for(uint32_t j = 0; j < values.size(); ++j){ |
3311 | if(strict && _intervals[i][j]._lower <= values[j]){ |
3312 | _intervals[i][j]._lower = values[j]+1; |
3313 | } |
3314 | @@ -406,9 +417,9 @@ |
3315 | simplify(); |
3316 | } |
3317 | |
3318 | - void constrainUpper(std::vector<uint32_t> values, bool strict) { |
3319 | - for(uint32_t i = 0; i < _intervals.size(); i++) { |
3320 | - for(uint32_t j = 0; j < values.size(); j++){ |
3321 | + void constrainUpper(const std::vector<uint32_t>& values, bool strict) { |
3322 | + for(uint32_t i = 0; i < _intervals.size(); ++i) { |
3323 | + for(uint32_t j = 0; j < values.size(); ++j){ |
3324 | if(strict && _intervals[i][j]._upper >= values[j]){ |
3325 | _intervals[i][j]._upper = values[j]-1; |
3326 | } |
3327 | @@ -420,29 +431,17 @@ |
3328 | simplify(); |
3329 | } |
3330 | |
3331 | - void expandLower(std::vector<uint32_t> values) { |
3332 | - for(uint32_t i = 0; i < values.size(); i++) { |
3333 | - _intervals[0][i]._lower = std::min(values[i],_intervals[0][i]._lower); |
3334 | - } |
3335 | - } |
3336 | - |
3337 | - void expandUpper(std::vector<uint32_t> values) { |
3338 | - for(uint32_t i = 0; i < values.size(); i++) { |
3339 | - _intervals[0][i]._upper = std::max(values[i],_intervals[0][i]._upper); |
3340 | - } |
3341 | - } |
3342 | - |
3343 | - void print() { |
3344 | - for (auto interval : _intervals){ |
3345 | + void print() const { |
3346 | + for (const auto& interval : _intervals){ |
3347 | std::cout << "["; |
3348 | interval.print(); |
3349 | std::cout << "]" << std::endl; |
3350 | } |
3351 | } |
3352 | |
3353 | - std::string toString() { |
3354 | + std::string toString() const { |
3355 | std::string out; |
3356 | - for (auto interval : _intervals){ |
3357 | + for (const auto &interval : _intervals){ |
3358 | out += "["; |
3359 | out += interval.toString(); |
3360 | out += "]\n"; |
3361 | @@ -450,9 +449,9 @@ |
3362 | return out; |
3363 | } |
3364 | |
3365 | - std::vector<uint32_t> getLowerIds(){ |
3366 | + std::vector<uint32_t> getLowerIds() const { |
3367 | std::vector<uint32_t> ids; |
3368 | - for(auto interval : _intervals){ |
3369 | + for(const auto& interval : _intervals){ |
3370 | if(ids.empty()){ |
3371 | ids = interval.getLowerIds(); |
3372 | } else { |
3373 | @@ -464,13 +463,13 @@ |
3374 | return ids; |
3375 | } |
3376 | |
3377 | - std::vector<uint32_t> getLowerIds(int32_t modifier, std::vector<size_t> sizes){ |
3378 | + std::vector<uint32_t> getLowerIds(int32_t modifier, const std::vector<size_t>& sizes) const { |
3379 | std::vector<uint32_t> ids; |
3380 | for(uint32_t j = 0; j < size(); j++){ |
3381 | - auto interval = &_intervals[j]; |
3382 | + auto& interval = _intervals[j]; |
3383 | if(ids.empty()){ |
3384 | for(uint32_t i = 0; i < ids.size(); i++){ |
3385 | - auto shiftedInterval = shiftInterval(interval->operator[](i)._lower, interval->operator[](i)._upper, sizes[i], modifier); |
3386 | + auto shiftedInterval = shiftInterval(interval[i]._lower, interval[i]._upper, sizes[i], modifier); |
3387 | if(shiftedInterval.first > shiftedInterval.second){ |
3388 | ids.push_back(0); |
3389 | } else { |
3390 | @@ -482,7 +481,7 @@ |
3391 | if(ids[i] == 0){ |
3392 | continue; |
3393 | } |
3394 | - auto shiftedInterval = shiftInterval(interval->operator[](i)._lower, interval->operator[](i)._upper, sizes[i], modifier); |
3395 | + auto shiftedInterval = shiftInterval(interval[i]._lower, interval[i]._upper, sizes[i], modifier); |
3396 | if(shiftedInterval.first > shiftedInterval.second){ |
3397 | ids[i] = 0; |
3398 | } else { |
3399 | @@ -494,27 +493,13 @@ |
3400 | return ids; |
3401 | } |
3402 | |
3403 | - std::vector<uint32_t> getUpperIds(){ |
3404 | - std::vector<uint32_t> ids; |
3405 | - for(auto interval : _intervals){ |
3406 | - if(ids.empty()){ |
3407 | - ids = interval.getUpperIds(); |
3408 | - } else { |
3409 | - for(uint32_t i = 0; i < ids.size(); i++){ |
3410 | - ids[i] = std::max(ids[i], interval[i]._upper); |
3411 | - } |
3412 | - } |
3413 | - } |
3414 | - return ids; |
3415 | - } |
3416 | - |
3417 | - std::vector<uint32_t> getUpperIds(int32_t modifier, std::vector<size_t> sizes){ |
3418 | + std::vector<uint32_t> getUpperIds(int32_t modifier, const std::vector<size_t>& sizes) const { |
3419 | std::vector<uint32_t> ids; |
3420 | for(uint32_t j = 0; j < size(); j++){ |
3421 | - auto interval = &_intervals[j]; |
3422 | + const auto& interval = _intervals[j]; |
3423 | if(ids.empty()){ |
3424 | for(uint32_t i = 0; i < ids.size(); i++){ |
3425 | - auto shiftedInterval = shiftInterval(interval->operator[](i)._lower, interval->operator[](i)._upper, sizes[i], modifier); |
3426 | + auto shiftedInterval = shiftInterval(interval[i]._lower, interval[i]._upper, sizes[i], modifier); |
3427 | |
3428 | if(shiftedInterval.first > shiftedInterval.second){ |
3429 | ids.push_back(sizes[i]-1); |
3430 | @@ -527,7 +512,7 @@ |
3431 | if(ids[i] == sizes[i]-1){ |
3432 | continue; |
3433 | } |
3434 | - auto shiftedInterval = shiftInterval(interval->operator[](i)._lower, interval->operator[](i)._upper, sizes[i], modifier); |
3435 | + auto shiftedInterval = shiftInterval(interval[i]._lower, interval[i]._upper, sizes[i], modifier); |
3436 | |
3437 | if(shiftedInterval.first > shiftedInterval.second){ |
3438 | ids[i] = sizes[i]-1; |
3439 | @@ -540,7 +525,7 @@ |
3440 | return ids; |
3441 | } |
3442 | |
3443 | - void applyModifier(int32_t modifier, std::vector<size_t> sizes){ |
3444 | + void applyModifier(int32_t modifier, const std::vector<size_t>& sizes) { |
3445 | std::vector<interval_t> collectedIntervals; |
3446 | for(auto& interval : _intervals){ |
3447 | std::vector<interval_t> newIntervals; |
3448 | @@ -550,7 +535,7 @@ |
3449 | for(auto& interval1 : newIntervals){ |
3450 | auto shiftedInterval = shiftInterval(interval1[i]._lower, interval1[i]._upper, sizes[i], modifier); |
3451 | |
3452 | - if(shiftedInterval.first > shiftedInterval.second){ |
3453 | + if(shiftedInterval.first > shiftedInterval.second) { |
3454 | auto newInterval = interval1; |
3455 | |
3456 | interval1[i]._lower = 0; |
3457 | @@ -559,7 +544,7 @@ |
3458 | newInterval[i]._lower = shiftedInterval.first; |
3459 | newInterval[i]._upper = sizes[i]-1; |
3460 | tempIntervals.push_back(std::move(newInterval)); |
3461 | - }else { |
3462 | + } else { |
3463 | interval1[i]._lower = shiftedInterval.first; |
3464 | interval1[i]._upper = shiftedInterval.second; |
3465 | } |
3466 | @@ -572,43 +557,34 @@ |
3467 | _intervals = std::move(collectedIntervals); |
3468 | } |
3469 | |
3470 | - bool contains(interval_t interval){ |
3471 | - for(auto localInterval : _intervals){ |
3472 | - if(localInterval.contains(interval)){ |
3473 | + bool contains(const interval_t &interval, const std::vector<bool> &diagonalPositions) const { |
3474 | + for(const auto &localInterval : _intervals){ |
3475 | + if(localInterval.contains(interval, diagonalPositions)){ |
3476 | return true; |
3477 | } |
3478 | } |
3479 | return false; |
3480 | } |
3481 | |
3482 | - void removeInterval(interval_t interval) { |
3483 | - for (uint32_t i = 0; i < _intervals.size(); i++) { |
3484 | - if(interval.equals(_intervals[i])){ |
3485 | - removeInterval(i); |
3486 | - return; |
3487 | - } |
3488 | - } |
3489 | - } |
3490 | - |
3491 | void removeInterval(uint32_t index) { |
3492 | _intervals.erase(_intervals.begin() + index); |
3493 | } |
3494 | |
3495 | |
3496 | |
3497 | - void restrict(uint32_t k){ |
3498 | + void restrict(uint32_t k) { |
3499 | simplify(); |
3500 | if(k == 0){ |
3501 | return; |
3502 | } |
3503 | |
3504 | while (size() > k){ |
3505 | - closestIntervals closestInterval = getClosestIntervals(); |
3506 | - auto interval = &_intervals[closestInterval.intervalId1]; |
3507 | - auto otherInterval = &_intervals[closestInterval.intervalId2]; |
3508 | + interval_dist_t closestInterval = getClosestIntervals(); |
3509 | + auto& interval = _intervals[closestInterval.intervalId1]; |
3510 | + const auto& otherInterval = _intervals[closestInterval.intervalId2]; |
3511 | |
3512 | - for(uint32_t l = 0; l < interval->size(); l++) { |
3513 | - interval->operator[](l) |= otherInterval->operator[](l); |
3514 | + for(uint32_t l = 0; l < interval.size(); l++) { |
3515 | + interval[l] |= otherInterval[l]; |
3516 | } |
3517 | |
3518 | _intervals.erase(_intervals.begin() + closestInterval.intervalId2); |
3519 | @@ -616,85 +592,55 @@ |
3520 | simplify(); |
3521 | } |
3522 | |
3523 | - closestIntervals getClosestIntervals(){ |
3524 | - closestIntervals currentBest = {0,0, UINT32_MAX}; |
3525 | - for (uint32_t i = 0; i < size()-1; i++) { |
3526 | - auto interval = &_intervals[i]; |
3527 | - for(uint32_t j = i+1; j < size(); j++){ |
3528 | - auto otherInterval = &_intervals[j]; |
3529 | - uint32_t dist = 0; |
3530 | - |
3531 | - for(uint32_t k = 0; k < interval->size(); k++) { |
3532 | - int32_t val1 = otherInterval->operator[](k)._lower - interval->operator[](k)._upper; |
3533 | - int32_t val2 = interval->operator[](k)._lower - otherInterval->operator[](k)._upper; |
3534 | - // int32_t lowerDist = interval->operator[](k)._lower > otherInterval->operator[](k)._lower? |
3535 | - // interval->operator[](k)._lower - otherInterval->operator[](k)._lower : |
3536 | - // otherInterval->operator[](k)._lower - interval->operator[](k)._lower; |
3537 | - // int32_t upperDist = interval->operator[](k)._upper > otherInterval->operator[](k)._upper? |
3538 | - // interval->operator[](k)._upper - otherInterval->operator[](k)._upper : |
3539 | - // otherInterval->operator[](k)._upper - interval->operator[](k)._upper; |
3540 | - dist += std::max(0, std::max(val1, val2)); |
3541 | - //dist += std::max(upperDist + lowerDist, upperDist + lowerDist + std::max(val1, val2)); |
3542 | - if(dist >= currentBest.distance){ |
3543 | - break; |
3544 | - } |
3545 | + interval_dist_t getClosestIntervals() const { |
3546 | + interval_dist_t currentBest = {0,0, std::numeric_limits<uint32_t>::max()}; |
3547 | + for (uint32_t i = 0; i < size()-1; i++) { |
3548 | + const auto& interval = _intervals[i]; |
3549 | + for(uint32_t j = i+1; j < size(); j++){ |
3550 | + const auto& otherInterval = _intervals[j]; |
3551 | + uint32_t dist = 0; |
3552 | + |
3553 | + for(uint32_t k = 0; k < interval.size(); k++) { |
3554 | + int32_t val1 = otherInterval[k]._lower - interval[k]._upper; |
3555 | + int32_t val2 = interval[k]._lower - otherInterval[k]._upper; |
3556 | + dist += std::max(0, std::max(val1, val2)); |
3557 | + if(dist >= currentBest.distance){ |
3558 | + break; |
3559 | } |
3560 | - |
3561 | - if(dist < currentBest.distance){ |
3562 | - currentBest.distance = dist; |
3563 | - currentBest.intervalId1 = i; |
3564 | - currentBest.intervalId2 = j; |
3565 | - |
3566 | - //if the distance is 1 we cannot find any intervals that are closer so we stop searching |
3567 | - if(currentBest.distance == 1){ |
3568 | - return currentBest; |
3569 | - } |
3570 | - } |
3571 | } |
3572 | + |
3573 | + if(dist < currentBest.distance){ |
3574 | + currentBest.distance = dist; |
3575 | + currentBest.intervalId1 = i; |
3576 | + currentBest.intervalId2 = j; |
3577 | + |
3578 | + //if the distance is 1 we cannot find any intervals that are closer so we stop searching |
3579 | + if(currentBest.distance == 1){ |
3580 | + return currentBest; |
3581 | + } |
3582 | + } |
3583 | } |
3584 | + } |
3585 | return currentBest; |
3586 | } |
3587 | |
3588 | void simplify() { |
3589 | - std::set<uint32_t> rangesToRemove; |
3590 | - if(_intervals.empty()){ |
3591 | - return; |
3592 | + while(!_intervals.empty() && !_intervals[0].isSound()){ |
3593 | + _intervals.erase(_intervals.begin()); |
3594 | } |
3595 | - |
3596 | - for (uint32_t i = 0; i < _intervals.size(); i++) { |
3597 | - auto interval = &_intervals[i]; |
3598 | - if(!interval->isSound()){ |
3599 | - rangesToRemove.insert(i); |
3600 | - continue; |
3601 | - } |
3602 | - for(uint32_t j = i+1; j < _intervals.size(); j++){ |
3603 | - auto otherInterval = &_intervals[j]; |
3604 | - |
3605 | - if(!otherInterval->isSound()){ |
3606 | - continue; |
3607 | - } |
3608 | - bool overlap = true; |
3609 | - |
3610 | - if(overlap){ |
3611 | - for(uint32_t k = 0; k < interval->size(); k++) { |
3612 | - if(interval->operator[](k)._lower > otherInterval->operator[](k)._upper || otherInterval->operator[](k)._lower > interval->operator[](k)._upper) { |
3613 | - overlap = false; |
3614 | - break; |
3615 | - } |
3616 | - } |
3617 | - } |
3618 | - |
3619 | - if(overlap) { |
3620 | - for(uint32_t l = 0; l < interval->size(); l++) { |
3621 | - interval->operator[](l) |= otherInterval->operator[](l); |
3622 | - } |
3623 | - rangesToRemove.insert(j); |
3624 | - } |
3625 | + for (size_t i = 0; i < _intervals.size(); ++i) { |
3626 | + for(size_t j = _intervals.size()-1; j > i; --j){ |
3627 | + const auto& otherInterval = _intervals[j]; |
3628 | + auto& interval = _intervals[i]; |
3629 | + if(!otherInterval.isSound()){ |
3630 | + _intervals.erase(_intervals.begin() + j); |
3631 | + } |
3632 | + else if(interval.intersects(otherInterval)) { |
3633 | + interval |= otherInterval; |
3634 | + _intervals.erase(_intervals.begin() + j); |
3635 | + } |
3636 | } |
3637 | } |
3638 | - for (auto i = rangesToRemove.rbegin(); i != rangesToRemove.rend(); ++i) { |
3639 | - _intervals.erase(_intervals.begin() + *i); |
3640 | - } |
3641 | } |
3642 | |
3643 | void combineNeighbours() { |
3644 | @@ -704,15 +650,15 @@ |
3645 | } |
3646 | |
3647 | for (uint32_t i = 0; i < _intervals.size(); i++) { |
3648 | - auto interval = &_intervals[i]; |
3649 | - if(!interval->isSound()){ |
3650 | + auto& interval = _intervals[i]; |
3651 | + if(!interval.isSound()){ |
3652 | rangesToRemove.insert(i); |
3653 | continue; |
3654 | } |
3655 | for(uint32_t j = i+1; j < _intervals.size(); j++){ |
3656 | - auto otherInterval = &_intervals[j]; |
3657 | + const auto& otherInterval = _intervals[j]; |
3658 | |
3659 | - if(!otherInterval->isSound()){ |
3660 | + if(!otherInterval.isSound()){ |
3661 | continue; |
3662 | } |
3663 | bool overlap = true; |
3664 | @@ -720,9 +666,10 @@ |
3665 | uint32_t dist = 1; |
3666 | |
3667 | if(overlap){ |
3668 | - for(uint32_t k = 0; k < interval->size(); k++) { |
3669 | - if(interval->operator[](k)._lower > otherInterval->operator[](k)._upper || otherInterval->operator[](k)._lower > interval->operator[](k)._upper) { |
3670 | - if(interval->operator[](k)._lower > otherInterval->operator[](k)._upper + dist || otherInterval->operator[](k)._lower > interval->operator[](k)._upper + dist) { |
3671 | + for(uint32_t k = 0; k < interval.size(); k++) { |
3672 | + if(interval[k]._lower > otherInterval[k]._upper || otherInterval[k]._lower > interval[k]._upper) { |
3673 | + if(interval[k]._lower > otherInterval[k]._upper + dist || |
3674 | + otherInterval[k]._lower > interval[k]._upper + dist) { |
3675 | overlap = false; |
3676 | break; |
3677 | } else { |
3678 | @@ -733,8 +680,8 @@ |
3679 | } |
3680 | |
3681 | if(overlap) { |
3682 | - for(uint32_t l = 0; l < interval->size(); l++) { |
3683 | - interval->operator[](l) |= otherInterval->operator[](l); |
3684 | + for(uint32_t l = 0; l < interval.size(); l++) { |
3685 | + interval[l] |= otherInterval[l]; |
3686 | } |
3687 | rangesToRemove.insert(j); |
3688 | } |
3689 | |
3690 | === modified file 'include/PetriEngine/Colored/Multiset.h' |
3691 | --- include/PetriEngine/Colored/Multiset.h 2020-03-02 21:03:24 +0000 |
3692 | +++ include/PetriEngine/Colored/Multiset.h 2021-07-07 08:15:00 +0000 |
3693 | @@ -26,18 +26,18 @@ |
3694 | private: |
3695 | class Iterator { |
3696 | private: |
3697 | - Multiset* ms; |
3698 | - size_t index; |
3699 | + const Multiset* _ms; |
3700 | + size_t _index; |
3701 | |
3702 | public: |
3703 | - Iterator(Multiset* ms, size_t index) |
3704 | - : ms(ms), index(index) {} |
3705 | + Iterator(const Multiset* ms, size_t index) |
3706 | + : _ms(ms), _index(index) {} |
3707 | |
3708 | bool operator==(Iterator& other); |
3709 | bool operator!=(Iterator& other); |
3710 | Iterator& operator++(); |
3711 | - std::pair<const Color*,uint32_t&> operator++(int); |
3712 | - std::pair<const Color*,uint32_t&> operator*(); |
3713 | + std::pair<const Color*,const uint32_t&> operator++(int); |
3714 | + std::pair<const Color*, const uint32_t&> operator*(); |
3715 | }; |
3716 | |
3717 | typedef std::vector<std::pair<uint32_t,uint32_t>> Internal; |
3718 | @@ -67,14 +67,14 @@ |
3719 | |
3720 | size_t size() const; |
3721 | |
3722 | - Iterator begin(); |
3723 | - Iterator end(); |
3724 | + const Iterator begin() const; |
3725 | + const Iterator end() const; |
3726 | |
3727 | std::string toString() const; |
3728 | |
3729 | private: |
3730 | Internal _set; |
3731 | - ColorType* type; |
3732 | + const ColorType* _type; |
3733 | }; |
3734 | } |
3735 | } |
3736 | |
3737 | === modified file 'include/PetriEngine/Colored/PartitionBuilder.h' |
3738 | --- include/PetriEngine/Colored/PartitionBuilder.h 2021-04-22 12:43:03 +0000 |
3739 | +++ include/PetriEngine/Colored/PartitionBuilder.h 2021-07-07 08:15:00 +0000 |
3740 | @@ -1,59 +1,76 @@ |
3741 | #include "ColoredNetStructures.h" |
3742 | -#include "EquivalenceClass.h" |
3743 | +#include "EquivalenceVec.h" |
3744 | #include "IntervalGenerator.h" |
3745 | |
3746 | namespace PetriEngine { |
3747 | namespace Colored { |
3748 | class PartitionBuilder { |
3749 | + |
3750 | + |
3751 | public: |
3752 | - PartitionBuilder(std::vector<Transition> *transitions, |
3753 | - std::vector<Place> *places, |
3754 | - std::unordered_map<uint32_t,std::vector<uint32_t>> *placePostTransitionMap, |
3755 | - std::unordered_map<uint32_t,std::vector<uint32_t>> *placePreTransitionMap); |
3756 | + PartitionBuilder(const std::vector<Transition> &transitions, |
3757 | + const std::vector<Place> &places, |
3758 | + const std::unordered_map<uint32_t,std::vector<uint32_t>> &placePostTransitionMap, |
3759 | + const std::unordered_map<uint32_t,std::vector<uint32_t>> &placePreTransitionMap); |
3760 | |
3761 | - PartitionBuilder(std::vector<Transition> *transitions, |
3762 | - std::vector<Place> *places, |
3763 | - std::unordered_map<uint32_t,std::vector<uint32_t>> *placePostTransitionMap, |
3764 | - std::unordered_map<uint32_t,std::vector<uint32_t>> *placePreTransitionMap, |
3765 | - std::vector<Colored::ColorFixpoint> *placeColorFixpoints); |
3766 | + PartitionBuilder(const std::vector<Transition> &transitions, |
3767 | + const std::vector<Place> &places, |
3768 | + const std::unordered_map<uint32_t,std::vector<uint32_t>> &placePostTransitionMap, |
3769 | + const std::unordered_map<uint32_t,std::vector<uint32_t>> &placePreTransitionMap, |
3770 | + const std::vector<Colored::ColorFixpoint> *placeColorFixpoints); |
3771 | |
3772 | ~PartitionBuilder() {} |
3773 | |
3774 | //void initPartition(); |
3775 | - void partitionNet(); |
3776 | - void refinePartition(); |
3777 | - void printPartion(); |
3778 | - void assignColorMap(std::unordered_map<uint32_t, EquivalenceVec> &partition); |
3779 | + bool partitionNet(int32_t timeout); |
3780 | + void printPartion() const; |
3781 | + void assignColorMap(std::unordered_map<uint32_t, EquivalenceVec> &partition) const; |
3782 | |
3783 | - std::unordered_map<uint32_t, EquivalenceVec> getPartition(){ |
3784 | + std::unordered_map<uint32_t, EquivalenceVec> getPartition() const{ |
3785 | return _partition; |
3786 | } |
3787 | + |
3788 | private: |
3789 | - std::vector<Transition> *_transitions; |
3790 | - std::unordered_map<uint32_t,std::vector<uint32_t>> *_placePostTransitionMap; |
3791 | - std::unordered_map<uint32_t,std::vector<uint32_t>> *_placePreTransitionMap; |
3792 | + const std::vector<Transition> &_transitions; |
3793 | + const std::vector<Place> &_places; |
3794 | + const std::unordered_map<uint32_t,std::vector<uint32_t>> &_placePostTransitionMap; |
3795 | + const std::unordered_map<uint32_t,std::vector<uint32_t>> &_placePreTransitionMap; |
3796 | std::unordered_map<uint32_t,bool> _inQueue; |
3797 | - std::vector<Place> *_places; |
3798 | std::unordered_map<uint32_t, EquivalenceVec> _partition; |
3799 | - PetriEngine::IntervalGenerator intervalGenerator; |
3800 | + const PetriEngine::Colored::IntervalGenerator _interval_generator = IntervalGenerator(); |
3801 | std::vector<uint32_t> _placeQueue; |
3802 | |
3803 | bool splitPartition(EquivalenceVec equivalenceVec, uint32_t placeId); |
3804 | |
3805 | void handleTransition(uint32_t transitionId, uint32_t postPlaceId); |
3806 | - void handleTransition(Transition *transitionId, uint32_t postPlaceId, Arc *postArc); |
3807 | + void handleTransition(const Transition &transitionId, const uint32_t postPlaceId, const Arc *postArc); |
3808 | |
3809 | void handleLeafTransitions(); |
3810 | |
3811 | void addToQueue(uint32_t placeId); |
3812 | |
3813 | - std::vector<std::unordered_map<const Variable *, intervalTuple_t>> prepareVariables( |
3814 | - std::unordered_map<const Variable *, std::vector<std::unordered_map<uint32_t, int32_t>>> varModifierMap, |
3815 | - EquivalenceClass *eqClass , Arc *postArc, uint32_t placeId); |
3816 | - |
3817 | - bool findOverlap(EquivalenceVec equivalenceVec1, EquivalenceVec equivalenceVec2, uint32_t &overlap1, uint32_t &overlap2, EquivalenceClass &intersection); |
3818 | - |
3819 | - uint32_t eqClassIdCounter = 0; |
3820 | + bool checkTupleDiagonal(uint32_t placeId); |
3821 | + bool checkDiagonal(uint32_t placeId); |
3822 | + |
3823 | + void handleInArcs(const Transition &transition, std::set<const Colored::Variable*> &diagonalVars, const PositionVariableMap &varPositionMap, const std::vector<PetriEngine::Colored::VariableIntervalMap> &varMaps, uint32_t postPlaceId); |
3824 | + |
3825 | + void applyNewIntervals(const Arc &inArc, const std::vector<PetriEngine::Colored::VariableIntervalMap> &varMaps); |
3826 | + |
3827 | + void checkVarOnArc(const VariableModifierMap &varModifierMap, std::set<const Colored::Variable*> &diagonalVars, uint32_t placeId, bool inputArc); |
3828 | + |
3829 | + void checkVarOnInputArcs(const std::unordered_map<uint32_t,PositionVariableMap> &placeVariableMap, const PositionVariableMap &preVarPositionMap, std::set<const Colored::Variable*> &diagonalVars, uint32_t placeId); |
3830 | + |
3831 | + void markSharedVars(const PositionVariableMap &preVarPositionMap, const PositionVariableMap &varPositionMap, uint32_t postPlaceId, uint32_t prePlaceId); |
3832 | + void checkVarInGuard(const PositionVariableMap &preVarPositionMap, const std::set<const Colored::Variable*> &diagonalVars, uint32_t placeId); |
3833 | + |
3834 | + std::vector<VariableIntervalMap> prepareVariables( |
3835 | + const VariableModifierMap &varModifierMap, |
3836 | + const EquivalenceClass& eqClass , const Arc *postArc, uint32_t placeId); |
3837 | + |
3838 | + bool findOverlap(const EquivalenceVec &equivalenceVec1,const EquivalenceVec &equivalenceVec2, uint32_t &overlap1, uint32_t &overlap2, EquivalenceClass &intersection); |
3839 | + |
3840 | + uint32_t _eq_id_counter = 0; |
3841 | + |
3842 | }; |
3843 | } |
3844 | -} |
3845 | \ No newline at end of file |
3846 | +} |
3847 | |
3848 | === modified file 'include/PetriEngine/PQL/Expressions.h' |
3849 | --- include/PetriEngine/PQL/Expressions.h 2021-04-06 13:10:00 +0000 |
3850 | +++ include/PetriEngine/PQL/Expressions.h 2021-07-07 08:15:00 +0000 |
3851 | @@ -105,6 +105,7 @@ |
3852 | Expr::Types type() const override; |
3853 | Member constraint(SimplificationContext& context) const override; |
3854 | void toXML(std::ostream&, uint32_t tabs, bool tokencount = false) const override; |
3855 | + void toCompactXML(std::ostream&, uint32_t tabs, AnalysisContext& context, bool tokencount = false) const override; |
3856 | bool tk = false; |
3857 | |
3858 | void visit(Visitor& visitor) const override; |
3859 | @@ -125,6 +126,7 @@ |
3860 | Expr::Types type() const override; |
3861 | Member constraint(SimplificationContext& context) const override; |
3862 | void toXML(std::ostream&, uint32_t tabs, bool tokencount = false) const override; |
3863 | + void toCompactXML(std::ostream&, uint32_t tabs, AnalysisContext& context, bool tokencount = false) const override; |
3864 | |
3865 | |
3866 | void toBinary(std::ostream&) const override; |
3867 | @@ -143,6 +145,7 @@ |
3868 | Expr::Types type() const override; |
3869 | Member constraint(SimplificationContext& context) const override; |
3870 | void toXML(std::ostream&, uint32_t tabs, bool tokencount = false) const override; |
3871 | + void toCompactXML(std::ostream&, uint32_t tabs, AnalysisContext& context, bool tokencount = false) const override; |
3872 | |
3873 | |
3874 | void visit(Visitor& visitor) const override; |
3875 | @@ -164,6 +167,7 @@ |
3876 | Expr::Types type() const override; |
3877 | Member constraint(SimplificationContext& context) const override; |
3878 | void toXML(std::ostream&, uint32_t tabs, bool tokencount = false) const override; |
3879 | + void toCompactXML(std::ostream&, uint32_t tabs, AnalysisContext& context, bool tokencount = false) const override; |
3880 | void toBinary(std::ostream&) const override; |
3881 | |
3882 | void visit(Visitor& visitor) const override; |
3883 | @@ -187,6 +191,7 @@ |
3884 | int evaluate(const EvaluationContext& context) override; |
3885 | Expr::Types type() const override; |
3886 | void toXML(std::ostream&, uint32_t tabs, bool tokencount = false) const override; |
3887 | + void toCompactXML(std::ostream&, uint32_t tabs, AnalysisContext& context, bool tokencount = false) const override; |
3888 | void toBinary(std::ostream&) const override; |
3889 | |
3890 | void visit(Visitor& visitor) const override; |
3891 | @@ -218,6 +223,7 @@ |
3892 | void toXML(std::ostream& os, uint32_t tabs, bool tokencount = false) const override { |
3893 | _compiled->toXML(os, tabs, tokencount); |
3894 | } |
3895 | + void toCompactXML(std::ostream& out, uint32_t tabs, AnalysisContext& context, bool tokencount = false) const override; |
3896 | |
3897 | int formulaSize() const override { |
3898 | if(_compiled) return _compiled->formulaSize(); |
3899 | @@ -266,6 +272,7 @@ |
3900 | int evaluate(const EvaluationContext& context) override; |
3901 | Expr::Types type() const override; |
3902 | void toXML(std::ostream&, uint32_t tabs, bool tokencount = false) const override; |
3903 | + void toCompactXML(std::ostream&, uint32_t tabs, AnalysisContext& context, bool tokencount = false) const override; |
3904 | void toBinary(std::ostream&) const override; |
3905 | int formulaSize() const override{ |
3906 | return 1; |
3907 | @@ -309,6 +316,8 @@ |
3908 | |
3909 | void toXML(std::ostream& out, uint32_t tabs) const override |
3910 | { _compiled->toXML(out, tabs); } |
3911 | + void toCompactXML(std::ostream& out, uint32_t tabs, AnalysisContext& context) const override{ |
3912 | + } |
3913 | |
3914 | |
3915 | Quantifier getQuantifier() const override |
3916 | @@ -376,6 +385,7 @@ |
3917 | Condition_ptr pushNegation(negstat_t&, const EvaluationContext& context, bool nested, bool negated, bool initrw) override; |
3918 | void toXML(std::ostream&, uint32_t tabs) const override; |
3919 | void toBinary(std::ostream&) const override; |
3920 | + void toCompactXML(std::ostream&, uint32_t tabs, AnalysisContext& context) const override; |
3921 | |
3922 | |
3923 | Quantifier getQuantifier() const override { return Quantifier::NEG; } |
3924 | @@ -443,6 +453,7 @@ |
3925 | Condition_ptr prepareForReachability(bool negated) const override; |
3926 | Condition_ptr pushNegation(negstat_t&, const EvaluationContext& context, bool nested, bool negated, bool initrw) override; |
3927 | void toXML(std::ostream&, uint32_t tabs) const override; |
3928 | + void toCompactXML(std::ostream&, uint32_t tabs, AnalysisContext& context) const override; |
3929 | Quantifier getQuantifier() const override { return Quantifier::E; } |
3930 | Path getPath() const override { return Path::pError; } |
3931 | uint32_t distance(DistanceContext& context) const override { |
3932 | @@ -471,6 +482,7 @@ |
3933 | Condition_ptr prepareForReachability(bool negated) const override; |
3934 | Condition_ptr pushNegation(negstat_t&, const EvaluationContext& context, bool nested, bool negated, bool initrw) override; |
3935 | void toXML(std::ostream&, uint32_t tabs) const override; |
3936 | + void toCompactXML(std::ostream&, uint32_t tabs, AnalysisContext& context) const override; |
3937 | Quantifier getQuantifier() const override { return Quantifier::A; } |
3938 | Path getPath() const override { return Path::pError; } |
3939 | uint32_t distance(DistanceContext& context) const override { |
3940 | @@ -509,6 +521,7 @@ |
3941 | Retval simplify(SimplificationContext &context) const override; |
3942 | |
3943 | void toXML(std::ostream &, uint32_t tabs) const override; |
3944 | + void toCompactXML(std::ostream&, uint32_t tabs, AnalysisContext& context) const override; |
3945 | |
3946 | Quantifier getQuantifier() const override { return Quantifier::EMPTY; } |
3947 | |
3948 | @@ -550,6 +563,7 @@ |
3949 | } |
3950 | Condition_ptr pushNegation(negstat_t&, const EvaluationContext& context, bool nested, bool negated, bool initrw) override; |
3951 | void toXML(std::ostream&, uint32_t tabs) const override; |
3952 | + void toCompactXML(std::ostream&, uint32_t tabs, AnalysisContext& context) const override; |
3953 | Quantifier getQuantifier() const override { return Quantifier::EMPTY; } |
3954 | Path getPath() const override { return Path::F; } |
3955 | uint32_t distance(DistanceContext& context) const override { |
3956 | @@ -577,6 +591,7 @@ |
3957 | Condition_ptr pushNegation(negstat_t&, const EvaluationContext& context, bool nested, bool negated, bool initrw) override; |
3958 | Retval simplify(SimplificationContext& context) const override; |
3959 | void toXML(std::ostream&, uint32_t tabs) const override; |
3960 | + void toCompactXML(std::ostream&, uint32_t tabs, AnalysisContext& context) const override; |
3961 | Quantifier getQuantifier() const override { return Quantifier::EMPTY; } |
3962 | Path getPath() const override { return Path::X; } |
3963 | uint32_t distance(DistanceContext& context) const override { |
3964 | @@ -598,6 +613,7 @@ |
3965 | Condition_ptr prepareForReachability(bool negated) const override; |
3966 | Condition_ptr pushNegation(negstat_t&, const EvaluationContext& context, bool nested, bool negated, bool initrw) override; |
3967 | void toXML(std::ostream&, uint32_t tabs) const override; |
3968 | + void toCompactXML(std::ostream&, uint32_t tabs, AnalysisContext& context) const override; |
3969 | Quantifier getQuantifier() const override { return Quantifier::E; } |
3970 | Path getPath() const override { return Path::X; } |
3971 | uint32_t distance(DistanceContext& context) const override; |
3972 | @@ -618,6 +634,7 @@ |
3973 | Condition_ptr prepareForReachability(bool negated) const override; |
3974 | Condition_ptr pushNegation(negstat_t&, const EvaluationContext& context, bool nested, bool negated, bool initrw) override; |
3975 | void toXML(std::ostream&, uint32_t tabs) const override; |
3976 | + void toCompactXML(std::ostream&, uint32_t tabs, AnalysisContext& context) const override; |
3977 | Quantifier getQuantifier() const override { return Quantifier::E; } |
3978 | Path getPath() const override { return Path::G; } |
3979 | uint32_t distance(DistanceContext& context) const override; |
3980 | @@ -639,6 +656,7 @@ |
3981 | Condition_ptr prepareForReachability(bool negated) const override; |
3982 | Condition_ptr pushNegation(negstat_t&, const EvaluationContext& context, bool nested, bool negated, bool initrw) override; |
3983 | void toXML(std::ostream&, uint32_t tabs) const override; |
3984 | + void toCompactXML(std::ostream&, uint32_t tabs, AnalysisContext& context) const override; |
3985 | Quantifier getQuantifier() const override { return Quantifier::E; } |
3986 | Path getPath() const override { return Path::F; } |
3987 | uint32_t distance(DistanceContext& context) const override; |
3988 | @@ -658,6 +676,7 @@ |
3989 | Condition_ptr prepareForReachability(bool negated) const override; |
3990 | Condition_ptr pushNegation(negstat_t&, const EvaluationContext& context, bool nested, bool negated, bool initrw) override; |
3991 | void toXML(std::ostream&, uint32_t tabs) const override; |
3992 | + void toCompactXML(std::ostream&, uint32_t tabs, AnalysisContext& context) const override; |
3993 | Quantifier getQuantifier() const override { return Quantifier::A; } |
3994 | Path getPath() const override { return Path::X; } |
3995 | uint32_t distance(DistanceContext& context) const override; |
3996 | @@ -677,6 +696,7 @@ |
3997 | Condition_ptr prepareForReachability(bool negated) const override; |
3998 | Condition_ptr pushNegation(negstat_t&, const EvaluationContext& context, bool nested, bool negated, bool initrw) override; |
3999 | void toXML(std::ostream&, uint32_t tabs) const override; |
4000 | + void toCompactXML(std::ostream&, uint32_t tabs, AnalysisContext& context) const override; |
4001 | Quantifier getQuantifier() const override { return Quantifier::A; } |
4002 | Path getPath() const override { return Path::G; } |
4003 | uint32_t distance(DistanceContext& context) const override; |
4004 | @@ -696,6 +716,7 @@ |
4005 | Condition_ptr prepareForReachability(bool negated) const override; |
4006 | Condition_ptr pushNegation(negstat_t&, const EvaluationContext& context, bool nested, bool negated, bool initrw) override; |
4007 | void toXML(std::ostream&, uint32_t tabs) const override; |
4008 | + void toCompactXML(std::ostream&, uint32_t tabs, AnalysisContext& context) const override; |
4009 | Quantifier getQuantifier() const override { return Quantifier::A; } |
4010 | Path getPath() const override { return Path::F; } |
4011 | uint32_t distance(DistanceContext& context) const override; |
4012 | @@ -742,6 +763,7 @@ |
4013 | void visit(Visitor&) const override; |
4014 | void visit(MutatingVisitor&) override; |
4015 | void toXML(std::ostream&, uint32_t tabs) const override; |
4016 | + void toCompactXML(std::ostream&, uint32_t tabs, AnalysisContext& context) const override; |
4017 | uint32_t distance(DistanceContext& context) const override { return (*this)[1]->distance(context); } |
4018 | Quantifier getQuantifier() const override { return Quantifier::EMPTY; } |
4019 | private: |
4020 | @@ -763,6 +785,7 @@ |
4021 | uint32_t distance(DistanceContext& context) const override; |
4022 | Condition_ptr pushNegation(negstat_t&, const EvaluationContext& context, bool nested, bool negated, bool initrw) override; |
4023 | void toXML(std::ostream&, uint32_t tabs) const override; |
4024 | + void toCompactXML(std::ostream&, uint32_t tabs, AnalysisContext& context) const override; |
4025 | |
4026 | private: |
4027 | std::string op() const override; |
4028 | @@ -777,6 +800,7 @@ |
4029 | void visit(MutatingVisitor&) override; |
4030 | uint32_t distance(DistanceContext& context) const override; |
4031 | void toXML(std::ostream&, uint32_t tabs) const override; |
4032 | + void toCompactXML(std::ostream&, uint32_t tabs, AnalysisContext& context) const override; |
4033 | Condition_ptr pushNegation(negstat_t&, const EvaluationContext& context, bool nested, bool negated, bool initrw) override; |
4034 | virtual bool isLoopSensitive() const override { return true; } |
4035 | private: |
4036 | @@ -794,6 +818,8 @@ |
4037 | std::string getName() const { |
4038 | return _name; |
4039 | } |
4040 | + void toXML(std::ostream& out, uint32_t tabs) const override; |
4041 | + void toCompactXML(std::ostream&, uint32_t tabs, AnalysisContext& context) const override; |
4042 | protected: |
4043 | void _analyze(AnalysisContext& context) override; |
4044 | |
4045 | @@ -810,7 +836,7 @@ |
4046 | Condition_ptr pushNegation(negstat_t& stat, const EvaluationContext& context, bool nested, bool negated, bool initrw) override; |
4047 | void visit(Visitor&) const override; |
4048 | void visit(MutatingVisitor&) override; |
4049 | - |
4050 | + void toCompactXML(std::ostream&, uint32_t tabs, AnalysisContext& context) const override; |
4051 | std::string getName() const { |
4052 | return _name; |
4053 | } |
4054 | @@ -890,6 +916,7 @@ |
4055 | void visit(Visitor&) const override; |
4056 | void visit(MutatingVisitor&) override; |
4057 | void toXML(std::ostream&, uint32_t tabs) const override; |
4058 | + void toCompactXML(std::ostream&, uint32_t tabs, AnalysisContext& context) const override; |
4059 | Quantifier getQuantifier() const override { return Quantifier::AND; } |
4060 | Condition_ptr pushNegation(negstat_t&, const EvaluationContext& context, bool nested, bool negated, bool initrw) override; |
4061 | uint32_t distance(DistanceContext& context) const override; |
4062 | @@ -914,6 +941,7 @@ |
4063 | void visit(Visitor&) const override; |
4064 | void visit(MutatingVisitor&) override; |
4065 | void toXML(std::ostream&, uint32_t tabs) const override; |
4066 | + void toCompactXML(std::ostream&, uint32_t tabs, AnalysisContext& context) const override; |
4067 | |
4068 | Quantifier getQuantifier() const override { return Quantifier::OR; } |
4069 | Condition_ptr pushNegation(negstat_t&, const EvaluationContext& context, bool nested, bool negated, bool initrw) override; |
4070 | @@ -1001,6 +1029,7 @@ |
4071 | CTLType getQueryType() const override { return CTLType::LOPERATOR; } |
4072 | Path getPath() const override { return Path::pError; } |
4073 | virtual void toXML(std::ostream& stream, uint32_t tabs) const override; |
4074 | + void toCompactXML(std::ostream&, uint32_t tabs, AnalysisContext& context) const override; |
4075 | Retval simplify(SimplificationContext& context) const override; |
4076 | Result evaluate(const EvaluationContext& context) override; |
4077 | Result evalAndSet(const EvaluationContext& context) override; |
4078 | @@ -1090,6 +1119,7 @@ |
4079 | using CompareCondition::CompareCondition; |
4080 | Retval simplify(SimplificationContext& context) const override; |
4081 | void toXML(std::ostream&, uint32_t tabs) const override; |
4082 | + void toCompactXML(std::ostream&, uint32_t tabs, AnalysisContext& context) const override; |
4083 | |
4084 | uint32_t distance(DistanceContext& context) const override; |
4085 | Condition_ptr pushNegation(negstat_t&, const EvaluationContext& context, bool nested, bool negated, bool initrw) override; |
4086 | @@ -1110,6 +1140,7 @@ |
4087 | void toTAPAALQuery(std::ostream&,TAPAALConditionExportContext& context) const override; |
4088 | Retval simplify(SimplificationContext& context) const override; |
4089 | void toXML(std::ostream&, uint32_t tabs) const override; |
4090 | + void toCompactXML(std::ostream&, uint32_t tabs, AnalysisContext& context) const override; |
4091 | |
4092 | |
4093 | uint32_t distance(DistanceContext& context) const override; |
4094 | @@ -1130,6 +1161,7 @@ |
4095 | using CompareCondition::CompareCondition; |
4096 | Retval simplify(SimplificationContext& context) const override; |
4097 | void toXML(std::ostream&, uint32_t tabs) const override; |
4098 | + void toCompactXML(std::ostream&, uint32_t tabs, AnalysisContext& context) const override; |
4099 | |
4100 | uint32_t distance(DistanceContext& context) const override; |
4101 | Condition_ptr pushNegation(negstat_t&, const EvaluationContext& context, bool nested, bool negated, bool initrw) override; |
4102 | @@ -1149,6 +1181,7 @@ |
4103 | using CompareCondition::CompareCondition; |
4104 | Retval simplify(SimplificationContext& context) const override; |
4105 | void toXML(std::ostream&, uint32_t tabs) const override; |
4106 | + void toCompactXML(std::ostream&, uint32_t tabs, AnalysisContext& context) const override; |
4107 | |
4108 | uint32_t distance(DistanceContext& context) const override; |
4109 | Condition_ptr pushNegation(negstat_t&, const EvaluationContext& context, bool nested, bool negated, bool initrw) override; |
4110 | @@ -1191,6 +1224,7 @@ |
4111 | Condition_ptr pushNegation(negstat_t&, const EvaluationContext& context, bool nested, bool negated, bool initrw) override; |
4112 | void toXML(std::ostream&, uint32_t tabs) const override; |
4113 | void toBinary(std::ostream&) const override; |
4114 | + void toCompactXML(std::ostream&, uint32_t tabs, AnalysisContext& context) const override; |
4115 | |
4116 | Quantifier getQuantifier() const override { return Quantifier::EMPTY; } |
4117 | Path getPath() const override { return Path::pError; } |
4118 | @@ -1223,6 +1257,7 @@ |
4119 | Condition_ptr pushNegation(negstat_t&, const EvaluationContext& context, bool nested, bool negated, bool initrw) override; |
4120 | void toXML(std::ostream&, uint32_t tabs) const override; |
4121 | void toBinary(std::ostream&) const override; |
4122 | + void toCompactXML(std::ostream&, uint32_t tabs, AnalysisContext& context) const override; |
4123 | |
4124 | static Condition_ptr DEADLOCK; |
4125 | Quantifier getQuantifier() const override { return Quantifier::DEADLOCK; } |
4126 | @@ -1355,6 +1390,7 @@ |
4127 | Condition_ptr prepareForReachability(bool negated) const override; |
4128 | Condition_ptr pushNegation(negstat_t&, const EvaluationContext& context, bool nested, bool negated, bool initrw) override; |
4129 | void toXML(std::ostream&, uint32_t tabs) const override; |
4130 | + void toCompactXML(std::ostream&, uint32_t tabs, AnalysisContext& context) const override; |
4131 | |
4132 | Quantifier getQuantifier() const override { return Quantifier::UPPERBOUNDS; } |
4133 | Path getPath() const override { return Path::pError; } |
4134 | |
4135 | === modified file 'include/PetriEngine/PQL/PQL.h' |
4136 | --- include/PetriEngine/PQL/PQL.h 2021-03-23 14:10:04 +0000 |
4137 | +++ include/PetriEngine/PQL/PQL.h 2021-07-07 08:15:00 +0000 |
4138 | @@ -120,6 +120,7 @@ |
4139 | /** Output the expression as it currently is to a file in XML */ |
4140 | virtual void toXML(std::ostream&, uint32_t tabs, bool tokencount = false) const = 0; |
4141 | virtual void toBinary(std::ostream&) const = 0; |
4142 | + virtual void toCompactXML(std::ostream&, uint32_t tabs, AnalysisContext& context, bool tokencount = false) const = 0; |
4143 | |
4144 | /** Count size of the entire formula in number of nodes */ |
4145 | [[nodiscard]] virtual int formulaSize() const = 0; |
4146 | @@ -231,6 +232,7 @@ |
4147 | |
4148 | /** Output the condition as it currently is to a file in XML */ |
4149 | virtual void toXML(std::ostream&, uint32_t tabs) const = 0; |
4150 | + virtual void toCompactXML(std::ostream&, uint32_t tabs, AnalysisContext& context) const = 0; |
4151 | virtual void toBinary(std::ostream& out) const = 0; |
4152 | |
4153 | /** Checks if the condition is trivially true */ |
4154 | |
4155 | === modified file 'include/PetriEngine/PetriNetBuilder.h' |
4156 | --- include/PetriEngine/PetriNetBuilder.h 2021-03-05 16:43:31 +0000 |
4157 | +++ include/PetriEngine/PetriNetBuilder.h 2021-07-07 08:15:00 +0000 |
4158 | @@ -135,8 +135,8 @@ |
4159 | std::vector< std::tuple<double, double> > _placelocations; |
4160 | std::vector< std::tuple<double, double> > _transitionlocations; |
4161 | |
4162 | - std::vector<Transition> _transitions; |
4163 | - std::vector<Place> _places; |
4164 | + std::vector<PetriEngine::Transition> _transitions; |
4165 | + std::vector<PetriEngine::Place> _places; |
4166 | |
4167 | std::vector<MarkVal> initialMarking; |
4168 | Reducer reducer; |
4169 | |
4170 | === modified file 'include/PetriEngine/Reducer.h' |
4171 | --- include/PetriEngine/Reducer.h 2021-06-22 09:25:10 +0000 |
4172 | +++ include/PetriEngine/Reducer.h 2021-07-07 08:15:00 +0000 |
4173 | @@ -14,7 +14,6 @@ |
4174 | #include "NetStructures.h" |
4175 | |
4176 | #include <vector> |
4177 | -#include <optional> |
4178 | |
4179 | namespace PetriEngine { |
4180 | |
4181 | @@ -132,7 +131,7 @@ |
4182 | bool ReducebyRuleA(uint32_t* placeInQuery); |
4183 | bool ReducebyRuleB(uint32_t* placeInQuery, bool remove_deadlocks, bool remove_consumers); |
4184 | bool ReducebyRuleC(uint32_t* placeInQuery); |
4185 | - bool ReducebyRuleD(uint32_t *placeInQuery, bool remove_consumers); |
4186 | + bool ReducebyRuleD(uint32_t* placeInQuery); |
4187 | bool ReducebyRuleE(uint32_t* placeInQuery); |
4188 | bool ReducebyRuleI(uint32_t* placeInQuery, bool remove_loops, bool remove_consumers); |
4189 | bool ReducebyRuleF(uint32_t* placeInQuery); |
4190 | @@ -147,9 +146,9 @@ |
4191 | std::string getTransitionName(uint32_t transition); |
4192 | std::string getPlaceName(uint32_t place); |
4193 | |
4194 | - Transition& getTransition(uint32_t transition); |
4195 | - ArcIter getOutArc(Transition&, uint32_t place); |
4196 | - ArcIter getInArc(uint32_t place, Transition&); |
4197 | + PetriEngine::Transition& getTransition(uint32_t transition); |
4198 | + ArcIter getOutArc(PetriEngine::Transition&, uint32_t place); |
4199 | + ArcIter getInArc(uint32_t place, PetriEngine::Transition&); |
4200 | void eraseTransition(std::vector<uint32_t>&, uint32_t); |
4201 | void skipTransition(uint32_t); |
4202 | void skipPlace(uint32_t); |
4203 | |
4204 | === modified file 'include/PetriEngine/TAR/range.h' |
4205 | --- include/PetriEngine/TAR/range.h 2021-02-18 12:01:45 +0000 |
4206 | +++ include/PetriEngine/TAR/range.h 2021-07-07 08:15:00 +0000 |
4207 | @@ -56,11 +56,11 @@ |
4208 | return no_lower() && no_upper(); |
4209 | } |
4210 | |
4211 | - bool isSound() { |
4212 | + bool isSound() const { |
4213 | return _lower <= _upper; |
4214 | } |
4215 | |
4216 | - bool contains(uint32_t id){ |
4217 | + bool contains(uint32_t id) const { |
4218 | return _lower <= id && id <= _upper; |
4219 | } |
4220 | |
4221 | @@ -69,7 +69,7 @@ |
4222 | _lower = min(); |
4223 | } |
4224 | |
4225 | - uint32_t size(){ |
4226 | + uint32_t size() const { |
4227 | return 1 + _upper - _lower; |
4228 | } |
4229 | |
4230 | @@ -99,6 +99,10 @@ |
4231 | ); |
4232 | } |
4233 | |
4234 | + bool intersects(const range_t& other) const { |
4235 | + return _lower <= other._upper && other._lower <= _upper; |
4236 | + } |
4237 | + |
4238 | range_t& operator&=(const range_t& other) { |
4239 | _lower = std::max(_lower, other._lower); |
4240 | _upper = std::min(_upper, other._upper); |
4241 | |
4242 | === modified file 'include/PetriEngine/options.h' |
4243 | --- include/PetriEngine/options.h 2021-04-14 11:51:52 +0000 |
4244 | +++ include/PetriEngine/options.h 2021-07-07 08:15:00 +0000 |
4245 | @@ -41,13 +41,14 @@ |
4246 | bool printstatistics = true; |
4247 | std::set<size_t> querynumbers; |
4248 | PetriEngine::Reachability::Strategy strategy = PetriEngine::Reachability::DEFAULT; |
4249 | - int queryReductionTimeout = 30, intervalTimeout = 10, lpsolveTimeout = 10; |
4250 | + int queryReductionTimeout = 30, intervalTimeout = 10, partitionTimeout = 5, lpsolveTimeout = 10; |
4251 | TraceLevel trace = TraceLevel::None; |
4252 | bool use_query_reductions = true; |
4253 | uint32_t siphontrapTimeout = 0; |
4254 | uint32_t siphonDepth = 0; |
4255 | uint32_t cores = 1; |
4256 | std::string output_stats; |
4257 | + bool doVerification = true; |
4258 | |
4259 | TemporalLogic logic = TemporalLogic::CTL; |
4260 | bool noreach = false; |
4261 | @@ -68,12 +69,15 @@ |
4262 | |
4263 | std::string query_out_file; |
4264 | std::string model_out_file; |
4265 | + std::string unfolded_out_file; |
4266 | + std::string unfold_query_out_file; |
4267 | |
4268 | |
4269 | //CPN Specific options |
4270 | bool cpnOverApprox = false; |
4271 | bool computeCFP = true; |
4272 | bool computePartition = true; |
4273 | + bool symmetricVariables = true; |
4274 | bool isCPN = false; |
4275 | uint32_t seed_offset = 0; |
4276 | int max_intervals = 250; //0 disabled |
4277 | |
4278 | === modified file 'include/PetriParse/PNMLParser.h' |
4279 | --- include/PetriParse/PNMLParser.h 2021-04-22 12:43:03 +0000 |
4280 | +++ include/PetriParse/PNMLParser.h 2021-07-07 08:15:00 +0000 |
4281 | @@ -39,6 +39,7 @@ |
4282 | std::string source, |
4283 | target; |
4284 | int weight; |
4285 | + bool inhib; |
4286 | PetriEngine::Colored::ArcExpression_ptr expr; |
4287 | }; |
4288 | typedef std::vector<Arc> ArcList; |
4289 | @@ -58,8 +59,8 @@ |
4290 | }; |
4291 | typedef std::unordered_map<std::string, NodeName> NodeNameMap; |
4292 | |
4293 | - typedef std::unordered_map<std::string, PetriEngine::Colored::ColorType*> ColorTypeMap; |
4294 | - typedef std::unordered_map<std::string, PetriEngine::Colored::Variable*> VariableMap; |
4295 | + typedef std::unordered_map<std::string, const PetriEngine::Colored::ColorType*> ColorTypeMap; |
4296 | + typedef std::unordered_map<std::string, const PetriEngine::Colored::Variable*> VariableMap; |
4297 | |
4298 | public: |
4299 | |
4300 | @@ -89,7 +90,7 @@ |
4301 | PetriEngine::Colored::GuardExpression_ptr parseGuardExpression(rapidxml::xml_node<>* element, bool notFlag); |
4302 | PetriEngine::Colored::ColorExpression_ptr parseColorExpression(rapidxml::xml_node<>* element); |
4303 | PetriEngine::Colored::AllExpression_ptr parseAllExpression(rapidxml::xml_node<>* element); |
4304 | - PetriEngine::Colored::ColorType* parseUserSort(rapidxml::xml_node<>* element); |
4305 | + const PetriEngine::Colored::ColorType* parseUserSort(rapidxml::xml_node<>* element); |
4306 | PetriEngine::Colored::ArcExpression_ptr parseNumberOfExpression(rapidxml::xml_node<>* element); |
4307 | void collectColorsInTuple(rapidxml::xml_node<>* element,std::vector<std::vector<PetriEngine::Colored::ColorExpression_ptr>>& collectedColors); |
4308 | PetriEngine::Colored::ArcExpression_ptr constructAddExpressionFromTupleExpression(rapidxml::xml_node<>* element,std::vector<std::vector<PetriEngine::Colored::ColorExpression_ptr>> collectedColors, uint32_t numberof); |
4309 | @@ -106,7 +107,6 @@ |
4310 | PetriEngine::AbstractPetriNetBuilder* builder; |
4311 | NodeNameMap id2name; |
4312 | ArcList arcs; |
4313 | - ArcList inhibarcs; |
4314 | TransitionList transitions; |
4315 | ColorTypeMap colorTypes; |
4316 | VariableMap variables; |
4317 | |
4318 | === modified file 'src/LTL/LTLMain.cpp' |
4319 | --- src/LTL/LTLMain.cpp 2021-06-06 19:08:53 +0000 |
4320 | +++ src/LTL/LTLMain.cpp 2021-07-07 08:15:00 +0000 |
4321 | @@ -190,13 +190,11 @@ |
4322 | assert(false); |
4323 | std::cerr << "Error: cannot LTL verify with algorithm None"; |
4324 | } |
4325 | - bool answer = result.satisfied ^ negate_answer; |
4326 | std::cout << "FORMULA " << queryName |
4327 | - << (answer ? " TRUE" : " FALSE") << " TECHNIQUES EXPLICIT " |
4328 | + << (result.satisfied ^ negate_answer ? " TRUE" : " FALSE") << " TECHNIQUES EXPLICIT " |
4329 | << LTL::to_string(options.ltlalgorithm) |
4330 | << (result.is_weak ? " WEAK_SKIP" : "") |
4331 | << std::endl; |
4332 | - std::cout << "Query is" << (answer ? "" : " NOT") << " satisfied." << std::endl; |
4333 | #ifdef DEBUG_EXPLORED_STATES |
4334 | std::cout << "FORMULA " << queryName << " STATS EXPLORED " << result.explored_states << std::endl; |
4335 | #endif |
4336 | |
4337 | === modified file 'src/PetriEngine/Colored/BindingGenerator.cpp' |
4338 | --- src/PetriEngine/Colored/BindingGenerator.cpp 2021-04-14 10:41:18 +0000 |
4339 | +++ src/PetriEngine/Colored/BindingGenerator.cpp 2021-07-07 08:15:00 +0000 |
4340 | @@ -38,20 +38,14 @@ |
4341 | _generator->nextBinding(); |
4342 | if (_generator->isInitial()) _generator = nullptr; |
4343 | return *this; |
4344 | - } |
4345 | - |
4346 | - const Colored::ExpressionContext::BindingMap NaiveBindingGenerator::Iterator::operator++(int) { |
4347 | - auto prev = _generator->currentBinding(); |
4348 | - ++*this; |
4349 | - return prev; |
4350 | - } |
4351 | - |
4352 | - Colored::ExpressionContext::BindingMap& NaiveBindingGenerator::Iterator::operator*() { |
4353 | + } |
4354 | + |
4355 | + const Colored::BindingMap& NaiveBindingGenerator::Iterator::operator*() const { |
4356 | return _generator->currentBinding(); |
4357 | } |
4358 | |
4359 | - NaiveBindingGenerator::NaiveBindingGenerator(Colored::Transition& transition, |
4360 | - ColorTypeMap& colorTypes) |
4361 | + NaiveBindingGenerator::NaiveBindingGenerator(const Colored::Transition& transition, |
4362 | + Colored::ColorTypeMap& colorTypes) |
4363 | : _colorTypes(colorTypes) |
4364 | { |
4365 | _expr = transition.guard; |
4366 | @@ -59,15 +53,15 @@ |
4367 | if (_expr != nullptr) { |
4368 | _expr->getVariables(variables); |
4369 | } |
4370 | - for (auto arc : transition.input_arcs) { |
4371 | - assert(arc.expr != nullptr); |
4372 | - arc.expr->getVariables(variables); |
4373 | - } |
4374 | - for (auto arc : transition.output_arcs) { |
4375 | - assert(arc.expr != nullptr); |
4376 | - arc.expr->getVariables(variables); |
4377 | - } |
4378 | - for (auto var : variables) { |
4379 | + for (const auto& arc : transition.input_arcs) { |
4380 | + assert(arc.expr != nullptr); |
4381 | + arc.expr->getVariables(variables); |
4382 | + } |
4383 | + for (const auto& arc : transition.output_arcs) { |
4384 | + assert(arc.expr != nullptr); |
4385 | + arc.expr->getVariables(variables); |
4386 | + } |
4387 | + for (const auto& var : variables) { |
4388 | _bindings[var] = &var->colorType->operator[](0); |
4389 | } |
4390 | |
4391 | @@ -75,21 +69,21 @@ |
4392 | nextBinding(); |
4393 | } |
4394 | |
4395 | - bool NaiveBindingGenerator::eval() { |
4396 | + bool NaiveBindingGenerator::eval() const { |
4397 | if (_expr == nullptr) |
4398 | return true; |
4399 | Colored::EquivalenceVec placePartition; |
4400 | |
4401 | - Colored::ExpressionContext context {_bindings, _colorTypes, placePartition}; |
4402 | + const Colored::ExpressionContext &context {_bindings, _colorTypes, placePartition}; |
4403 | return _expr->eval(context); |
4404 | } |
4405 | |
4406 | - Colored::ExpressionContext::BindingMap& NaiveBindingGenerator::nextBinding() { |
4407 | + const Colored::BindingMap& NaiveBindingGenerator::nextBinding() { |
4408 | bool test = false; |
4409 | while (!test) { |
4410 | - for (auto& _binding : _bindings) { |
4411 | - _binding.second = &_binding.second->operator++(); |
4412 | - if (_binding.second->getId() != 0) { |
4413 | + for (auto& binding : _bindings) { |
4414 | + binding.second = &binding.second->operator++(); |
4415 | + if (binding.second->getId() != 0) { |
4416 | break; |
4417 | } |
4418 | } |
4419 | @@ -102,7 +96,7 @@ |
4420 | return _bindings; |
4421 | } |
4422 | |
4423 | - Colored::ExpressionContext::BindingMap& NaiveBindingGenerator::currentBinding() { |
4424 | + const Colored::BindingMap& NaiveBindingGenerator::currentBinding() const { |
4425 | return _bindings; |
4426 | } |
4427 | |
4428 | @@ -122,9 +116,8 @@ |
4429 | } |
4430 | |
4431 | |
4432 | - |
4433 | - FixpointBindingGenerator::Iterator::Iterator(FixpointBindingGenerator* generator) |
4434 | - : _generator(generator) |
4435 | + FixpointBindingGenerator::Iterator::Iterator(FixpointBindingGenerator* generator) |
4436 | + : _generator(generator) |
4437 | { |
4438 | } |
4439 | |
4440 | @@ -148,94 +141,143 @@ |
4441 | return *this; |
4442 | } |
4443 | |
4444 | - const Colored::ExpressionContext::BindingMap FixpointBindingGenerator::Iterator::operator++(int) { |
4445 | - auto prev = _generator->currentBinding(); |
4446 | - ++*this; |
4447 | - return prev; |
4448 | - } |
4449 | - |
4450 | - Colored::ExpressionContext::BindingMap& FixpointBindingGenerator::Iterator::operator*() { |
4451 | + const Colored::BindingMap& FixpointBindingGenerator::Iterator::operator*() const { |
4452 | return _generator->currentBinding(); |
4453 | } |
4454 | |
4455 | - FixpointBindingGenerator::FixpointBindingGenerator(Colored::Transition& transition, |
4456 | - ColorTypeMap& colorTypes) |
4457 | - : _colorTypes(colorTypes), _transition(transition) |
4458 | + FixpointBindingGenerator::FixpointBindingGenerator(const Colored::Transition& transition, |
4459 | + const Colored::ColorTypeMap& colorTypes, const std::vector<std::set<const Colored::Variable *>>& symmetric_vars) |
4460 | + : _expr(transition.guard), _colorTypes(colorTypes), _transition(transition), _symmetric_vars(symmetric_vars) |
4461 | { |
4462 | _isDone = false; |
4463 | _noValidBindings = false; |
4464 | _nextIndex = 0; |
4465 | - _expr = _transition.guard; |
4466 | |
4467 | std::set<const Colored::Variable*> variables; |
4468 | if (_expr != nullptr) { |
4469 | _expr->getVariables(variables); |
4470 | } |
4471 | - for (auto arc : _transition.input_arcs) { |
4472 | - assert(arc.expr != nullptr); |
4473 | - arc.expr->getVariables(variables); |
4474 | - } |
4475 | - for (auto arc : _transition.output_arcs) { |
4476 | - assert(arc.expr != nullptr); |
4477 | - arc.expr->getVariables(variables); |
4478 | + for (const auto &arc : _transition.input_arcs) { |
4479 | + assert(arc.expr != nullptr); |
4480 | + arc.expr->getVariables(variables); |
4481 | + } |
4482 | + for (const auto &arc : _transition.output_arcs) { |
4483 | + assert(arc.expr != nullptr); |
4484 | + arc.expr->getVariables(variables); |
4485 | + } |
4486 | + |
4487 | + for(const auto &varSet : symmetric_vars){ |
4488 | + std::vector<std::vector<uint32_t>> combinations; |
4489 | + std::vector<uint32_t> temp; |
4490 | + generateCombinations(varSet.begin().operator*()->colorType->size()-1, varSet.size(), combinations, temp); |
4491 | + _symmetric_var_combinations.push_back(combinations); |
4492 | } |
4493 | |
4494 | |
4495 | - for (auto var : variables) { |
4496 | - if(_transition.variableMaps.empty() || _transition.variableMaps[_nextIndex][var]._intervals.empty()){ |
4497 | + for (auto* var : variables) { |
4498 | + if(_transition.variableMaps.empty() || _transition.variableMaps[_nextIndex].find(var)->second.empty()){ |
4499 | _noValidBindings = true; |
4500 | break; |
4501 | } |
4502 | - auto color = var->colorType->getColor(_transition.variableMaps[_nextIndex][var].getFirst().getLowerIds()); |
4503 | + auto color = var->colorType->getColor(_transition.variableMaps[_nextIndex].find(var)->second.front().getLowerIds()); |
4504 | _bindings[var] = color; |
4505 | } |
4506 | + assignSymmetricVars(); |
4507 | |
4508 | if (!_noValidBindings && !eval()) |
4509 | nextBinding(); |
4510 | } |
4511 | |
4512 | - |
4513 | - bool FixpointBindingGenerator::eval() { |
4514 | + bool FixpointBindingGenerator::assignSymmetricVars(){ |
4515 | + if(_currentOuterId < _symmetric_vars.size()){ |
4516 | + if(_currentInnerId >= _symmetric_var_combinations[_currentOuterId].size()){ |
4517 | + _currentOuterId++; |
4518 | + _currentInnerId = 0; |
4519 | + } |
4520 | + } else { |
4521 | + return false; |
4522 | + } |
4523 | + uint32_t j = 0; |
4524 | + for(auto var : _symmetric_vars[_currentOuterId]){ |
4525 | + _bindings[var] = &var->colorType->operator[](_symmetric_var_combinations[_currentOuterId][_currentInnerId][j]); |
4526 | + j++; |
4527 | + } |
4528 | + _currentInnerId++; |
4529 | + if(_currentInnerId >= _symmetric_var_combinations[_currentOuterId].size()){ |
4530 | + if(_currentOuterId < _symmetric_vars.size()){ |
4531 | + _currentOuterId++; |
4532 | + _currentInnerId = 0; |
4533 | + } else { |
4534 | + return false; |
4535 | + } |
4536 | + } |
4537 | + return true; |
4538 | + } |
4539 | + |
4540 | + |
4541 | + bool FixpointBindingGenerator::eval() const{ |
4542 | if (_expr == nullptr) |
4543 | return true; |
4544 | |
4545 | Colored::EquivalenceVec placePartition; |
4546 | - Colored::ExpressionContext context {_bindings, _colorTypes, placePartition}; |
4547 | + const Colored::ExpressionContext &context {_bindings, _colorTypes, placePartition}; |
4548 | return _expr->eval(context); |
4549 | } |
4550 | |
4551 | - Colored::ExpressionContext::BindingMap& FixpointBindingGenerator::nextBinding() { |
4552 | + const Colored::BindingMap& FixpointBindingGenerator::nextBinding() { |
4553 | bool test = false; |
4554 | while (!test) { |
4555 | bool next = true; |
4556 | |
4557 | - for (auto& _binding : _bindings) { |
4558 | - auto varInterval = _transition.variableMaps[_nextIndex][_binding.first]; |
4559 | - std::vector<uint32_t> colorIds; |
4560 | - _binding.second->getTupleId(&colorIds); |
4561 | - auto nextIntervalBinding = varInterval.isRangeEnd(colorIds); |
4562 | - |
4563 | - if (nextIntervalBinding.size() == 0){ |
4564 | - _binding.second = &_binding.second->operator++(); |
4565 | - next = false; |
4566 | - break; |
4567 | - } else { |
4568 | - _binding.second = _binding.second->getColorType()->getColor(nextIntervalBinding.getLowerIds()); |
4569 | - |
4570 | - if(!nextIntervalBinding.equals(varInterval.getFirst())){ |
4571 | + if(assignSymmetricVars()){ |
4572 | + next = false; |
4573 | + } else { |
4574 | + for (auto& binding : _bindings) { |
4575 | + bool varSymmetric = false; |
4576 | + for(auto& set : _symmetric_vars){ |
4577 | + if(set.find(binding.first) != set.end()){ |
4578 | + varSymmetric = true; |
4579 | + break; |
4580 | + } |
4581 | + } |
4582 | + if(varSymmetric){ |
4583 | + continue; |
4584 | + } |
4585 | + |
4586 | + const auto &varInterval = _transition.variableMaps[_nextIndex].find(binding.first)->second; |
4587 | + std::vector<uint32_t> colorIds; |
4588 | + binding.second->getTupleId(colorIds); |
4589 | + const auto &nextIntervalBinding = varInterval.isRangeEnd(colorIds); |
4590 | + |
4591 | + if (nextIntervalBinding.size() == 0){ |
4592 | + binding.second = &binding.second->operator++(); |
4593 | + _currentInnerId = 0; |
4594 | + _currentOuterId = 0; |
4595 | + assignSymmetricVars(); |
4596 | next = false; |
4597 | - break; |
4598 | - } |
4599 | + break; |
4600 | + } else { |
4601 | + binding.second = binding.second->getColorType()->getColor(nextIntervalBinding.getLowerIds()); |
4602 | + _currentInnerId = 0; |
4603 | + _currentOuterId = 0; |
4604 | + assignSymmetricVars(); |
4605 | + if(!nextIntervalBinding.equals(varInterval.front())){ |
4606 | + next = false; |
4607 | + |
4608 | + break; |
4609 | + } |
4610 | + } |
4611 | } |
4612 | - } |
4613 | + } |
4614 | + |
4615 | if(next){ |
4616 | _nextIndex++; |
4617 | if(isInitial()){ |
4618 | _isDone = true; |
4619 | break; |
4620 | } |
4621 | - for(auto& _binding : _bindings){ |
4622 | - _binding.second = _binding.second->getColorType()->getColor(_transition.variableMaps[_nextIndex][_binding.first].getFirst().getLowerIds()); |
4623 | + for(auto& binding : _bindings){ |
4624 | + binding.second = binding.second->getColorType()->getColor(_transition.variableMaps[_nextIndex].find(binding.first)->second.front().getLowerIds()); |
4625 | } |
4626 | } |
4627 | test = eval(); |
4628 | @@ -244,11 +286,27 @@ |
4629 | return _bindings; |
4630 | } |
4631 | |
4632 | - Colored::ExpressionContext::BindingMap& FixpointBindingGenerator::currentBinding() { |
4633 | + void FixpointBindingGenerator::generateCombinations( |
4634 | + uint32_t options, |
4635 | + uint32_t samples, |
4636 | + std::vector<std::vector<uint32_t>> &result, |
4637 | + std::vector<uint32_t> ¤t) const { |
4638 | + if (samples == 0) { |
4639 | + result.push_back(current); |
4640 | + return; |
4641 | + } |
4642 | + for (uint32_t i = 0; i <= options; i++) { |
4643 | + current.push_back(i); |
4644 | + generateCombinations(i, samples - 1, result, current); |
4645 | + current.pop_back(); |
4646 | + } |
4647 | + } |
4648 | + |
4649 | + const Colored::BindingMap& FixpointBindingGenerator::currentBinding() const { |
4650 | return _bindings; |
4651 | } |
4652 | |
4653 | - bool FixpointBindingGenerator::isInitial() const{ |
4654 | + bool FixpointBindingGenerator::isInitial() const { |
4655 | return _nextIndex >= _transition.variableMaps.size(); |
4656 | } |
4657 | |
4658 | |
4659 | === modified file 'src/PetriEngine/Colored/CMakeLists.txt' |
4660 | --- src/PetriEngine/Colored/CMakeLists.txt 2021-04-14 10:41:18 +0000 |
4661 | +++ src/PetriEngine/Colored/CMakeLists.txt 2021-07-07 08:15:00 +0000 |
4662 | @@ -6,5 +6,7 @@ |
4663 | BindingGenerator.cpp |
4664 | PartitionBuilder.cpp |
4665 | EquivalenceClass.cpp |
4666 | -GuardRestrictor.cpp) |
4667 | +GuardRestrictor.cpp |
4668 | +IntervalGenerator.cpp |
4669 | +EquivalenceVec.cpp) |
4670 | add_dependencies(Colored rapidxml-ext ptrie-ext glpk-ext) |
4671 | |
4672 | === modified file 'src/PetriEngine/Colored/ColoredPetriNetBuilder.cpp' |
4673 | --- src/PetriEngine/Colored/ColoredPetriNetBuilder.cpp 2021-04-30 17:01:57 +0000 |
4674 | +++ src/PetriEngine/Colored/ColoredPetriNetBuilder.cpp 2021-07-07 08:15:00 +0000 |
4675 | @@ -19,15 +19,26 @@ |
4676 | |
4677 | #include "PetriEngine/Colored/ColoredPetriNetBuilder.h" |
4678 | #include <chrono> |
4679 | - |
4680 | +#include <tuple> |
4681 | +using std::get; |
4682 | namespace PetriEngine { |
4683 | ColoredPetriNetBuilder::ColoredPetriNetBuilder() { |
4684 | } |
4685 | |
4686 | - ColoredPetriNetBuilder::ColoredPetriNetBuilder(const ColoredPetriNetBuilder& orig) { |
4687 | + ColoredPetriNetBuilder::ColoredPetriNetBuilder(const ColoredPetriNetBuilder& orig) |
4688 | + : _placenames(orig._placenames), _transitionnames(orig._transitionnames), |
4689 | + _places(orig._places), _transitions(orig._transitions) |
4690 | + { |
4691 | } |
4692 | |
4693 | ColoredPetriNetBuilder::~ColoredPetriNetBuilder() { |
4694 | + // cleaning up colors |
4695 | + for(auto& e : _colors) |
4696 | + { |
4697 | + if(e.second != Colored::ColorType::dotInstance()) |
4698 | + delete e.second; |
4699 | + } |
4700 | + _colors.clear(); |
4701 | } |
4702 | |
4703 | void ColoredPetriNetBuilder::addPlace(const std::string& name, int tokens, double x, double y) { |
4704 | @@ -36,7 +47,7 @@ |
4705 | } |
4706 | } |
4707 | |
4708 | - void ColoredPetriNetBuilder::addPlace(const std::string& name, Colored::ColorType* type, Colored::Multiset&& tokens, double x, double y) { |
4709 | + void ColoredPetriNetBuilder::addPlace(const std::string& name, const Colored::ColorType* type, Colored::Multiset&& tokens, double x, double y) { |
4710 | if(_placenames.count(name) == 0) |
4711 | { |
4712 | uint32_t next = _placenames.size(); |
4713 | @@ -48,23 +59,33 @@ |
4714 | _placeFixpointQueue.emplace_back(next); |
4715 | } |
4716 | |
4717 | - Colored::intervalTuple_t placeConstraints; |
4718 | + Colored::interval_vector_t placeConstraints; |
4719 | Colored::ColorFixpoint colorFixpoint = {placeConstraints, !tokens.empty()}; |
4720 | + uint32_t colorCounter = 0; |
4721 | + |
4722 | + if(tokens.size() == type->size()) { |
4723 | + for(const auto& colorPair : tokens){ |
4724 | + if(colorPair.second > 0){ |
4725 | + colorCounter++; |
4726 | + } else { |
4727 | + break; |
4728 | + } |
4729 | + } |
4730 | + } |
4731 | |
4732 | - if(tokens.size() == type->size()){ |
4733 | + if(colorCounter == type->size()){ |
4734 | colorFixpoint.constraints.addInterval(type->getFullInterval()); |
4735 | } else { |
4736 | - uint32_t index = 0; |
4737 | - for (auto colorPair : tokens) { |
4738 | + for (const auto& colorPair : tokens) { |
4739 | Colored::interval_t tokenConstraints; |
4740 | - colorPair.first->getColorConstraints(&tokenConstraints, &index); |
4741 | + uint32_t index = 0; |
4742 | + colorPair.first->getColorConstraints(tokenConstraints, index); |
4743 | |
4744 | colorFixpoint.constraints.addInterval(tokenConstraints); |
4745 | - index = 0; |
4746 | } |
4747 | } |
4748 | |
4749 | - _placeColorFixpoints.push_back(colorFixpoint); |
4750 | + _placeColorFixpoints.push_back(colorFixpoint); |
4751 | } |
4752 | } |
4753 | |
4754 | @@ -89,8 +110,8 @@ |
4755 | } |
4756 | } |
4757 | |
4758 | - void ColoredPetriNetBuilder::addInputArc(const std::string& place, const std::string& transition, const Colored::ArcExpression_ptr& expr) { |
4759 | - addArc(place, transition, expr, true); |
4760 | + void ColoredPetriNetBuilder::addInputArc(const std::string& place, const std::string& transition, const Colored::ArcExpression_ptr& expr, bool inhibitor, int weight) { |
4761 | + addArc(place, transition, expr, true, inhibitor, weight); |
4762 | } |
4763 | |
4764 | void ColoredPetriNetBuilder::addOutputArc(const std::string& transition, const std::string& place, int weight) { |
4765 | @@ -100,10 +121,10 @@ |
4766 | } |
4767 | |
4768 | void ColoredPetriNetBuilder::addOutputArc(const std::string& transition, const std::string& place, const Colored::ArcExpression_ptr& expr) { |
4769 | - addArc(place, transition, expr, false); |
4770 | + addArc(place, transition, expr, false, false, 1); |
4771 | } |
4772 | |
4773 | - void ColoredPetriNetBuilder::addArc(const std::string& place, const std::string& transition, const Colored::ArcExpression_ptr& expr, bool input) { |
4774 | + void ColoredPetriNetBuilder::addArc(const std::string& place, const std::string& transition, const Colored::ArcExpression_ptr& expr, bool input, bool inhibitor, int weight) { |
4775 | if(_transitionnames.count(transition) == 0) |
4776 | { |
4777 | std::cout << "Transition '" << transition << "' not found. Adding it." << std::endl; |
4778 | @@ -125,46 +146,173 @@ |
4779 | Colored::Arc arc; |
4780 | arc.place = p; |
4781 | arc.transition = t; |
4782 | - assert(expr != nullptr); |
4783 | + _places[p].inhibitor |= inhibitor; |
4784 | + if(!inhibitor) |
4785 | + assert(expr != nullptr); |
4786 | arc.expr = std::move(expr); |
4787 | arc.input = input; |
4788 | - input? _transitions[t].input_arcs.push_back(std::move(arc)): _transitions[t].output_arcs.push_back(std::move(arc)); |
4789 | + arc.weight = weight; |
4790 | + if(inhibitor){ |
4791 | + _inhibitorArcs.push_back(std::move(arc)); |
4792 | + } else { |
4793 | + input? _transitions[t].input_arcs.push_back(std::move(arc)): _transitions[t].output_arcs.push_back(std::move(arc)); |
4794 | + } |
4795 | |
4796 | } |
4797 | |
4798 | - void ColoredPetriNetBuilder::addColorType(const std::string& id, Colored::ColorType* type) { |
4799 | + void ColoredPetriNetBuilder::addColorType(const std::string& id, const Colored::ColorType* type) { |
4800 | _colors[id] = type; |
4801 | } |
4802 | |
4803 | void ColoredPetriNetBuilder::sort() { |
4804 | } |
4805 | |
4806 | + //------------------- Symmetric Variables --------------------// |
4807 | + void ColoredPetriNetBuilder::computeSymmetricVariables(){ |
4808 | + if(_isColored){ |
4809 | + for(uint32_t transitionId = 0; transitionId < _transitions.size(); transitionId++){ |
4810 | + const Colored::Transition &transition = _transitions[transitionId]; |
4811 | + if(transition.guard){ |
4812 | + continue; |
4813 | + //the variables cannot appear on the guard |
4814 | + } |
4815 | + |
4816 | + for(const auto &inArc : transition.input_arcs){ |
4817 | + std::set<const Colored::Variable*> inArcVars; |
4818 | + std::vector<uint32_t> numbers; |
4819 | + |
4820 | + //Application of symmetric variables for partitioned places is currently unhandled |
4821 | + if(_partitionComputed && !_partition[inArc.place].isDiagonal()){ |
4822 | + continue; |
4823 | + } |
4824 | + |
4825 | + //the expressions is eligible if it is an addexpression that contains only |
4826 | + //numberOfExpressions with the same number |
4827 | + bool isEligible = inArc.expr->isEligibleForSymmetry(numbers); |
4828 | + |
4829 | + if(isEligible && numbers.size() > 1){ |
4830 | + inArc.expr->getVariables(inArcVars); |
4831 | + //It cannot be symmetric with anything if there is only one variable |
4832 | + if(inArcVars.size() < 2){ |
4833 | + continue; |
4834 | + } |
4835 | + //The variables may appear only on one input arc and one output arc |
4836 | + checkSymmetricVarsInArcs(transition, inArc, inArcVars, isEligible); |
4837 | + |
4838 | + |
4839 | + //All the variables have to appear on exactly one output arc and nowhere else |
4840 | + checkSymmetricVarsOutArcs(transition, inArcVars, isEligible); |
4841 | + }else{ |
4842 | + isEligible = false; |
4843 | + } |
4844 | + if(isEligible){ |
4845 | + symmetric_var_map[transitionId].emplace_back(inArcVars); |
4846 | + } |
4847 | + } |
4848 | + } |
4849 | + } |
4850 | + } |
4851 | + |
4852 | + void ColoredPetriNetBuilder::checkSymmetricVarsInArcs(const Colored::Transition &transition, const Colored::Arc &inArc, const std::set<const Colored::Variable*> &inArcVars, bool &isEligible ) const{ |
4853 | + for(auto& otherInArc : transition.input_arcs){ |
4854 | + if(inArc.place == otherInArc.place){ |
4855 | + continue; |
4856 | + } |
4857 | + std::set<const Colored::Variable*> otherArcVars; |
4858 | + otherInArc.expr->getVariables(otherArcVars); |
4859 | + for(auto* var : inArcVars){ |
4860 | + if(otherArcVars.find(var) != otherArcVars.end()){ |
4861 | + isEligible = false; |
4862 | + break; |
4863 | + } |
4864 | + } |
4865 | + } |
4866 | + } |
4867 | + |
4868 | + void ColoredPetriNetBuilder::checkSymmetricVarsOutArcs(const Colored::Transition &transition, const std::set<const Colored::Variable*> &inArcVars, bool &isEligible) const{ |
4869 | + uint32_t numArcs = 0; |
4870 | + bool foundSomeVars = false; |
4871 | + for(auto& outputArc : transition.output_arcs){ |
4872 | + bool foundArc = true; |
4873 | + std::set<const Colored::Variable*> otherArcVars; |
4874 | + outputArc.expr->getVariables(otherArcVars); |
4875 | + for(auto* var : inArcVars){ |
4876 | + if(otherArcVars.find(var) == otherArcVars.end()){ |
4877 | + foundArc = false; |
4878 | + } else{ |
4879 | + foundSomeVars = true; |
4880 | + } |
4881 | + } |
4882 | + if(foundArc){ |
4883 | + //Application of symmetric variables for partitioned places is currently unhandled |
4884 | + if(_partitionComputed && !_partition.find(outputArc.place)->second.isDiagonal()){ |
4885 | + isEligible = false; |
4886 | + break; |
4887 | + } |
4888 | + numArcs++; |
4889 | + //All vars were present |
4890 | + foundSomeVars = false; |
4891 | + } |
4892 | + //If some vars are present the vars are not eligible |
4893 | + if(foundSomeVars){ |
4894 | + isEligible = false; |
4895 | + break; |
4896 | + } |
4897 | + } |
4898 | + |
4899 | + if(numArcs != 1){ |
4900 | + isEligible = false; |
4901 | + } |
4902 | + } |
4903 | + |
4904 | + void ColoredPetriNetBuilder::printSymmetricVariables() const { |
4905 | + for(uint32_t transitionId = 0; transitionId < _transitions.size(); transitionId++){ |
4906 | + const auto &transition = _transitions[transitionId]; |
4907 | + if ( symmetric_var_map.find(transitionId) == symmetric_var_map.end() ) { |
4908 | + std::cout << "Transition " << transition.name << " has no symmetric variables" << std::endl; |
4909 | + }else{ |
4910 | + std::cout << "Transition " << transition.name << " has symmetric variables: " << std::endl; |
4911 | + for(const auto &set : symmetric_var_map.find(transitionId)->second){ |
4912 | + std::string toPrint = "SET: "; |
4913 | + for(auto* variable : set){ |
4914 | + toPrint += variable->name + ", "; |
4915 | + } |
4916 | + std::cout << toPrint << std::endl; |
4917 | + } |
4918 | + } |
4919 | + } |
4920 | + } |
4921 | + |
4922 | + |
4923 | //----------------------- Partitioning -----------------------// |
4924 | |
4925 | - void ColoredPetriNetBuilder::computePartition(){ |
4926 | - auto partitionStart = std::chrono::high_resolution_clock::now(); |
4927 | - Colored::PartitionBuilder pBuilder = _fixpointDone? Colored::PartitionBuilder(&_transitions, &_places, &_placePostTransitionMap, &_placePreTransitionMap, &_placeColorFixpoints) : Colored::PartitionBuilder(&_transitions, &_places, &_placePostTransitionMap, &_placePreTransitionMap); |
4928 | - |
4929 | - pBuilder.partitionNet(); |
4930 | - //pBuilder.printPartion(); |
4931 | - _partition = pBuilder.getPartition(); |
4932 | - pBuilder.assignColorMap(_partition); |
4933 | - _partitionComputed = true; |
4934 | - auto partitionEnd = std::chrono::high_resolution_clock::now(); |
4935 | - _partitionTimer = (std::chrono::duration_cast<std::chrono::microseconds>(partitionEnd - partitionStart).count())*0.000001; |
4936 | + void ColoredPetriNetBuilder::computePartition(int32_t timeout){ |
4937 | + if(_isColored){ |
4938 | + auto partitionStart = std::chrono::high_resolution_clock::now(); |
4939 | + Colored::PartitionBuilder pBuilder = _fixpointDone? Colored::PartitionBuilder(_transitions, _places, _placePostTransitionMap, _placePreTransitionMap, &_placeColorFixpoints) : Colored::PartitionBuilder(_transitions, _places, _placePostTransitionMap, _placePreTransitionMap); |
4940 | + |
4941 | + if(pBuilder.partitionNet(timeout)){ |
4942 | + //pBuilder.printPartion(); |
4943 | + _partition = pBuilder.getPartition(); |
4944 | + pBuilder.assignColorMap(_partition); |
4945 | + _partitionComputed = true; |
4946 | + } |
4947 | + auto partitionEnd = std::chrono::high_resolution_clock::now(); |
4948 | + _partitionTimer = (std::chrono::duration_cast<std::chrono::microseconds>(partitionEnd - partitionStart).count())*0.000001; |
4949 | + } |
4950 | } |
4951 | |
4952 | //----------------------- Color fixpoint -----------------------// |
4953 | |
4954 | - void ColoredPetriNetBuilder::printPlaceTable() { |
4955 | - for (auto place: _places) { |
4956 | - auto placeID = _placenames[place.name]; |
4957 | - auto placeColorFixpoint = _placeColorFixpoints[placeID]; |
4958 | + void ColoredPetriNetBuilder::printPlaceTable() const{ |
4959 | + for (const auto &place: _places) { |
4960 | + const auto &placeID = _placenames.find(place.name)->second; |
4961 | + const auto &placeColorFixpoint = _placeColorFixpoints[placeID]; |
4962 | std::cout << "Place: " << place.name << " in queue: " << placeColorFixpoint.inQueue << " with colortype " << place.type->getName() << std::endl; |
4963 | |
4964 | - for(auto fixpointPair : placeColorFixpoint.constraints._intervals) { |
4965 | + for(const auto &fixpointPair : placeColorFixpoint.constraints) { |
4966 | std::cout << "["; |
4967 | - for(auto range : fixpointPair._ranges) { |
4968 | + for(const auto &range : fixpointPair._ranges) { |
4969 | std::cout << range._lower << "-" << range._upper << ", "; |
4970 | } |
4971 | std::cout << "]"<< std::endl; |
4972 | @@ -172,61 +320,62 @@ |
4973 | std::cout << std::endl; |
4974 | } |
4975 | } |
4976 | - |
4977 | - |
4978 | - |
4979 | + |
4980 | void ColoredPetriNetBuilder::computePlaceColorFixpoint(uint32_t maxIntervals, uint32_t maxIntervalsReduced, int32_t timeout) { |
4981 | - //Start timers for timing color fixpoint creation and max interval reduction steps |
4982 | - auto start = std::chrono::high_resolution_clock::now(); |
4983 | - std::chrono::_V2::system_clock::time_point end = std::chrono::high_resolution_clock::now(); |
4984 | - auto reduceTimer = std::chrono::high_resolution_clock::now(); |
4985 | - while(!_placeFixpointQueue.empty()){ |
4986 | - //Reduce max interval once timeout passes |
4987 | - if(maxIntervals > maxIntervalsReduced && timeout > 0 && std::chrono::duration_cast<std::chrono::seconds>(end - reduceTimer).count() >= timeout){ |
4988 | - maxIntervals = maxIntervalsReduced; |
4989 | - } |
4990 | + if(_isColored){ |
4991 | + //Start timers for timing color fixpoint creation and max interval reduction steps |
4992 | + auto start = std::chrono::high_resolution_clock::now(); |
4993 | + auto end = std::chrono::high_resolution_clock::now(); |
4994 | + auto reduceTimer = std::chrono::high_resolution_clock::now(); |
4995 | + while(!_placeFixpointQueue.empty()){ |
4996 | + //Reduce max interval once timeout passes |
4997 | + if(maxIntervals > maxIntervalsReduced && timeout > 0 && std::chrono::duration_cast<std::chrono::seconds>(end - reduceTimer).count() >= timeout){ |
4998 | + maxIntervals = maxIntervalsReduced; |
4999 | + } |
5000 | + |
Generally, check if you can use const-ref, use typedefs, and try to chop your methods/functions into smaller pieces.
Also remove dead/commented out elements where it is no longer needed - and validate that the "fail on error"-pieces you removed should really be removed (i.e. the calls to std::exit).