Merge lp:~verifypn-cpn/verifypn/unfold-improve into lp:verifypn
- unfold-improve
- Merge into new-trunk
Status: | Merged |
---|---|
Approved by: | Jiri Srba |
Approved revision: | 221 |
Merged at revision: | 210 |
Proposed branch: | lp:~verifypn-cpn/verifypn/unfold-improve |
Merge into: | lp:verifypn |
Diff against target: |
728 lines (+133/-155) 7 files modified
CMakeLists.txt (+5/-3) PetriEngine/AbstractPetriNetBuilder.h (+4/-4) PetriEngine/Colored/ColoredNetStructures.h (+1/-2) PetriEngine/Colored/ColoredPetriNetBuilder.cpp (+60/-83) PetriEngine/Colored/ColoredPetriNetBuilder.h (+23/-25) PetriEngine/Colored/Expressions.h (+35/-33) PetriParse/PNMLParser.cpp (+5/-5) |
To merge this branch: | bzr merge lp:~verifypn-cpn/verifypn/unfold-improve |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Jiri Srba | Approve | ||
Review via email: mp+348445@code.launchpad.net |
Commit message
Description of the change
Improved the unfolding of colored Petri nets
Jiri Srba (srba) wrote : | # |
Jiri Srba (srba) wrote : | # |
Version 220 is also consistent, no noticable improvement (data in the spreadsheet).
Jiri Srba (srba) wrote : | # |
There are some warnings to be fixed:
PetriEngine/
temporary object prevents copy elision [-Wpessimizing-
PetriEngine/
call here
..._places.
PetriEngine/
temporary object prevents copy elision [-Wpessimizing-
PetriEngine/
call here
..._transitio
- 221. By Peter Gjøl Jensen
-
fixed warnings
Peter Gjøl Jensen (peter-gjoel) wrote : | # |
Warnings should be fixed now.
Preview Diff
1 | === modified file 'CMakeLists.txt' | |||
2 | --- CMakeLists.txt 2018-04-19 22:14:38 +0000 | |||
3 | +++ CMakeLists.txt 2018-06-26 07:06:25 +0000 | |||
4 | @@ -1,15 +1,19 @@ | |||
5 | 1 | cmake_minimum_required(VERSION 2.8.4) | 1 | cmake_minimum_required(VERSION 2.8.4) |
6 | 2 | project(verifypn) | 2 | project(verifypn) |
7 | 3 | 3 | ||
9 | 4 | if (UNIX) | 4 | if (UNIX AND NOT APPLE) |
10 | 5 | if (CMAKE_SIZEOF_VOID_P EQUAL 8) # is system 64-bit? | 5 | if (CMAKE_SIZEOF_VOID_P EQUAL 8) # is system 64-bit? |
11 | 6 | set(ARCH_TYPE "linux64") | 6 | set(ARCH_TYPE "linux64") |
12 | 7 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -flto -march=x86-64 -std=c++14 -m64 -I.") | ||
13 | 8 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -flto=4 -march=x86-64 -std=c++14 -m64 -static -static-libgcc -static-libstdc++") | ||
14 | 7 | else() | 9 | else() |
15 | 8 | set(ARCH_TYPE "linux32") | 10 | set(ARCH_TYPE "linux32") |
16 | 9 | endif () | 11 | endif () |
17 | 10 | elseif(APPLE) | 12 | elseif(APPLE) |
18 | 11 | if (CMAKE_SIZEOF_VOID_P EQUAL 8) # is system 64-bit? | 13 | if (CMAKE_SIZEOF_VOID_P EQUAL 8) # is system 64-bit? |
19 | 12 | set(ARCH_TYPE "osx64") | 14 | set(ARCH_TYPE "osx64") |
20 | 15 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=10.7 -std=c++14 -m64 -I. -stdlib=libc++") | ||
21 | 16 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -dynamic -mmacosx-version-min=10.7 -std=c++14 -m64 -stdlib=libc++ -lc++") | ||
22 | 13 | else() | 17 | else() |
23 | 14 | set(ARCH_TYPE "osx32") | 18 | set(ARCH_TYPE "osx32") |
24 | 15 | endif () | 19 | endif () |
25 | @@ -21,11 +25,9 @@ | |||
26 | 21 | endif() | 25 | endif() |
27 | 22 | endif () | 26 | endif () |
28 | 23 | 27 | ||
29 | 24 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -flto -march=x86-64 -std=c++14 -m64 -I.") | ||
30 | 25 | set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wall -pedantic-errors -O2 -DNDEBUG") | 28 | set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wall -pedantic-errors -O2 -DNDEBUG") |
31 | 26 | set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g") | 29 | set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g") |
32 | 27 | 30 | ||
33 | 28 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -flto=4 -march=x86-64 -std=c++14 -m64 -static -static-libgcc -static-libstdc++") | ||
34 | 29 | set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -O2 -DNDEBUG") | 31 | set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -O2 -DNDEBUG") |
35 | 30 | set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -g") | 32 | set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -g") |
36 | 31 | 33 | ||
37 | 32 | 34 | ||
38 | === modified file 'PetriEngine/AbstractPetriNetBuilder.h' | |||
39 | --- PetriEngine/AbstractPetriNetBuilder.h 2018-05-12 15:14:12 +0000 | |||
40 | +++ PetriEngine/AbstractPetriNetBuilder.h 2018-06-26 07:06:25 +0000 | |||
41 | @@ -42,7 +42,7 @@ | |||
42 | 42 | /** Add a new colored place with a unique name */ | 42 | /** Add a new colored place with a unique name */ |
43 | 43 | virtual void addPlace(const std::string& name, | 43 | virtual void addPlace(const std::string& name, |
44 | 44 | Colored::ColorType* type, | 44 | Colored::ColorType* type, |
46 | 45 | Colored::Multiset tokens, | 45 | Colored::Multiset&& tokens, |
47 | 46 | double x = 0, | 46 | double x = 0, |
48 | 47 | double y = 0) | 47 | double y = 0) |
49 | 48 | { | 48 | { |
50 | @@ -55,7 +55,7 @@ | |||
51 | 55 | double y = 0) = 0; | 55 | double y = 0) = 0; |
52 | 56 | /** Add a new colored transition with a unique name */ | 56 | /** Add a new colored transition with a unique name */ |
53 | 57 | virtual void addTransition(const std::string& name, | 57 | virtual void addTransition(const std::string& name, |
55 | 58 | Colored::GuardExpression_ptr guard, | 58 | const Colored::GuardExpression_ptr& guard, |
56 | 59 | double x = 0, | 59 | double x = 0, |
57 | 60 | double y = 0) | 60 | double y = 0) |
58 | 61 | { | 61 | { |
59 | @@ -70,7 +70,7 @@ | |||
60 | 70 | /** Add colored input arc with given arc expression */ | 70 | /** Add colored input arc with given arc expression */ |
61 | 71 | virtual void addInputArc(const std::string& place, | 71 | virtual void addInputArc(const std::string& place, |
62 | 72 | const std::string& transition, | 72 | const std::string& transition, |
64 | 73 | Colored::ArcExpression_ptr expr) | 73 | const Colored::ArcExpression_ptr& expr) |
65 | 74 | { | 74 | { |
66 | 75 | std::cerr << "Colored input arcs are not supported in standard P/T nets" << std::endl; | 75 | std::cerr << "Colored input arcs are not supported in standard P/T nets" << std::endl; |
67 | 76 | exit(ErrorCode); | 76 | exit(ErrorCode); |
68 | @@ -82,7 +82,7 @@ | |||
69 | 82 | /** Add output arc with given arc expression */ | 82 | /** Add output arc with given arc expression */ |
70 | 83 | virtual void addOutputArc(const std::string& transition, | 83 | virtual void addOutputArc(const std::string& transition, |
71 | 84 | const std::string& place, | 84 | const std::string& place, |
73 | 85 | Colored::ArcExpression_ptr expr) | 85 | const Colored::ArcExpression_ptr& expr) |
74 | 86 | { | 86 | { |
75 | 87 | std::cerr << "Colored output arcs are not supported in standard P/T nets" << std::endl; | 87 | std::cerr << "Colored output arcs are not supported in standard P/T nets" << std::endl; |
76 | 88 | exit(ErrorCode); | 88 | exit(ErrorCode); |
77 | 89 | 89 | ||
78 | === modified file 'PetriEngine/Colored/ColoredNetStructures.h' | |||
79 | --- PetriEngine/Colored/ColoredNetStructures.h 2018-03-13 22:08:31 +0000 | |||
80 | +++ PetriEngine/Colored/ColoredNetStructures.h 2018-06-26 07:06:25 +0000 | |||
81 | @@ -33,8 +33,7 @@ | |||
82 | 33 | struct Transition { | 33 | struct Transition { |
83 | 34 | std::string name; | 34 | std::string name; |
84 | 35 | GuardExpression_ptr guard; | 35 | GuardExpression_ptr guard; |
87 | 36 | std::vector<std::unordered_map<std::string,const Color*>> bindings; | 36 | std::vector<Arc> arcs; |
86 | 37 | std::vector<size_t> arcs; | ||
88 | 38 | }; | 37 | }; |
89 | 39 | 38 | ||
90 | 40 | struct Place { | 39 | struct Place { |
91 | 41 | 40 | ||
92 | === modified file 'PetriEngine/Colored/ColoredPetriNetBuilder.cpp' | |||
93 | --- PetriEngine/Colored/ColoredPetriNetBuilder.cpp 2018-05-20 18:25:00 +0000 | |||
94 | +++ PetriEngine/Colored/ColoredPetriNetBuilder.cpp 2018-06-26 07:06:25 +0000 | |||
95 | @@ -1,10 +1,4 @@ | |||
96 | 1 | /* | 1 | /* |
97 | 2 | * To change this license header, choose License Headers in Project Properties. | ||
98 | 3 | * To change this template file, choose Tools | Templates | ||
99 | 4 | * and open the template in the editor. | ||
100 | 5 | */ | ||
101 | 6 | |||
102 | 7 | /* | ||
103 | 8 | * File: ColoredPetriNetBuilder.cpp | 2 | * File: ColoredPetriNetBuilder.cpp |
104 | 9 | * Author: Klostergaard | 3 | * Author: Klostergaard |
105 | 10 | * | 4 | * |
106 | @@ -30,11 +24,11 @@ | |||
107 | 30 | } | 24 | } |
108 | 31 | } | 25 | } |
109 | 32 | 26 | ||
111 | 33 | void ColoredPetriNetBuilder::addPlace(const std::string& name, Colored::ColorType* type, Colored::Multiset tokens, double x, double y) { | 27 | void ColoredPetriNetBuilder::addPlace(const std::string& name, Colored::ColorType* type, Colored::Multiset&& tokens, double x, double y) { |
112 | 34 | if(_placenames.count(name) == 0) | 28 | if(_placenames.count(name) == 0) |
113 | 35 | { | 29 | { |
114 | 36 | uint32_t next = _placenames.size(); | 30 | uint32_t next = _placenames.size(); |
116 | 37 | _places.push_back(Colored::Place {name, type, tokens}); | 31 | _places.emplace_back(Colored::Place {name, type, tokens}); |
117 | 38 | _placenames[name] = next; | 32 | _placenames[name] = next; |
118 | 39 | } | 33 | } |
119 | 40 | } | 34 | } |
120 | @@ -45,11 +39,11 @@ | |||
121 | 45 | } | 39 | } |
122 | 46 | } | 40 | } |
123 | 47 | 41 | ||
125 | 48 | void ColoredPetriNetBuilder::addTransition(const std::string& name, Colored::GuardExpression_ptr guard, double x, double y) { | 42 | void ColoredPetriNetBuilder::addTransition(const std::string& name, const Colored::GuardExpression_ptr& guard, double x, double y) { |
126 | 49 | if(_transitionnames.count(name) == 0) | 43 | if(_transitionnames.count(name) == 0) |
127 | 50 | { | 44 | { |
128 | 51 | uint32_t next = _transitionnames.size(); | 45 | uint32_t next = _transitionnames.size(); |
130 | 52 | _transitions.push_back(Colored::Transition {name, guard}); | 46 | _transitions.emplace_back(Colored::Transition {name, guard}); |
131 | 53 | _transitionnames[name] = next; | 47 | _transitionnames[name] = next; |
132 | 54 | } | 48 | } |
133 | 55 | } | 49 | } |
134 | @@ -60,7 +54,7 @@ | |||
135 | 60 | } | 54 | } |
136 | 61 | } | 55 | } |
137 | 62 | 56 | ||
139 | 63 | void ColoredPetriNetBuilder::addInputArc(const std::string& place, const std::string& transition, Colored::ArcExpression_ptr expr) { | 57 | void ColoredPetriNetBuilder::addInputArc(const std::string& place, const std::string& transition, const Colored::ArcExpression_ptr& expr) { |
140 | 64 | addArc(place, transition, expr, true); | 58 | addArc(place, transition, expr, true); |
141 | 65 | } | 59 | } |
142 | 66 | 60 | ||
143 | @@ -70,11 +64,11 @@ | |||
144 | 70 | } | 64 | } |
145 | 71 | } | 65 | } |
146 | 72 | 66 | ||
148 | 73 | void ColoredPetriNetBuilder::addOutputArc(const std::string& transition, const std::string& place, Colored::ArcExpression_ptr expr) { | 67 | void ColoredPetriNetBuilder::addOutputArc(const std::string& transition, const std::string& place, const Colored::ArcExpression_ptr& expr) { |
149 | 74 | addArc(place, transition, expr, false); | 68 | addArc(place, transition, expr, false); |
150 | 75 | } | 69 | } |
151 | 76 | 70 | ||
153 | 77 | void ColoredPetriNetBuilder::addArc(const std::string& place, const std::string& transition, Colored::ArcExpression_ptr expr, bool input) { | 71 | void ColoredPetriNetBuilder::addArc(const std::string& place, const std::string& transition, const Colored::ArcExpression_ptr& expr, bool input) { |
154 | 78 | if(_transitionnames.count(transition) == 0) | 72 | if(_transitionnames.count(transition) == 0) |
155 | 79 | { | 73 | { |
156 | 80 | std::cout << "Transition '" << transition << "' not found. Adding it." << std::endl; | 74 | std::cout << "Transition '" << transition << "' not found. Adding it." << std::endl; |
157 | @@ -95,10 +89,9 @@ | |||
158 | 95 | arc.place = p; | 89 | arc.place = p; |
159 | 96 | arc.transition = t; | 90 | arc.transition = t; |
160 | 97 | assert(expr != nullptr); | 91 | assert(expr != nullptr); |
162 | 98 | arc.expr = expr; | 92 | arc.expr = std::move(expr); |
163 | 99 | arc.input = input; | 93 | arc.input = input; |
166 | 100 | _transitions[t].arcs.push_back(_arcs.size()); | 94 | _transitions[t].arcs.push_back(std::move(arc)); |
165 | 101 | _arcs.push_back(arc); | ||
167 | 102 | } | 95 | } |
168 | 103 | 96 | ||
169 | 104 | void ColoredPetriNetBuilder::addColorType(const std::string& id, Colored::ColorType* type) { | 97 | void ColoredPetriNetBuilder::addColorType(const std::string& id, Colored::ColorType* type) { |
170 | @@ -121,9 +114,6 @@ | |||
171 | 121 | unfoldTransition(transition); | 114 | unfoldTransition(transition); |
172 | 122 | } | 115 | } |
173 | 123 | 116 | ||
174 | 124 | for (auto& arc : _arcs) { | ||
175 | 125 | unfoldArc(arc); | ||
176 | 126 | } | ||
177 | 127 | _unfolded = true; | 117 | _unfolded = true; |
178 | 128 | auto end = std::chrono::high_resolution_clock::now(); | 118 | auto end = std::chrono::high_resolution_clock::now(); |
179 | 129 | _time = (std::chrono::duration_cast<std::chrono::microseconds>(end - start).count())*0.000001; | 119 | _time = (std::chrono::duration_cast<std::chrono::microseconds>(end - start).count())*0.000001; |
180 | @@ -135,50 +125,42 @@ | |||
181 | 135 | void ColoredPetriNetBuilder::unfoldPlace(Colored::Place& place) { | 125 | void ColoredPetriNetBuilder::unfoldPlace(Colored::Place& place) { |
182 | 136 | for (size_t i = 0; i < place.type->size(); ++i) { | 126 | for (size_t i = 0; i < place.type->size(); ++i) { |
183 | 137 | std::string name = place.name + ";" + std::to_string(i); | 127 | std::string name = place.name + ";" + std::to_string(i); |
185 | 138 | const Colored::Color* color = &(*place.type)[i]; | 128 | const Colored::Color* color = &place.type->operator[](i); |
186 | 139 | _ptBuilder.addPlace(name, place.marking[color], 0.0, 0.0); | 129 | _ptBuilder.addPlace(name, place.marking[color], 0.0, 0.0); |
188 | 140 | _ptplacenames[place.name][color->getId()] = name; | 130 | _ptplacenames[place.name][color->getId()] = std::move(name); |
189 | 141 | ++_nptplaces; | 131 | ++_nptplaces; |
190 | 142 | } | 132 | } |
191 | 143 | } | 133 | } |
192 | 144 | 134 | ||
193 | 145 | void ColoredPetriNetBuilder::unfoldTransition(Colored::Transition& transition) { | 135 | void ColoredPetriNetBuilder::unfoldTransition(Colored::Transition& transition) { |
194 | 146 | BindingGenerator gen(transition, _arcs, _colors); | 136 | BindingGenerator gen(transition, _arcs, _colors); |
195 | 137 | size_t i = 0; | ||
196 | 147 | for (auto& b : gen) { | 138 | for (auto& b : gen) { |
204 | 148 | size_t i = transition.bindings.size(); | 139 | std::string name = transition.name + ";" + std::to_string(i++); |
198 | 149 | std::unordered_map<std::string, const Colored::Color*> binding; | ||
199 | 150 | for (auto& elem : b) { | ||
200 | 151 | binding[elem.var->name] = elem.color; | ||
201 | 152 | } | ||
202 | 153 | transition.bindings.push_back(binding); | ||
203 | 154 | std::string name = transition.name + ";" + std::to_string(i); | ||
205 | 155 | _ptBuilder.addTransition(name, 0.0, 0.0); | 140 | _ptBuilder.addTransition(name, 0.0, 0.0); |
206 | 156 | _pttransitionnames[transition.name].push_back(name); | 141 | _pttransitionnames[transition.name].push_back(name); |
207 | 157 | ++_npttransitions; | 142 | ++_npttransitions; |
208 | 143 | for (auto& arc : transition.arcs) { | ||
209 | 144 | unfoldArc(arc, b, name); | ||
210 | 145 | } | ||
211 | 158 | } | 146 | } |
212 | 159 | } | 147 | } |
213 | 160 | 148 | ||
235 | 161 | void ColoredPetriNetBuilder::unfoldArc(Colored::Arc& arc) { | 149 | void ColoredPetriNetBuilder::unfoldArc(Colored::Arc& arc, Colored::ExpressionContext::BindingMap& binding, std::string& tName) { |
236 | 162 | Colored::Transition& transition = _transitions[arc.transition]; | 150 | Colored::ExpressionContext context {binding, _colors}; |
237 | 163 | for (size_t i = 0; i < transition.bindings.size(); ++i) { | 151 | auto ms = arc.expr->eval(context); |
238 | 164 | Colored::ExpressionContext context {transition.bindings[i], _colors}; | 152 | |
239 | 165 | Colored::Multiset ms = arc.expr->eval(context); | 153 | for (const auto& color : ms) { |
240 | 166 | 154 | if (color.second == 0) { | |
241 | 167 | for (auto color : ms) { | 155 | continue; |
242 | 168 | if (color.second == 0) { | 156 | } |
243 | 169 | continue; | 157 | const std::string& pName = _ptplacenames[_places[arc.place].name][color.first->getId()]; |
244 | 170 | } | 158 | if (arc.input) { |
245 | 171 | 159 | _ptBuilder.addInputArc(pName, tName, false, color.second); | |
246 | 172 | std::string pName = _ptplacenames[_places[arc.place].name][color.first->getId()]; | 160 | } else { |
247 | 173 | std::string tName = _pttransitionnames[transition.name][i]; | 161 | _ptBuilder.addOutputArc(tName, pName, color.second); |
248 | 174 | 162 | } | |
249 | 175 | if (arc.input) { | 163 | ++_nptarcs; |
229 | 176 | _ptBuilder.addInputArc(pName, tName, false, color.second); | ||
230 | 177 | } else { | ||
231 | 178 | _ptBuilder.addOutputArc(tName, pName, color.second); | ||
232 | 179 | } | ||
233 | 180 | ++_nptarcs; | ||
234 | 181 | } | ||
250 | 182 | } | 164 | } |
251 | 183 | } | 165 | } |
252 | 184 | 166 | ||
253 | @@ -191,24 +173,24 @@ | |||
254 | 191 | 173 | ||
255 | 192 | for (auto& transition : _transitions) { | 174 | for (auto& transition : _transitions) { |
256 | 193 | _ptBuilder.addTransition(transition.name, 0.0, 0.0); | 175 | _ptBuilder.addTransition(transition.name, 0.0, 0.0); |
267 | 194 | } | 176 | for (auto& arc : transition.arcs) { |
268 | 195 | 177 | try { | |
269 | 196 | for (auto& arc : _arcs) { | 178 | if (arc.input) { |
270 | 197 | try { | 179 | _ptBuilder.addInputArc(_places[arc.place].name, _transitions[arc.transition].name, false, |
271 | 198 | if (arc.input) { | 180 | arc.expr->weight()); |
272 | 199 | _ptBuilder.addInputArc(_places[arc.place].name, _transitions[arc.transition].name, false, | 181 | } else { |
273 | 200 | arc.expr->weight()); | 182 | _ptBuilder.addOutputArc(_transitions[arc.transition].name, _places[arc.place].name, |
274 | 201 | } else { | 183 | arc.expr->weight()); |
275 | 202 | _ptBuilder.addOutputArc(_transitions[arc.transition].name, _places[arc.place].name, | 184 | } |
276 | 203 | arc.expr->weight()); | 185 | } catch (Colored::WeightException& e) { |
277 | 186 | std::cerr << "Exception on arc: " << arcToString(arc) << std::endl; | ||
278 | 187 | std::cerr << "In expression: " << arc.expr->toString() << std::endl; | ||
279 | 188 | std::cerr << e.what() << std::endl; | ||
280 | 189 | exit(ErrorCode); | ||
281 | 204 | } | 190 | } |
282 | 205 | } catch (Colored::WeightException e) { | ||
283 | 206 | std::cerr << "Exception on arc: " << arcToString(arc) << std::endl; | ||
284 | 207 | std::cerr << "In expression: " << arc.expr->toString() << std::endl; | ||
285 | 208 | std::cerr << e.what() << std::endl; | ||
286 | 209 | exit(ErrorCode); | ||
287 | 210 | } | 191 | } |
288 | 211 | } | 192 | } |
289 | 193 | |||
290 | 212 | _stripped = true; | 194 | _stripped = true; |
291 | 213 | _isColored = false; | 195 | _isColored = false; |
292 | 214 | } | 196 | } |
293 | @@ -240,13 +222,13 @@ | |||
294 | 240 | return *this; | 222 | return *this; |
295 | 241 | } | 223 | } |
296 | 242 | 224 | ||
298 | 243 | std::vector<Colored::Binding> BindingGenerator::Iterator::operator++(int) { | 225 | const Colored::ExpressionContext::BindingMap BindingGenerator::Iterator::operator++(int) { |
299 | 244 | auto prev = _generator->currentBinding(); | 226 | auto prev = _generator->currentBinding(); |
300 | 245 | ++*this; | 227 | ++*this; |
301 | 246 | return prev; | 228 | return prev; |
302 | 247 | } | 229 | } |
303 | 248 | 230 | ||
305 | 249 | std::vector<Colored::Binding>& BindingGenerator::Iterator::operator*() { | 231 | Colored::ExpressionContext::BindingMap& BindingGenerator::Iterator::operator*() { |
306 | 250 | return _generator->currentBinding(); | 232 | return _generator->currentBinding(); |
307 | 251 | } | 233 | } |
308 | 252 | 234 | ||
309 | @@ -260,13 +242,12 @@ | |||
310 | 260 | if (_expr != nullptr) { | 242 | if (_expr != nullptr) { |
311 | 261 | _expr->getVariables(variables); | 243 | _expr->getVariables(variables); |
312 | 262 | } | 244 | } |
315 | 263 | for (auto ai : transition.arcs) { | 245 | for (auto arc : transition.arcs) { |
314 | 264 | auto& arc = arcs[ai]; | ||
316 | 265 | assert(arc.expr != nullptr); | 246 | assert(arc.expr != nullptr); |
317 | 266 | arc.expr->getVariables(variables); | 247 | arc.expr->getVariables(variables); |
318 | 267 | } | 248 | } |
319 | 268 | for (auto var : variables) { | 249 | for (auto var : variables) { |
321 | 269 | _bindings.push_back(Colored::Binding {var, &(*var->colorType)[0]}); | 250 | _bindings[var->name] = &var->colorType->operator[](0); |
322 | 270 | } | 251 | } |
323 | 271 | 252 | ||
324 | 272 | if (!eval()) | 253 | if (!eval()) |
325 | @@ -277,20 +258,16 @@ | |||
326 | 277 | if (_expr == nullptr) | 258 | if (_expr == nullptr) |
327 | 278 | return true; | 259 | return true; |
328 | 279 | 260 | ||
334 | 280 | std::unordered_map<std::string, const Colored::Color*> binding; | 261 | Colored::ExpressionContext context {_bindings, _colorTypes}; |
330 | 281 | for (auto& elem : _bindings) { | ||
331 | 282 | binding[elem.var->name] = elem.color; | ||
332 | 283 | } | ||
333 | 284 | Colored::ExpressionContext context {binding, _colorTypes}; | ||
335 | 285 | return _expr->eval(context); | 262 | return _expr->eval(context); |
336 | 286 | } | 263 | } |
339 | 287 | 264 | ||
340 | 288 | std::vector<Colored::Binding>& BindingGenerator::nextBinding() { | 265 | Colored::ExpressionContext::BindingMap& BindingGenerator::nextBinding() { |
341 | 289 | bool test = false; | 266 | bool test = false; |
342 | 290 | while (!test) { | 267 | while (!test) { |
346 | 291 | for (size_t i = 0; i < _bindings.size(); ++i) { | 268 | for (auto& _binding : _bindings) { |
347 | 292 | _bindings[i].color = &++(*_bindings[i].color); | 269 | _binding.second = &_binding.second->operator++(); |
348 | 293 | if (_bindings[i].color->getId() != 0) { | 270 | if (_binding.second->getId() != 0) { |
349 | 294 | break; | 271 | break; |
350 | 295 | } | 272 | } |
351 | 296 | } | 273 | } |
352 | @@ -303,23 +280,23 @@ | |||
353 | 303 | return _bindings; | 280 | return _bindings; |
354 | 304 | } | 281 | } |
355 | 305 | 282 | ||
357 | 306 | std::vector<Colored::Binding>& BindingGenerator::currentBinding() { | 283 | Colored::ExpressionContext::BindingMap& BindingGenerator::currentBinding() { |
358 | 307 | return _bindings; | 284 | return _bindings; |
359 | 308 | } | 285 | } |
360 | 309 | 286 | ||
361 | 310 | bool BindingGenerator::isInitial() const { | 287 | bool BindingGenerator::isInitial() const { |
362 | 311 | for (auto& b : _bindings) { | 288 | for (auto& b : _bindings) { |
364 | 312 | if (b.color->getId() != 0) return false; | 289 | if (b.second->getId() != 0) return false; |
365 | 313 | } | 290 | } |
366 | 314 | return true; | 291 | return true; |
367 | 315 | } | 292 | } |
368 | 316 | 293 | ||
369 | 317 | BindingGenerator::Iterator BindingGenerator::begin() { | 294 | BindingGenerator::Iterator BindingGenerator::begin() { |
371 | 318 | return Iterator(this); | 295 | return {this}; |
372 | 319 | } | 296 | } |
373 | 320 | 297 | ||
374 | 321 | BindingGenerator::Iterator BindingGenerator::end() { | 298 | BindingGenerator::Iterator BindingGenerator::end() { |
376 | 322 | return Iterator(nullptr); | 299 | return {nullptr}; |
377 | 323 | } | 300 | } |
378 | 324 | } | 301 | } |
379 | 325 | 302 | ||
380 | 326 | 303 | ||
381 | === modified file 'PetriEngine/Colored/ColoredPetriNetBuilder.h' | |||
382 | --- PetriEngine/Colored/ColoredPetriNetBuilder.h 2018-05-20 18:25:00 +0000 | |||
383 | +++ PetriEngine/Colored/ColoredPetriNetBuilder.h 2018-06-26 07:06:25 +0000 | |||
384 | @@ -1,10 +1,4 @@ | |||
385 | 1 | /* | 1 | /* |
386 | 2 | * To change this license header, choose License Headers in Project Properties. | ||
387 | 3 | * To change this template file, choose Tools | Templates | ||
388 | 4 | * and open the template in the editor. | ||
389 | 5 | */ | ||
390 | 6 | |||
391 | 7 | /* | ||
392 | 8 | * File: ColoredPetriNetBuilder.h | 2 | * File: ColoredPetriNetBuilder.h |
393 | 9 | * Author: Klostergaard | 3 | * Author: Klostergaard |
394 | 10 | * | 4 | * |
395 | @@ -39,14 +33,14 @@ | |||
396 | 39 | double y = 0) override ; | 33 | double y = 0) override ; |
397 | 40 | void addPlace(const std::string& name, | 34 | void addPlace(const std::string& name, |
398 | 41 | Colored::ColorType* type, | 35 | Colored::ColorType* type, |
407 | 42 | Colored::Multiset tokens, | 36 | Colored::Multiset&& tokens, |
408 | 43 | double x = 0, | 37 | double x = 0, |
409 | 44 | double y = 0) override; | 38 | double y = 0) override; |
410 | 45 | void addTransition(const std::string& name, | 39 | void addTransition(const std::string& name, |
411 | 46 | double x = 0, | 40 | double x = 0, |
412 | 47 | double y = 0) override; | 41 | double y = 0) override; |
413 | 48 | void addTransition(const std::string& name, | 42 | void addTransition(const std::string& name, |
414 | 49 | Colored::GuardExpression_ptr guard, | 43 | const Colored::GuardExpression_ptr& guard, |
415 | 50 | double x = 0, | 44 | double x = 0, |
416 | 51 | double y = 0) override; | 45 | double y = 0) override; |
417 | 52 | void addInputArc(const std::string& place, | 46 | void addInputArc(const std::string& place, |
418 | @@ -55,13 +49,13 @@ | |||
419 | 55 | int) override; | 49 | int) override; |
420 | 56 | void addInputArc(const std::string& place, | 50 | void addInputArc(const std::string& place, |
421 | 57 | const std::string& transition, | 51 | const std::string& transition, |
423 | 58 | Colored::ArcExpression_ptr expr) override; | 52 | const Colored::ArcExpression_ptr& expr) override; |
424 | 59 | void addOutputArc(const std::string& transition, | 53 | void addOutputArc(const std::string& transition, |
425 | 60 | const std::string& place, | 54 | const std::string& place, |
426 | 61 | int weight = 1) override; | 55 | int weight = 1) override; |
427 | 62 | void addOutputArc(const std::string& transition, | 56 | void addOutputArc(const std::string& transition, |
428 | 63 | const std::string& place, | 57 | const std::string& place, |
430 | 64 | Colored::ArcExpression_ptr expr) override; | 58 | const Colored::ArcExpression_ptr& expr) override; |
431 | 65 | void addColorType(const std::string& id, | 59 | void addColorType(const std::string& id, |
432 | 66 | Colored::ColorType* type) override; | 60 | Colored::ColorType* type) override; |
433 | 67 | 61 | ||
434 | @@ -81,7 +75,11 @@ | |||
435 | 81 | } | 75 | } |
436 | 82 | 76 | ||
437 | 83 | uint32_t getArcCount() const { | 77 | uint32_t getArcCount() const { |
439 | 84 | return _arcs.size(); | 78 | uint32_t sum = 0; |
440 | 79 | for (auto& t : _transitions) { | ||
441 | 80 | sum += t.arcs.size(); | ||
442 | 81 | } | ||
443 | 82 | return sum; | ||
444 | 85 | } | 83 | } |
445 | 86 | 84 | ||
446 | 87 | uint32_t getUnfoldedPlaceCount() const { | 85 | uint32_t getUnfoldedPlaceCount() const { |
447 | @@ -134,12 +132,12 @@ | |||
448 | 134 | 132 | ||
449 | 135 | void addArc(const std::string& place, | 133 | void addArc(const std::string& place, |
450 | 136 | const std::string& transition, | 134 | const std::string& transition, |
452 | 137 | Colored::ArcExpression_ptr expr, | 135 | const Colored::ArcExpression_ptr& expr, |
453 | 138 | bool input); | 136 | bool input); |
454 | 139 | 137 | ||
455 | 140 | void unfoldPlace(Colored::Place& place); | 138 | void unfoldPlace(Colored::Place& place); |
456 | 141 | void unfoldTransition(Colored::Transition& transition); | 139 | void unfoldTransition(Colored::Transition& transition); |
458 | 142 | void unfoldArc(Colored::Arc& arc); | 140 | void unfoldArc(Colored::Arc& arc, Colored::ExpressionContext::BindingMap& binding, std::string& name); |
459 | 143 | }; | 141 | }; |
460 | 144 | 142 | ||
461 | 145 | class BindingGenerator { | 143 | class BindingGenerator { |
462 | @@ -154,12 +152,12 @@ | |||
463 | 154 | bool operator==(Iterator& other); | 152 | bool operator==(Iterator& other); |
464 | 155 | bool operator!=(Iterator& other); | 153 | bool operator!=(Iterator& other); |
465 | 156 | Iterator& operator++(); | 154 | Iterator& operator++(); |
468 | 157 | std::vector<Colored::Binding> operator++(int); | 155 | const Colored::ExpressionContext::BindingMap operator++(int); |
469 | 158 | std::vector<Colored::Binding>& operator*(); | 156 | Colored::ExpressionContext::BindingMap& operator*(); |
470 | 159 | }; | 157 | }; |
471 | 160 | private: | 158 | private: |
472 | 161 | Colored::GuardExpression_ptr _expr; | 159 | Colored::GuardExpression_ptr _expr; |
474 | 162 | std::vector<Colored::Binding> _bindings; | 160 | Colored::ExpressionContext::BindingMap _bindings; |
475 | 163 | ColoredPetriNetBuilder::ColorTypeMap& _colorTypes; | 161 | ColoredPetriNetBuilder::ColorTypeMap& _colorTypes; |
476 | 164 | 162 | ||
477 | 165 | bool eval(); | 163 | bool eval(); |
478 | @@ -168,9 +166,9 @@ | |||
479 | 168 | BindingGenerator(Colored::Transition& transition, | 166 | BindingGenerator(Colored::Transition& transition, |
480 | 169 | const std::vector<Colored::Arc>& arcs, | 167 | const std::vector<Colored::Arc>& arcs, |
481 | 170 | ColoredPetriNetBuilder::ColorTypeMap& colorTypes); | 168 | ColoredPetriNetBuilder::ColorTypeMap& colorTypes); |
485 | 171 | 169 | ||
486 | 172 | std::vector<Colored::Binding>& nextBinding(); | 170 | Colored::ExpressionContext::BindingMap& nextBinding(); |
487 | 173 | std::vector<Colored::Binding>& currentBinding(); | 171 | Colored::ExpressionContext::BindingMap& currentBinding(); |
488 | 174 | bool isInitial() const; | 172 | bool isInitial() const; |
489 | 175 | Iterator begin(); | 173 | Iterator begin(); |
490 | 176 | Iterator end(); | 174 | Iterator end(); |
491 | 177 | 175 | ||
492 | === modified file 'PetriEngine/Colored/Expressions.h' | |||
493 | --- PetriEngine/Colored/Expressions.h 2018-05-27 12:00:38 +0000 | |||
494 | +++ PetriEngine/Colored/Expressions.h 2018-06-26 07:06:25 +0000 | |||
495 | @@ -32,7 +32,9 @@ | |||
496 | 32 | 32 | ||
497 | 33 | namespace Colored { | 33 | namespace Colored { |
498 | 34 | struct ExpressionContext { | 34 | struct ExpressionContext { |
500 | 35 | std::unordered_map<std::string, const Color*>& binding; | 35 | typedef std::unordered_map<std::string, const Color*> BindingMap; |
501 | 36 | |||
502 | 37 | BindingMap& binding; | ||
503 | 36 | std::unordered_map<std::string, ColorType*>& colorTypes; | 38 | std::unordered_map<std::string, ColorType*>& colorTypes; |
504 | 37 | 39 | ||
505 | 38 | const Color* findColor(const std::string& color) const { | 40 | const Color* findColor(const std::string& color) const { |
506 | @@ -191,8 +193,8 @@ | |||
507 | 191 | return _color->toString() + "++"; | 193 | return _color->toString() + "++"; |
508 | 192 | } | 194 | } |
509 | 193 | 195 | ||
512 | 194 | SuccessorExpression(ColorExpression_ptr color) | 196 | SuccessorExpression(ColorExpression_ptr&& color) |
513 | 195 | : _color(color) {} | 197 | : _color(std::move(color)) {} |
514 | 196 | }; | 198 | }; |
515 | 197 | 199 | ||
516 | 198 | class PredecessorExpression : public ColorExpression { | 200 | class PredecessorExpression : public ColorExpression { |
517 | @@ -212,8 +214,8 @@ | |||
518 | 212 | return _color->toString() + "--"; | 214 | return _color->toString() + "--"; |
519 | 213 | } | 215 | } |
520 | 214 | 216 | ||
523 | 215 | PredecessorExpression(ColorExpression_ptr color) | 217 | PredecessorExpression(ColorExpression_ptr&& color) |
524 | 216 | : _color(color) {} | 218 | : _color(std::move(color)) {} |
525 | 217 | }; | 219 | }; |
526 | 218 | 220 | ||
527 | 219 | class TupleExpression : public ColorExpression { | 221 | class TupleExpression : public ColorExpression { |
528 | @@ -250,8 +252,8 @@ | |||
529 | 250 | return res; | 252 | return res; |
530 | 251 | } | 253 | } |
531 | 252 | 254 | ||
534 | 253 | TupleExpression(std::vector<ColorExpression_ptr> colors) | 255 | TupleExpression(std::vector<ColorExpression_ptr>&& colors) |
535 | 254 | : _colors(colors) {} | 256 | : _colors(std::move(colors)) {} |
536 | 255 | }; | 257 | }; |
537 | 256 | 258 | ||
538 | 257 | class GuardExpression : public Expression { | 259 | class GuardExpression : public Expression { |
539 | @@ -279,8 +281,8 @@ | |||
540 | 279 | _right->getVariables(variables); | 281 | _right->getVariables(variables); |
541 | 280 | } | 282 | } |
542 | 281 | 283 | ||
545 | 282 | LessThanExpression(ColorExpression_ptr left, ColorExpression_ptr right) | 284 | LessThanExpression(ColorExpression_ptr&& left, ColorExpression_ptr&& right) |
546 | 283 | : _left(left), _right(right) {} | 285 | : _left(std::move(left)), _right(std::move(right)) {} |
547 | 284 | }; | 286 | }; |
548 | 285 | 287 | ||
549 | 286 | class GreaterThanExpression : public GuardExpression { | 288 | class GreaterThanExpression : public GuardExpression { |
550 | @@ -298,8 +300,8 @@ | |||
551 | 298 | _right->getVariables(variables); | 300 | _right->getVariables(variables); |
552 | 299 | } | 301 | } |
553 | 300 | 302 | ||
556 | 301 | GreaterThanExpression(ColorExpression_ptr left, ColorExpression_ptr right) | 303 | GreaterThanExpression(ColorExpression_ptr&& left, ColorExpression_ptr&& right) |
557 | 302 | : _left(left), _right(right) {} | 304 | : _left(std::move(left)), _right(std::move(right)) {} |
558 | 303 | }; | 305 | }; |
559 | 304 | 306 | ||
560 | 305 | class LessThanEqExpression : public GuardExpression { | 307 | class LessThanEqExpression : public GuardExpression { |
561 | @@ -317,8 +319,8 @@ | |||
562 | 317 | _right->getVariables(variables); | 319 | _right->getVariables(variables); |
563 | 318 | } | 320 | } |
564 | 319 | 321 | ||
567 | 320 | LessThanEqExpression(ColorExpression_ptr left, ColorExpression_ptr right) | 322 | LessThanEqExpression(ColorExpression_ptr&& left, ColorExpression_ptr&& right) |
568 | 321 | : _left(left), _right(right) {} | 323 | : _left(std::move(left)), _right(std::move(right)) {} |
569 | 322 | }; | 324 | }; |
570 | 323 | 325 | ||
571 | 324 | class GreaterThanEqExpression : public GuardExpression { | 326 | class GreaterThanEqExpression : public GuardExpression { |
572 | @@ -336,8 +338,8 @@ | |||
573 | 336 | _right->getVariables(variables); | 338 | _right->getVariables(variables); |
574 | 337 | } | 339 | } |
575 | 338 | 340 | ||
578 | 339 | GreaterThanEqExpression(ColorExpression_ptr left, ColorExpression_ptr right) | 341 | GreaterThanEqExpression(ColorExpression_ptr&& left, ColorExpression_ptr&& right) |
579 | 340 | : _left(left), _right(right) {} | 342 | : _left(std::move(left)), _right(std::move(right)) {} |
580 | 341 | }; | 343 | }; |
581 | 342 | 344 | ||
582 | 343 | class EqualityExpression : public GuardExpression { | 345 | class EqualityExpression : public GuardExpression { |
583 | @@ -355,8 +357,8 @@ | |||
584 | 355 | _right->getVariables(variables); | 357 | _right->getVariables(variables); |
585 | 356 | } | 358 | } |
586 | 357 | 359 | ||
589 | 358 | EqualityExpression(ColorExpression_ptr left, ColorExpression_ptr right) | 360 | EqualityExpression(ColorExpression_ptr&& left, ColorExpression_ptr&& right) |
590 | 359 | : _left(left), _right(right) {} | 361 | : _left(std::move(left)), _right(std::move(right)) {} |
591 | 360 | }; | 362 | }; |
592 | 361 | 363 | ||
593 | 362 | class InequalityExpression : public GuardExpression { | 364 | class InequalityExpression : public GuardExpression { |
594 | @@ -374,8 +376,8 @@ | |||
595 | 374 | _right->getVariables(variables); | 376 | _right->getVariables(variables); |
596 | 375 | } | 377 | } |
597 | 376 | 378 | ||
600 | 377 | InequalityExpression(ColorExpression_ptr left, ColorExpression_ptr right) | 379 | InequalityExpression(ColorExpression_ptr&& left, ColorExpression_ptr&& right) |
601 | 378 | : _left(left), _right(right) {} | 380 | : _left(std::move(left)), _right(std::move(right)) {} |
602 | 379 | }; | 381 | }; |
603 | 380 | 382 | ||
604 | 381 | class NotExpression : public GuardExpression { | 383 | class NotExpression : public GuardExpression { |
605 | @@ -391,7 +393,7 @@ | |||
606 | 391 | _expr->getVariables(variables); | 393 | _expr->getVariables(variables); |
607 | 392 | } | 394 | } |
608 | 393 | 395 | ||
610 | 394 | NotExpression(GuardExpression_ptr expr) : _expr(expr) {} | 396 | NotExpression(GuardExpression_ptr&& expr) : _expr(std::move(expr)) {} |
611 | 395 | }; | 397 | }; |
612 | 396 | 398 | ||
613 | 397 | class AndExpression : public GuardExpression { | 399 | class AndExpression : public GuardExpression { |
614 | @@ -409,7 +411,7 @@ | |||
615 | 409 | _right->getVariables(variables); | 411 | _right->getVariables(variables); |
616 | 410 | } | 412 | } |
617 | 411 | 413 | ||
619 | 412 | AndExpression(GuardExpression_ptr left, GuardExpression_ptr right) | 414 | AndExpression(GuardExpression_ptr&& left, GuardExpression_ptr&& right) |
620 | 413 | : _left(left), _right(right) {} | 415 | : _left(left), _right(right) {} |
621 | 414 | }; | 416 | }; |
622 | 415 | 417 | ||
623 | @@ -428,8 +430,8 @@ | |||
624 | 428 | _right->getVariables(variables); | 430 | _right->getVariables(variables); |
625 | 429 | } | 431 | } |
626 | 430 | 432 | ||
629 | 431 | OrExpression(GuardExpression_ptr left, GuardExpression_ptr right) | 433 | OrExpression(GuardExpression_ptr&& left, GuardExpression_ptr&& right) |
630 | 432 | : _left(left), _right(right) {} | 434 | : _left(std::move(left)), _right(std::move(right)) {} |
631 | 433 | }; | 435 | }; |
632 | 434 | 436 | ||
633 | 435 | class ArcExpression : public Expression { | 437 | class ArcExpression : public Expression { |
634 | @@ -539,10 +541,10 @@ | |||
635 | 539 | return res; | 541 | return res; |
636 | 540 | } | 542 | } |
637 | 541 | 543 | ||
642 | 542 | NumberOfExpression(std::vector<ColorExpression_ptr> color, uint32_t number = 1) | 544 | NumberOfExpression(std::vector<ColorExpression_ptr>&& color, uint32_t number = 1) |
643 | 543 | : _number(number), _color(color), _all(nullptr) {} | 545 | : _number(number), _color(std::move(color)), _all(nullptr) {} |
644 | 544 | NumberOfExpression(AllExpression_ptr all, uint32_t number = 1) | 546 | NumberOfExpression(AllExpression_ptr&& all, uint32_t number = 1) |
645 | 545 | : _number(number), _color(), _all(all) {} | 547 | : _number(number), _color(), _all(std::move(all)) {} |
646 | 546 | }; | 548 | }; |
647 | 547 | 549 | ||
648 | 548 | typedef std::shared_ptr<NumberOfExpression> NumberOfExpression_ptr; | 550 | typedef std::shared_ptr<NumberOfExpression> NumberOfExpression_ptr; |
649 | @@ -582,8 +584,8 @@ | |||
650 | 582 | return res; | 584 | return res; |
651 | 583 | } | 585 | } |
652 | 584 | 586 | ||
655 | 585 | AddExpression(std::vector<ArcExpression_ptr> constituents) | 587 | AddExpression(std::vector<ArcExpression_ptr>&& constituents) |
656 | 586 | : _constituents(constituents) {} | 588 | : _constituents(std::move(constituents)) {} |
657 | 587 | }; | 589 | }; |
658 | 588 | 590 | ||
659 | 589 | class SubtractExpression : public ArcExpression { | 591 | class SubtractExpression : public ArcExpression { |
660 | @@ -619,8 +621,8 @@ | |||
661 | 619 | return _left->toString() + " - " + _right->toString(); | 621 | return _left->toString() + " - " + _right->toString(); |
662 | 620 | } | 622 | } |
663 | 621 | 623 | ||
666 | 622 | SubtractExpression(ArcExpression_ptr left, ArcExpression_ptr right) | 624 | SubtractExpression(ArcExpression_ptr&& left, ArcExpression_ptr&& right) |
667 | 623 | : _left(left), _right(right) {} | 625 | : _left(std::move(left)), _right(std::move(right)) {} |
668 | 624 | }; | 626 | }; |
669 | 625 | 627 | ||
670 | 626 | class ScalarProductExpression : public ArcExpression { | 628 | class ScalarProductExpression : public ArcExpression { |
671 | @@ -645,8 +647,8 @@ | |||
672 | 645 | return std::to_string(_scalar) + " * " + _expr->toString(); | 647 | return std::to_string(_scalar) + " * " + _expr->toString(); |
673 | 646 | } | 648 | } |
674 | 647 | 649 | ||
677 | 648 | ScalarProductExpression(ArcExpression_ptr expr, uint32_t scalar) | 650 | ScalarProductExpression(ArcExpression_ptr&& expr, uint32_t scalar) |
678 | 649 | : _scalar(scalar), _expr(expr) {} | 651 | : _scalar(std::move(scalar)), _expr(expr) {} |
679 | 650 | }; | 652 | }; |
680 | 651 | } | 653 | } |
681 | 652 | } | 654 | } |
682 | 653 | 655 | ||
683 | === modified file 'PetriParse/PNMLParser.cpp' | |||
684 | --- PetriParse/PNMLParser.cpp 2018-05-20 18:25:00 +0000 | |||
685 | +++ PetriParse/PNMLParser.cpp 2018-06-26 07:06:25 +0000 | |||
686 | @@ -206,7 +206,7 @@ | |||
687 | 206 | for (auto it = element->first_node(); it; it = it->next_sibling()) { | 206 | for (auto it = element->first_node(); it; it = it->next_sibling()) { |
688 | 207 | constituents.push_back(parseArcExpression(it)); | 207 | constituents.push_back(parseArcExpression(it)); |
689 | 208 | } | 208 | } |
691 | 209 | return std::make_shared<PetriEngine::Colored::AddExpression>(constituents); | 209 | return std::make_shared<PetriEngine::Colored::AddExpression>(std::move(constituents)); |
692 | 210 | } else if (strcmp(element->name(), "subtract") == 0) { | 210 | } else if (strcmp(element->name(), "subtract") == 0) { |
693 | 211 | auto left = element->first_node(); | 211 | auto left = element->first_node(); |
694 | 212 | auto right = left->next_sibling(); | 212 | auto right = left->next_sibling(); |
695 | @@ -290,7 +290,7 @@ | |||
696 | 290 | for (auto it = element->first_node(); it; it = it->next_sibling()) { | 290 | for (auto it = element->first_node(); it; it = it->next_sibling()) { |
697 | 291 | colors.push_back(parseColorExpression(it)); | 291 | colors.push_back(parseColorExpression(it)); |
698 | 292 | } | 292 | } |
700 | 293 | return std::make_shared<PetriEngine::Colored::TupleExpression>(colors); | 293 | return std::make_shared<PetriEngine::Colored::TupleExpression>(std::move(colors)); |
701 | 294 | } else if (strcmp(element->name(), "subterm") == 0 || strcmp(element->name(), "structure") == 0) { | 294 | } else if (strcmp(element->name(), "subterm") == 0 || strcmp(element->name(), "structure") == 0) { |
702 | 295 | return parseColorExpression(element->first_node()); | 295 | return parseColorExpression(element->first_node()); |
703 | 296 | } | 296 | } |
704 | @@ -336,13 +336,13 @@ | |||
705 | 336 | } | 336 | } |
706 | 337 | auto allExpr = parseAllExpression(first); | 337 | auto allExpr = parseAllExpression(first); |
707 | 338 | if (allExpr) { | 338 | if (allExpr) { |
709 | 339 | return std::make_shared<PetriEngine::Colored::NumberOfExpression>(allExpr, number); | 339 | return std::make_shared<PetriEngine::Colored::NumberOfExpression>(std::move(allExpr), number); |
710 | 340 | } else { | 340 | } else { |
711 | 341 | std::vector<PetriEngine::Colored::ColorExpression_ptr> colors; | 341 | std::vector<PetriEngine::Colored::ColorExpression_ptr> colors; |
712 | 342 | for (auto it = first; it; it = it->next_sibling()) { | 342 | for (auto it = first; it; it = it->next_sibling()) { |
713 | 343 | colors.push_back(parseColorExpression(it)); | 343 | colors.push_back(parseColorExpression(it)); |
714 | 344 | } | 344 | } |
716 | 345 | return std::make_shared<PetriEngine::Colored::NumberOfExpression>(colors, number); | 345 | return std::make_shared<PetriEngine::Colored::NumberOfExpression>(std::move(colors), number); |
717 | 346 | } | 346 | } |
718 | 347 | } | 347 | } |
719 | 348 | 348 | ||
720 | @@ -436,7 +436,7 @@ | |||
721 | 436 | } | 436 | } |
722 | 437 | else | 437 | else |
723 | 438 | { | 438 | { |
725 | 439 | builder->addPlace(id, type, hlinitialMarking, x, y); | 439 | builder->addPlace(id, type, std::move(hlinitialMarking), x, y); |
726 | 440 | } | 440 | } |
727 | 441 | } | 441 | } |
728 | 442 | //Map id to name | 442 | //Map id to name |
Version 219 is consistent and well performing.