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

Proposed by Andreas Klostergaard on 2018-06-24
Status: Merged
Approved by: Jiri Srba on 2018-06-26
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 2018-06-24 Approve on 2018-06-26
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.
Jiri Srba (srba) wrote :

Version 219 is consistent and well performing.

Jiri Srba (srba) wrote :

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

review: Approve
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 on 2018-06-26

fixed warnings

Peter Gjøl Jensen (peter-gjoel) wrote :

Warnings should be fixed now.

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

Subscribers

People subscribed via source and target branches