Merge lp:~verifypn-cpn/verifypn/unfold-improve into lp:verifypn

Proposed by Andreas Klostergaard
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
Reviewer Review Type Date Requested Status
Jiri Srba Approve
Review via email: mp+348445@code.launchpad.net

Description of the change

Improved the unfolding of colored Petri nets

To post a comment you must log in.
Revision history for this message
Jiri Srba (srba) wrote :

Version 219 is consistent and well performing.

Revision history for this message
Jiri Srba (srba) wrote :

Version 220 is also consistent, no noticable improvement (data in the spreadsheet).

review: Approve
Revision history for this message
Jiri Srba (srba) wrote :

There are some warnings to be fixed:

PetriEngine/Colored/ColoredPetriNetBuilder.cpp:31:34: warning: moving a
      temporary object prevents copy elision [-Wpessimizing-move]
            _places.emplace_back(std::move(Colored::Place {name, type, t...
                                 ^
PetriEngine/Colored/ColoredPetriNetBuilder.cpp:31:34: note: remove std::move
      call here
  ..._places.emplace_back(std::move(Colored::Place {name, type, tokens}));
                          ^~~~~~~~~~ ~
PetriEngine/Colored/ColoredPetriNetBuilder.cpp:46:39: warning: moving a
      temporary object prevents copy elision [-Wpessimizing-move]
            _transitions.emplace_back(std::move(Colored::Transition {nam...
                                      ^
PetriEngine/Colored/ColoredPetriNetBuilder.cpp:46:39: note: remove std::move
      call here
  ..._transitions.emplace_back(std::move(Colored::Transition {name, guard}));
                               ^~~~~~~~~~ ~

review: Needs Fixing
221. By Peter Gjøl Jensen

fixed warnings

Revision history for this message
Peter Gjøl Jensen (peter-gjoel) wrote :

Warnings should be fixed now.

Revision history for this message
Jiri Srba (srba) wrote :

Warning fixed.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'CMakeLists.txt'
--- CMakeLists.txt 2018-04-19 22:14:38 +0000
+++ CMakeLists.txt 2018-06-26 07:06:25 +0000
@@ -1,15 +1,19 @@
1cmake_minimum_required(VERSION 2.8.4)1cmake_minimum_required(VERSION 2.8.4)
2project(verifypn)2project(verifypn)
33
4if (UNIX)4if (UNIX AND NOT APPLE)
5 if (CMAKE_SIZEOF_VOID_P EQUAL 8) # is system 64-bit?5 if (CMAKE_SIZEOF_VOID_P EQUAL 8) # is system 64-bit?
6 set(ARCH_TYPE "linux64")6 set(ARCH_TYPE "linux64")
7 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -flto -march=x86-64 -std=c++14 -m64 -I.")
8 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -flto=4 -march=x86-64 -std=c++14 -m64 -static -static-libgcc -static-libstdc++")
7 else()9 else()
8 set(ARCH_TYPE "linux32")10 set(ARCH_TYPE "linux32")
9 endif ()11 endif ()
10elseif(APPLE)12elseif(APPLE)
11 if (CMAKE_SIZEOF_VOID_P EQUAL 8) # is system 64-bit?13 if (CMAKE_SIZEOF_VOID_P EQUAL 8) # is system 64-bit?
12 set(ARCH_TYPE "osx64")14 set(ARCH_TYPE "osx64")
15 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=10.7 -std=c++14 -m64 -I. -stdlib=libc++")
16 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -dynamic -mmacosx-version-min=10.7 -std=c++14 -m64 -stdlib=libc++ -lc++")
13 else()17 else()
14 set(ARCH_TYPE "osx32")18 set(ARCH_TYPE "osx32")
15 endif ()19 endif ()
@@ -21,11 +25,9 @@
21 endif()25 endif()
22endif ()26endif ()
2327
24set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -flto -march=x86-64 -std=c++14 -m64 -I.")
25set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wall -pedantic-errors -O2 -DNDEBUG")28set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wall -pedantic-errors -O2 -DNDEBUG")
26set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g")29set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g")
2730
28set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -flto=4 -march=x86-64 -std=c++14 -m64 -static -static-libgcc -static-libstdc++")
29set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -O2 -DNDEBUG")31set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -O2 -DNDEBUG")
30set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -g")32set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -g")
3133
3234
=== modified file 'PetriEngine/AbstractPetriNetBuilder.h'
--- PetriEngine/AbstractPetriNetBuilder.h 2018-05-12 15:14:12 +0000
+++ PetriEngine/AbstractPetriNetBuilder.h 2018-06-26 07:06:25 +0000
@@ -42,7 +42,7 @@
42 /** Add a new colored place with a unique name */42 /** Add a new colored place with a unique name */
43 virtual void addPlace(const std::string& name,43 virtual void addPlace(const std::string& name,
44 Colored::ColorType* type,44 Colored::ColorType* type,
45 Colored::Multiset tokens,45 Colored::Multiset&& tokens,
46 double x = 0,46 double x = 0,
47 double y = 0)47 double y = 0)
48 {48 {
@@ -55,7 +55,7 @@
55 double y = 0) = 0;55 double y = 0) = 0;
56 /** Add a new colored transition with a unique name */56 /** Add a new colored transition with a unique name */
57 virtual void addTransition(const std::string& name,57 virtual void addTransition(const std::string& name,
58 Colored::GuardExpression_ptr guard,58 const Colored::GuardExpression_ptr& guard,
59 double x = 0,59 double x = 0,
60 double y = 0)60 double y = 0)
61 {61 {
@@ -70,7 +70,7 @@
70 /** Add colored input arc with given arc expression */70 /** Add colored input arc with given arc expression */
71 virtual void addInputArc(const std::string& place,71 virtual void addInputArc(const std::string& place,
72 const std::string& transition,72 const std::string& transition,
73 Colored::ArcExpression_ptr expr)73 const Colored::ArcExpression_ptr& expr)
74 {74 {
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;
76 exit(ErrorCode);76 exit(ErrorCode);
@@ -82,7 +82,7 @@
82 /** Add output arc with given arc expression */82 /** Add output arc with given arc expression */
83 virtual void addOutputArc(const std::string& transition,83 virtual void addOutputArc(const std::string& transition,
84 const std::string& place,84 const std::string& place,
85 Colored::ArcExpression_ptr expr)85 const Colored::ArcExpression_ptr& expr)
86 {86 {
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;
88 exit(ErrorCode);88 exit(ErrorCode);
8989
=== modified file 'PetriEngine/Colored/ColoredNetStructures.h'
--- PetriEngine/Colored/ColoredNetStructures.h 2018-03-13 22:08:31 +0000
+++ PetriEngine/Colored/ColoredNetStructures.h 2018-06-26 07:06:25 +0000
@@ -33,8 +33,7 @@
33 struct Transition {33 struct Transition {
34 std::string name;34 std::string name;
35 GuardExpression_ptr guard;35 GuardExpression_ptr guard;
36 std::vector<std::unordered_map<std::string,const Color*>> bindings;36 std::vector<Arc> arcs;
37 std::vector<size_t> arcs;
38 };37 };
39 38
40 struct Place {39 struct Place {
4140
=== modified file 'PetriEngine/Colored/ColoredPetriNetBuilder.cpp'
--- PetriEngine/Colored/ColoredPetriNetBuilder.cpp 2018-05-20 18:25:00 +0000
+++ PetriEngine/Colored/ColoredPetriNetBuilder.cpp 2018-06-26 07:06:25 +0000
@@ -1,10 +1,4 @@
1/*1/*
2 * To change this license header, choose License Headers in Project Properties.
3 * To change this template file, choose Tools | Templates
4 * and open the template in the editor.
5 */
6
7/*
8 * File: ColoredPetriNetBuilder.cpp2 * File: ColoredPetriNetBuilder.cpp
9 * Author: Klostergaard3 * Author: Klostergaard
10 * 4 *
@@ -30,11 +24,11 @@
30 }24 }
31 }25 }
3226
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) {
34 if(_placenames.count(name) == 0)28 if(_placenames.count(name) == 0)
35 {29 {
36 uint32_t next = _placenames.size();30 uint32_t next = _placenames.size();
37 _places.push_back(Colored::Place {name, type, tokens});31 _places.emplace_back(Colored::Place {name, type, tokens});
38 _placenames[name] = next;32 _placenames[name] = next;
39 }33 }
40 }34 }
@@ -45,11 +39,11 @@
45 }39 }
46 }40 }
4741
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) {
49 if(_transitionnames.count(name) == 0)43 if(_transitionnames.count(name) == 0)
50 {44 {
51 uint32_t next = _transitionnames.size();45 uint32_t next = _transitionnames.size();
52 _transitions.push_back(Colored::Transition {name, guard});46 _transitions.emplace_back(Colored::Transition {name, guard});
53 _transitionnames[name] = next;47 _transitionnames[name] = next;
54 }48 }
55 }49 }
@@ -60,7 +54,7 @@
60 }54 }
61 }55 }
6256
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) {
64 addArc(place, transition, expr, true);58 addArc(place, transition, expr, true);
65 }59 }
6660
@@ -70,11 +64,11 @@
70 }64 }
71 }65 }
7266
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) {
74 addArc(place, transition, expr, false);68 addArc(place, transition, expr, false);
75 }69 }
7670
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) {
78 if(_transitionnames.count(transition) == 0)72 if(_transitionnames.count(transition) == 0)
79 {73 {
80 std::cout << "Transition '" << transition << "' not found. Adding it." << std::endl;74 std::cout << "Transition '" << transition << "' not found. Adding it." << std::endl;
@@ -95,10 +89,9 @@
95 arc.place = p;89 arc.place = p;
96 arc.transition = t;90 arc.transition = t;
97 assert(expr != nullptr);91 assert(expr != nullptr);
98 arc.expr = expr;92 arc.expr = std::move(expr);
99 arc.input = input;93 arc.input = input;
100 _transitions[t].arcs.push_back(_arcs.size());94 _transitions[t].arcs.push_back(std::move(arc));
101 _arcs.push_back(arc);
102 }95 }
10396
104 void ColoredPetriNetBuilder::addColorType(const std::string& id, Colored::ColorType* type) {97 void ColoredPetriNetBuilder::addColorType(const std::string& id, Colored::ColorType* type) {
@@ -121,9 +114,6 @@
121 unfoldTransition(transition);114 unfoldTransition(transition);
122 }115 }
123116
124 for (auto& arc : _arcs) {
125 unfoldArc(arc);
126 }
127 _unfolded = true;117 _unfolded = true;
128 auto end = std::chrono::high_resolution_clock::now();118 auto end = std::chrono::high_resolution_clock::now();
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;
@@ -135,50 +125,42 @@
135 void ColoredPetriNetBuilder::unfoldPlace(Colored::Place& place) {125 void ColoredPetriNetBuilder::unfoldPlace(Colored::Place& place) {
136 for (size_t i = 0; i < place.type->size(); ++i) {126 for (size_t i = 0; i < place.type->size(); ++i) {
137 std::string name = place.name + ";" + std::to_string(i);127 std::string name = place.name + ";" + std::to_string(i);
138 const Colored::Color* color = &(*place.type)[i];128 const Colored::Color* color = &place.type->operator[](i);
139 _ptBuilder.addPlace(name, place.marking[color], 0.0, 0.0);129 _ptBuilder.addPlace(name, place.marking[color], 0.0, 0.0);
140 _ptplacenames[place.name][color->getId()] = name;130 _ptplacenames[place.name][color->getId()] = std::move(name);
141 ++_nptplaces;131 ++_nptplaces;
142 }132 }
143 }133 }
144134
145 void ColoredPetriNetBuilder::unfoldTransition(Colored::Transition& transition) {135 void ColoredPetriNetBuilder::unfoldTransition(Colored::Transition& transition) {
146 BindingGenerator gen(transition, _arcs, _colors);136 BindingGenerator gen(transition, _arcs, _colors);
137 size_t i = 0;
147 for (auto& b : gen) {138 for (auto& b : gen) {
148 size_t i = transition.bindings.size();139 std::string name = transition.name + ";" + std::to_string(i++);
149 std::unordered_map<std::string, const Colored::Color*> binding;
150 for (auto& elem : b) {
151 binding[elem.var->name] = elem.color;
152 }
153 transition.bindings.push_back(binding);
154 std::string name = transition.name + ";" + std::to_string(i);
155 _ptBuilder.addTransition(name, 0.0, 0.0);140 _ptBuilder.addTransition(name, 0.0, 0.0);
156 _pttransitionnames[transition.name].push_back(name);141 _pttransitionnames[transition.name].push_back(name);
157 ++_npttransitions;142 ++_npttransitions;
143 for (auto& arc : transition.arcs) {
144 unfoldArc(arc, b, name);
145 }
158 }146 }
159 }147 }
160148
161 void ColoredPetriNetBuilder::unfoldArc(Colored::Arc& arc) {149 void ColoredPetriNetBuilder::unfoldArc(Colored::Arc& arc, Colored::ExpressionContext::BindingMap& binding, std::string& tName) {
162 Colored::Transition& transition = _transitions[arc.transition];150 Colored::ExpressionContext context {binding, _colors};
163 for (size_t i = 0; i < transition.bindings.size(); ++i) {151 auto ms = arc.expr->eval(context);
164 Colored::ExpressionContext context {transition.bindings[i], _colors};152
165 Colored::Multiset ms = arc.expr->eval(context);153 for (const auto& color : ms) {
166154 if (color.second == 0) {
167 for (auto color : ms) {155 continue;
168 if (color.second == 0) {156 }
169 continue;157 const std::string& pName = _ptplacenames[_places[arc.place].name][color.first->getId()];
170 }158 if (arc.input) {
171159 _ptBuilder.addInputArc(pName, tName, false, color.second);
172 std::string pName = _ptplacenames[_places[arc.place].name][color.first->getId()];160 } else {
173 std::string tName = _pttransitionnames[transition.name][i];161 _ptBuilder.addOutputArc(tName, pName, color.second);
174162 }
175 if (arc.input) {163 ++_nptarcs;
176 _ptBuilder.addInputArc(pName, tName, false, color.second);
177 } else {
178 _ptBuilder.addOutputArc(tName, pName, color.second);
179 }
180 ++_nptarcs;
181 }
182 }164 }
183 }165 }
184166
@@ -191,24 +173,24 @@
191173
192 for (auto& transition : _transitions) {174 for (auto& transition : _transitions) {
193 _ptBuilder.addTransition(transition.name, 0.0, 0.0);175 _ptBuilder.addTransition(transition.name, 0.0, 0.0);
194 }176 for (auto& arc : transition.arcs) {
195177 try {
196 for (auto& arc : _arcs) {178 if (arc.input) {
197 try {179 _ptBuilder.addInputArc(_places[arc.place].name, _transitions[arc.transition].name, false,
198 if (arc.input) {180 arc.expr->weight());
199 _ptBuilder.addInputArc(_places[arc.place].name, _transitions[arc.transition].name, false,181 } else {
200 arc.expr->weight());182 _ptBuilder.addOutputArc(_transitions[arc.transition].name, _places[arc.place].name,
201 } else {183 arc.expr->weight());
202 _ptBuilder.addOutputArc(_transitions[arc.transition].name, _places[arc.place].name,184 }
203 arc.expr->weight());185 } catch (Colored::WeightException& e) {
186 std::cerr << "Exception on arc: " << arcToString(arc) << std::endl;
187 std::cerr << "In expression: " << arc.expr->toString() << std::endl;
188 std::cerr << e.what() << std::endl;
189 exit(ErrorCode);
204 }190 }
205 } catch (Colored::WeightException e) {
206 std::cerr << "Exception on arc: " << arcToString(arc) << std::endl;
207 std::cerr << "In expression: " << arc.expr->toString() << std::endl;
208 std::cerr << e.what() << std::endl;
209 exit(ErrorCode);
210 }191 }
211 }192 }
193
212 _stripped = true;194 _stripped = true;
213 _isColored = false;195 _isColored = false;
214 }196 }
@@ -240,13 +222,13 @@
240 return *this;222 return *this;
241 }223 }
242224
243 std::vector<Colored::Binding> BindingGenerator::Iterator::operator++(int) {225 const Colored::ExpressionContext::BindingMap BindingGenerator::Iterator::operator++(int) {
244 auto prev = _generator->currentBinding();226 auto prev = _generator->currentBinding();
245 ++*this;227 ++*this;
246 return prev;228 return prev;
247 }229 }
248230
249 std::vector<Colored::Binding>& BindingGenerator::Iterator::operator*() {231 Colored::ExpressionContext::BindingMap& BindingGenerator::Iterator::operator*() {
250 return _generator->currentBinding();232 return _generator->currentBinding();
251 }233 }
252234
@@ -260,13 +242,12 @@
260 if (_expr != nullptr) {242 if (_expr != nullptr) {
261 _expr->getVariables(variables);243 _expr->getVariables(variables);
262 }244 }
263 for (auto ai : transition.arcs) {245 for (auto arc : transition.arcs) {
264 auto& arc = arcs[ai];
265 assert(arc.expr != nullptr);246 assert(arc.expr != nullptr);
266 arc.expr->getVariables(variables);247 arc.expr->getVariables(variables);
267 }248 }
268 for (auto var : variables) {249 for (auto var : variables) {
269 _bindings.push_back(Colored::Binding {var, &(*var->colorType)[0]});250 _bindings[var->name] = &var->colorType->operator[](0);
270 }251 }
271 252
272 if (!eval())253 if (!eval())
@@ -277,20 +258,16 @@
277 if (_expr == nullptr)258 if (_expr == nullptr)
278 return true;259 return true;
279260
280 std::unordered_map<std::string, const Colored::Color*> binding;261 Colored::ExpressionContext context {_bindings, _colorTypes};
281 for (auto& elem : _bindings) {
282 binding[elem.var->name] = elem.color;
283 }
284 Colored::ExpressionContext context {binding, _colorTypes};
285 return _expr->eval(context);262 return _expr->eval(context);
286 }263 }
287 264
288 std::vector<Colored::Binding>& BindingGenerator::nextBinding() {265 Colored::ExpressionContext::BindingMap& BindingGenerator::nextBinding() {
289 bool test = false;266 bool test = false;
290 while (!test) {267 while (!test) {
291 for (size_t i = 0; i < _bindings.size(); ++i) {268 for (auto& _binding : _bindings) {
292 _bindings[i].color = &++(*_bindings[i].color);269 _binding.second = &_binding.second->operator++();
293 if (_bindings[i].color->getId() != 0) {270 if (_binding.second->getId() != 0) {
294 break;271 break;
295 }272 }
296 }273 }
@@ -303,23 +280,23 @@
303 return _bindings;280 return _bindings;
304 }281 }
305282
306 std::vector<Colored::Binding>& BindingGenerator::currentBinding() {283 Colored::ExpressionContext::BindingMap& BindingGenerator::currentBinding() {
307 return _bindings;284 return _bindings;
308 }285 }
309286
310 bool BindingGenerator::isInitial() const {287 bool BindingGenerator::isInitial() const {
311 for (auto& b : _bindings) {288 for (auto& b : _bindings) {
312 if (b.color->getId() != 0) return false;289 if (b.second->getId() != 0) return false;
313 }290 }
314 return true;291 return true;
315 }292 }
316293
317 BindingGenerator::Iterator BindingGenerator::begin() {294 BindingGenerator::Iterator BindingGenerator::begin() {
318 return Iterator(this);295 return {this};
319 }296 }
320297
321 BindingGenerator::Iterator BindingGenerator::end() {298 BindingGenerator::Iterator BindingGenerator::end() {
322 return Iterator(nullptr);299 return {nullptr};
323 }300 }
324}301}
325302
326303
=== modified file 'PetriEngine/Colored/ColoredPetriNetBuilder.h'
--- PetriEngine/Colored/ColoredPetriNetBuilder.h 2018-05-20 18:25:00 +0000
+++ PetriEngine/Colored/ColoredPetriNetBuilder.h 2018-06-26 07:06:25 +0000
@@ -1,10 +1,4 @@
1/*1/*
2 * To change this license header, choose License Headers in Project Properties.
3 * To change this template file, choose Tools | Templates
4 * and open the template in the editor.
5 */
6
7/*
8 * File: ColoredPetriNetBuilder.h2 * File: ColoredPetriNetBuilder.h
9 * Author: Klostergaard3 * Author: Klostergaard
10 *4 *
@@ -39,14 +33,14 @@
39 double y = 0) override ;33 double y = 0) override ;
40 void addPlace(const std::string& name,34 void addPlace(const std::string& name,
41 Colored::ColorType* type,35 Colored::ColorType* type,
42 Colored::Multiset tokens,36 Colored::Multiset&& tokens,
43 double x = 0,37 double x = 0,
44 double y = 0) override;38 double y = 0) override;
45 void addTransition(const std::string& name,39 void addTransition(const std::string& name,
46 double x = 0,40 double x = 0,
47 double y = 0) override;41 double y = 0) override;
48 void addTransition(const std::string& name,42 void addTransition(const std::string& name,
49 Colored::GuardExpression_ptr guard,43 const Colored::GuardExpression_ptr& guard,
50 double x = 0,44 double x = 0,
51 double y = 0) override;45 double y = 0) override;
52 void addInputArc(const std::string& place,46 void addInputArc(const std::string& place,
@@ -55,13 +49,13 @@
55 int) override;49 int) override;
56 void addInputArc(const std::string& place,50 void addInputArc(const std::string& place,
57 const std::string& transition,51 const std::string& transition,
58 Colored::ArcExpression_ptr expr) override;52 const Colored::ArcExpression_ptr& expr) override;
59 void addOutputArc(const std::string& transition,53 void addOutputArc(const std::string& transition,
60 const std::string& place,54 const std::string& place,
61 int weight = 1) override;55 int weight = 1) override;
62 void addOutputArc(const std::string& transition,56 void addOutputArc(const std::string& transition,
63 const std::string& place,57 const std::string& place,
64 Colored::ArcExpression_ptr expr) override;58 const Colored::ArcExpression_ptr& expr) override;
65 void addColorType(const std::string& id,59 void addColorType(const std::string& id,
66 Colored::ColorType* type) override;60 Colored::ColorType* type) override;
6761
@@ -81,7 +75,11 @@
81 }75 }
8276
83 uint32_t getArcCount() const {77 uint32_t getArcCount() const {
84 return _arcs.size();78 uint32_t sum = 0;
79 for (auto& t : _transitions) {
80 sum += t.arcs.size();
81 }
82 return sum;
85 }83 }
8684
87 uint32_t getUnfoldedPlaceCount() const {85 uint32_t getUnfoldedPlaceCount() const {
@@ -134,12 +132,12 @@
134 132
135 void addArc(const std::string& place,133 void addArc(const std::string& place,
136 const std::string& transition,134 const std::string& transition,
137 Colored::ArcExpression_ptr expr,135 const Colored::ArcExpression_ptr& expr,
138 bool input);136 bool input);
139 137
140 void unfoldPlace(Colored::Place& place);138 void unfoldPlace(Colored::Place& place);
141 void unfoldTransition(Colored::Transition& transition);139 void unfoldTransition(Colored::Transition& transition);
142 void unfoldArc(Colored::Arc& arc);140 void unfoldArc(Colored::Arc& arc, Colored::ExpressionContext::BindingMap& binding, std::string& name);
143 };141 };
144 142
145 class BindingGenerator {143 class BindingGenerator {
@@ -154,12 +152,12 @@
154 bool operator==(Iterator& other);152 bool operator==(Iterator& other);
155 bool operator!=(Iterator& other);153 bool operator!=(Iterator& other);
156 Iterator& operator++();154 Iterator& operator++();
157 std::vector<Colored::Binding> operator++(int);155 const Colored::ExpressionContext::BindingMap operator++(int);
158 std::vector<Colored::Binding>& operator*();156 Colored::ExpressionContext::BindingMap& operator*();
159 };157 };
160 private:158 private:
161 Colored::GuardExpression_ptr _expr;159 Colored::GuardExpression_ptr _expr;
162 std::vector<Colored::Binding> _bindings;160 Colored::ExpressionContext::BindingMap _bindings;
163 ColoredPetriNetBuilder::ColorTypeMap& _colorTypes;161 ColoredPetriNetBuilder::ColorTypeMap& _colorTypes;
164 162
165 bool eval();163 bool eval();
@@ -168,9 +166,9 @@
168 BindingGenerator(Colored::Transition& transition,166 BindingGenerator(Colored::Transition& transition,
169 const std::vector<Colored::Arc>& arcs,167 const std::vector<Colored::Arc>& arcs,
170 ColoredPetriNetBuilder::ColorTypeMap& colorTypes);168 ColoredPetriNetBuilder::ColorTypeMap& colorTypes);
171 169
172 std::vector<Colored::Binding>& nextBinding();170 Colored::ExpressionContext::BindingMap& nextBinding();
173 std::vector<Colored::Binding>& currentBinding();171 Colored::ExpressionContext::BindingMap& currentBinding();
174 bool isInitial() const;172 bool isInitial() const;
175 Iterator begin();173 Iterator begin();
176 Iterator end();174 Iterator end();
177175
=== modified file 'PetriEngine/Colored/Expressions.h'
--- PetriEngine/Colored/Expressions.h 2018-05-27 12:00:38 +0000
+++ PetriEngine/Colored/Expressions.h 2018-06-26 07:06:25 +0000
@@ -32,7 +32,9 @@
32 32
33 namespace Colored {33 namespace Colored {
34 struct ExpressionContext {34 struct ExpressionContext {
35 std::unordered_map<std::string, const Color*>& binding;35 typedef std::unordered_map<std::string, const Color*> BindingMap;
36
37 BindingMap& binding;
36 std::unordered_map<std::string, ColorType*>& colorTypes;38 std::unordered_map<std::string, ColorType*>& colorTypes;
37 39
38 const Color* findColor(const std::string& color) const {40 const Color* findColor(const std::string& color) const {
@@ -191,8 +193,8 @@
191 return _color->toString() + "++";193 return _color->toString() + "++";
192 }194 }
193195
194 SuccessorExpression(ColorExpression_ptr color)196 SuccessorExpression(ColorExpression_ptr&& color)
195 : _color(color) {}197 : _color(std::move(color)) {}
196 };198 };
197 199
198 class PredecessorExpression : public ColorExpression {200 class PredecessorExpression : public ColorExpression {
@@ -212,8 +214,8 @@
212 return _color->toString() + "--";214 return _color->toString() + "--";
213 }215 }
214216
215 PredecessorExpression(ColorExpression_ptr color)217 PredecessorExpression(ColorExpression_ptr&& color)
216 : _color(color) {}218 : _color(std::move(color)) {}
217 };219 };
218 220
219 class TupleExpression : public ColorExpression {221 class TupleExpression : public ColorExpression {
@@ -250,8 +252,8 @@
250 return res;252 return res;
251 }253 }
252254
253 TupleExpression(std::vector<ColorExpression_ptr> colors)255 TupleExpression(std::vector<ColorExpression_ptr>&& colors)
254 : _colors(colors) {}256 : _colors(std::move(colors)) {}
255 };257 };
256 258
257 class GuardExpression : public Expression {259 class GuardExpression : public Expression {
@@ -279,8 +281,8 @@
279 _right->getVariables(variables);281 _right->getVariables(variables);
280 }282 }
281 283
282 LessThanExpression(ColorExpression_ptr left, ColorExpression_ptr right)284 LessThanExpression(ColorExpression_ptr&& left, ColorExpression_ptr&& right)
283 : _left(left), _right(right) {}285 : _left(std::move(left)), _right(std::move(right)) {}
284 };286 };
285 287
286 class GreaterThanExpression : public GuardExpression {288 class GreaterThanExpression : public GuardExpression {
@@ -298,8 +300,8 @@
298 _right->getVariables(variables);300 _right->getVariables(variables);
299 }301 }
300 302
301 GreaterThanExpression(ColorExpression_ptr left, ColorExpression_ptr right)303 GreaterThanExpression(ColorExpression_ptr&& left, ColorExpression_ptr&& right)
302 : _left(left), _right(right) {}304 : _left(std::move(left)), _right(std::move(right)) {}
303 };305 };
304 306
305 class LessThanEqExpression : public GuardExpression {307 class LessThanEqExpression : public GuardExpression {
@@ -317,8 +319,8 @@
317 _right->getVariables(variables);319 _right->getVariables(variables);
318 }320 }
319 321
320 LessThanEqExpression(ColorExpression_ptr left, ColorExpression_ptr right)322 LessThanEqExpression(ColorExpression_ptr&& left, ColorExpression_ptr&& right)
321 : _left(left), _right(right) {}323 : _left(std::move(left)), _right(std::move(right)) {}
322 };324 };
323 325
324 class GreaterThanEqExpression : public GuardExpression {326 class GreaterThanEqExpression : public GuardExpression {
@@ -336,8 +338,8 @@
336 _right->getVariables(variables);338 _right->getVariables(variables);
337 }339 }
338 340
339 GreaterThanEqExpression(ColorExpression_ptr left, ColorExpression_ptr right)341 GreaterThanEqExpression(ColorExpression_ptr&& left, ColorExpression_ptr&& right)
340 : _left(left), _right(right) {}342 : _left(std::move(left)), _right(std::move(right)) {}
341 };343 };
342 344
343 class EqualityExpression : public GuardExpression {345 class EqualityExpression : public GuardExpression {
@@ -355,8 +357,8 @@
355 _right->getVariables(variables);357 _right->getVariables(variables);
356 }358 }
357 359
358 EqualityExpression(ColorExpression_ptr left, ColorExpression_ptr right)360 EqualityExpression(ColorExpression_ptr&& left, ColorExpression_ptr&& right)
359 : _left(left), _right(right) {}361 : _left(std::move(left)), _right(std::move(right)) {}
360 };362 };
361 363
362 class InequalityExpression : public GuardExpression {364 class InequalityExpression : public GuardExpression {
@@ -374,8 +376,8 @@
374 _right->getVariables(variables);376 _right->getVariables(variables);
375 }377 }
376 378
377 InequalityExpression(ColorExpression_ptr left, ColorExpression_ptr right)379 InequalityExpression(ColorExpression_ptr&& left, ColorExpression_ptr&& right)
378 : _left(left), _right(right) {}380 : _left(std::move(left)), _right(std::move(right)) {}
379 };381 };
380 382
381 class NotExpression : public GuardExpression {383 class NotExpression : public GuardExpression {
@@ -391,7 +393,7 @@
391 _expr->getVariables(variables);393 _expr->getVariables(variables);
392 }394 }
393 395
394 NotExpression(GuardExpression_ptr expr) : _expr(expr) {}396 NotExpression(GuardExpression_ptr&& expr) : _expr(std::move(expr)) {}
395 };397 };
396 398
397 class AndExpression : public GuardExpression {399 class AndExpression : public GuardExpression {
@@ -409,7 +411,7 @@
409 _right->getVariables(variables);411 _right->getVariables(variables);
410 }412 }
411 413
412 AndExpression(GuardExpression_ptr left, GuardExpression_ptr right)414 AndExpression(GuardExpression_ptr&& left, GuardExpression_ptr&& right)
413 : _left(left), _right(right) {}415 : _left(left), _right(right) {}
414 };416 };
415 417
@@ -428,8 +430,8 @@
428 _right->getVariables(variables);430 _right->getVariables(variables);
429 }431 }
430 432
431 OrExpression(GuardExpression_ptr left, GuardExpression_ptr right)433 OrExpression(GuardExpression_ptr&& left, GuardExpression_ptr&& right)
432 : _left(left), _right(right) {}434 : _left(std::move(left)), _right(std::move(right)) {}
433 };435 };
434 436
435 class ArcExpression : public Expression {437 class ArcExpression : public Expression {
@@ -539,10 +541,10 @@
539 return res;541 return res;
540 }542 }
541543
542 NumberOfExpression(std::vector<ColorExpression_ptr> color, uint32_t number = 1)544 NumberOfExpression(std::vector<ColorExpression_ptr>&& color, uint32_t number = 1)
543 : _number(number), _color(color), _all(nullptr) {}545 : _number(number), _color(std::move(color)), _all(nullptr) {}
544 NumberOfExpression(AllExpression_ptr all, uint32_t number = 1)546 NumberOfExpression(AllExpression_ptr&& all, uint32_t number = 1)
545 : _number(number), _color(), _all(all) {}547 : _number(number), _color(), _all(std::move(all)) {}
546 };548 };
547549
548 typedef std::shared_ptr<NumberOfExpression> NumberOfExpression_ptr;550 typedef std::shared_ptr<NumberOfExpression> NumberOfExpression_ptr;
@@ -582,8 +584,8 @@
582 return res;584 return res;
583 }585 }
584586
585 AddExpression(std::vector<ArcExpression_ptr> constituents)587 AddExpression(std::vector<ArcExpression_ptr>&& constituents)
586 : _constituents(constituents) {}588 : _constituents(std::move(constituents)) {}
587 };589 };
588 590
589 class SubtractExpression : public ArcExpression {591 class SubtractExpression : public ArcExpression {
@@ -619,8 +621,8 @@
619 return _left->toString() + " - " + _right->toString();621 return _left->toString() + " - " + _right->toString();
620 }622 }
621623
622 SubtractExpression(ArcExpression_ptr left, ArcExpression_ptr right)624 SubtractExpression(ArcExpression_ptr&& left, ArcExpression_ptr&& right)
623 : _left(left), _right(right) {}625 : _left(std::move(left)), _right(std::move(right)) {}
624 };626 };
625 627
626 class ScalarProductExpression : public ArcExpression {628 class ScalarProductExpression : public ArcExpression {
@@ -645,8 +647,8 @@
645 return std::to_string(_scalar) + " * " + _expr->toString();647 return std::to_string(_scalar) + " * " + _expr->toString();
646 }648 }
647649
648 ScalarProductExpression(ArcExpression_ptr expr, uint32_t scalar)650 ScalarProductExpression(ArcExpression_ptr&& expr, uint32_t scalar)
649 : _scalar(scalar), _expr(expr) {}651 : _scalar(std::move(scalar)), _expr(expr) {}
650 };652 };
651 }653 }
652}654}
653655
=== modified file 'PetriParse/PNMLParser.cpp'
--- PetriParse/PNMLParser.cpp 2018-05-20 18:25:00 +0000
+++ PetriParse/PNMLParser.cpp 2018-06-26 07:06:25 +0000
@@ -206,7 +206,7 @@
206 for (auto it = element->first_node(); it; it = it->next_sibling()) {206 for (auto it = element->first_node(); it; it = it->next_sibling()) {
207 constituents.push_back(parseArcExpression(it));207 constituents.push_back(parseArcExpression(it));
208 }208 }
209 return std::make_shared<PetriEngine::Colored::AddExpression>(constituents);209 return std::make_shared<PetriEngine::Colored::AddExpression>(std::move(constituents));
210 } else if (strcmp(element->name(), "subtract") == 0) {210 } else if (strcmp(element->name(), "subtract") == 0) {
211 auto left = element->first_node();211 auto left = element->first_node();
212 auto right = left->next_sibling();212 auto right = left->next_sibling();
@@ -290,7 +290,7 @@
290 for (auto it = element->first_node(); it; it = it->next_sibling()) {290 for (auto it = element->first_node(); it; it = it->next_sibling()) {
291 colors.push_back(parseColorExpression(it));291 colors.push_back(parseColorExpression(it));
292 }292 }
293 return std::make_shared<PetriEngine::Colored::TupleExpression>(colors);293 return std::make_shared<PetriEngine::Colored::TupleExpression>(std::move(colors));
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) {
295 return parseColorExpression(element->first_node());295 return parseColorExpression(element->first_node());
296 }296 }
@@ -336,13 +336,13 @@
336 }336 }
337 auto allExpr = parseAllExpression(first);337 auto allExpr = parseAllExpression(first);
338 if (allExpr) {338 if (allExpr) {
339 return std::make_shared<PetriEngine::Colored::NumberOfExpression>(allExpr, number);339 return std::make_shared<PetriEngine::Colored::NumberOfExpression>(std::move(allExpr), number);
340 } else {340 } else {
341 std::vector<PetriEngine::Colored::ColorExpression_ptr> colors;341 std::vector<PetriEngine::Colored::ColorExpression_ptr> colors;
342 for (auto it = first; it; it = it->next_sibling()) {342 for (auto it = first; it; it = it->next_sibling()) {
343 colors.push_back(parseColorExpression(it));343 colors.push_back(parseColorExpression(it));
344 }344 }
345 return std::make_shared<PetriEngine::Colored::NumberOfExpression>(colors, number);345 return std::make_shared<PetriEngine::Colored::NumberOfExpression>(std::move(colors), number);
346 }346 }
347}347}
348348
@@ -436,7 +436,7 @@
436 }436 }
437 else437 else
438 {438 {
439 builder->addPlace(id, type, hlinitialMarking, x, y);439 builder->addPlace(id, type, std::move(hlinitialMarking), x, y);
440 }440 }
441 }441 }
442 //Map id to name442 //Map id to name

Subscribers

People subscribed via source and target branches