Merge lp:~verifypn-wf/verifypn/petergame into lp:~verifypn-wf/verifypn/png

Proposed by Bogi
Status: Needs review
Proposed branch: lp:~verifypn-wf/verifypn/petergame
Merge into: lp:~verifypn-wf/verifypn/png
Diff against target: 539 lines (+140/-23)
15 files modified
include/PetriEngine/AbstractPetriNetBuilder.h (+6/-1)
include/PetriEngine/Colored/ColoredNetStructures.h (+1/-0)
include/PetriEngine/Colored/ColoredPetriNetBuilder.h (+3/-0)
include/PetriEngine/NetStructures.h (+1/-0)
include/PetriEngine/PetriNet.h (+11/-0)
include/PetriEngine/PetriNetBuilder.h (+2/-0)
include/PetriEngine/SuccessorGenerator.h (+3/-2)
include/PetriEngine/options.h (+2/-0)
include/PetriParse/PNMLParser.h (+1/-0)
src/PetriEngine/Colored/ColoredPetriNetBuilder.cpp (+17/-9)
src/PetriEngine/PetriNet.cpp (+7/-0)
src/PetriEngine/PetriNetBuilder.cpp (+17/-4)
src/PetriEngine/SuccessorGenerator.cpp (+6/-4)
src/PetriParse/PNMLParser.cpp (+9/-2)
src/VerifyPN.cpp (+54/-1)
To merge this branch: bzr merge lp:~verifypn-wf/verifypn/petergame
Reviewer Review Type Date Requested Status
Bogi Approve
Review via email: mp+393023@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Bogi (boginw) :
review: Approve

Unmerged revisions

228. By Bogi

Added changes from Peter

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'include/PetriEngine/AbstractPetriNetBuilder.h'
2--- include/PetriEngine/AbstractPetriNetBuilder.h 2020-03-02 21:03:24 +0000
3+++ include/PetriEngine/AbstractPetriNetBuilder.h 2020-10-29 08:34:49 +0000
4@@ -50,11 +50,14 @@
5 exit(ErrorCode);
6 }
7 /** Add a new transition with a unique name */
8- virtual void addTransition(const std::string& name,
9+ virtual void addTransition(
10+ const std::string& name,
11+ const uint32_t player,
12 double x = 0,
13 double y = 0) = 0;
14 /** Add a new colored transition with a unique name */
15 virtual void addTransition(const std::string& name,
16+ const uint32_t player,
17 const Colored::GuardExpression_ptr& guard,
18 double x = 0,
19 double y = 0)
20@@ -102,6 +105,8 @@
21 virtual bool isColored() const {
22 return _isColored;
23 }
24+
25+ virtual bool isGame() const = 0;
26
27 virtual void sort() = 0;
28
29
30=== modified file 'include/PetriEngine/Colored/ColoredNetStructures.h'
31--- include/PetriEngine/Colored/ColoredNetStructures.h 2020-03-02 21:03:24 +0000
32+++ include/PetriEngine/Colored/ColoredNetStructures.h 2020-10-29 08:34:49 +0000
33@@ -33,6 +33,7 @@
34 struct Transition {
35 std::string name;
36 GuardExpression_ptr guard;
37+ uint32_t player;
38 std::vector<Arc> arcs;
39 };
40
41
42=== modified file 'include/PetriEngine/Colored/ColoredPetriNetBuilder.h'
43--- include/PetriEngine/Colored/ColoredPetriNetBuilder.h 2020-03-02 21:03:24 +0000
44+++ include/PetriEngine/Colored/ColoredPetriNetBuilder.h 2020-10-29 08:34:49 +0000
45@@ -37,9 +37,11 @@
46 double x = 0,
47 double y = 0) override;
48 void addTransition(const std::string& name,
49+ const uint32_t player,
50 double x = 0,
51 double y = 0) override;
52 void addTransition(const std::string& name,
53+ const uint32_t player,
54 const Colored::GuardExpression_ptr& guard,
55 double x = 0,
56 double y = 0) override;
57@@ -59,6 +61,7 @@
58 void addColorType(const std::string& id,
59 Colored::ColorType* type) override;
60
61+ bool isGame() const override;
62
63 void sort() override;
64
65
66=== modified file 'include/PetriEngine/NetStructures.h'
67--- include/PetriEngine/NetStructures.h 2020-03-02 21:03:24 +0000
68+++ include/PetriEngine/NetStructures.h 2020-10-29 08:34:49 +0000
69@@ -42,6 +42,7 @@
70 std::vector<Arc> post;
71 bool skip = false;
72 bool inhib = false;
73+ uint32_t player = 0;
74
75 void addPreArc(const Arc& arc)
76 {
77
78=== modified file 'include/PetriEngine/PetriNet.h'
79--- include/PetriEngine/PetriNet.h 2020-04-22 07:57:20 +0000
80+++ include/PetriEngine/PetriNet.h 2020-10-29 08:34:49 +0000
81@@ -59,6 +59,8 @@
82 class PetriNet {
83 PetriNet(uint32_t transitions, uint32_t invariants, uint32_t places);
84 public:
85+ typedef uint8_t player_t;
86+
87 ~PetriNet();
88
89 uint32_t initial(size_t id) const;
90@@ -68,6 +70,8 @@
91 bool fireable(const MarkVal* marking, int transitionIndex);
92 std::pair<const Invariant*, const Invariant*> preset(uint32_t id) const;
93 std::pair<const Invariant*, const Invariant*> postset(uint32_t id) const;
94+ bool ownedBy(uint32_t t, player_t p) const;
95+ player_t owner(uint32_t t) const { return _players[t]; }
96 uint32_t numberOfTransitions() const {
97 return _ntransitions;
98 }
99@@ -103,6 +107,11 @@
100 void sort();
101
102 void toXML(std::ostream& out);
103+
104+ static constexpr player_t NONE = 0;
105+ static constexpr player_t CTRL = 1;
106+ static constexpr player_t ENV = 2;
107+ static constexpr player_t ANY = CTRL | ENV;
108
109 const MarkVal* initial() const {
110 return _initialMarking;
111@@ -116,6 +125,8 @@
112 */
113 uint32_t _ninvariants, _ntransitions, _nplaces;
114
115+ // transitions to players. To avoid overhead during normal verification.
116+ std::vector<uint8_t> _players; // bool for now (ctrl==1, unctrl=2)
117 std::vector<TransPtr> _transitions;
118 std::vector<Invariant> _invariants;
119 std::vector<uint32_t> _placeToPtrs;
120
121=== modified file 'include/PetriEngine/PetriNetBuilder.h'
122--- include/PetriEngine/PetriNetBuilder.h 2020-03-02 21:03:24 +0000
123+++ include/PetriEngine/PetriNetBuilder.h 2020-10-29 08:34:49 +0000
124@@ -40,6 +40,7 @@
125 PetriNetBuilder(const PetriNetBuilder& other);
126 void addPlace(const std::string& name, int tokens, double x, double y) override;
127 void addTransition(const std::string& name,
128+ const uint32_t player,
129 double x,
130 double y) override;
131 void addInputArc(const std::string& place,
132@@ -49,6 +50,7 @@
133 void addOutputArc(const std::string& transition, const std::string& place, int weight) override;
134
135 virtual void sort() override;
136+ virtual bool isGame() const;
137 /** Make the resulting petri net, you take ownership */
138 PetriNet* makePetriNet(bool reorder = true);
139 /** Make the resulting initial marking, you take ownership */
140
141=== modified file 'include/PetriEngine/SuccessorGenerator.h'
142--- include/PetriEngine/SuccessorGenerator.h 2020-03-30 16:21:22 +0000
143+++ include/PetriEngine/SuccessorGenerator.h 2020-10-29 08:34:49 +0000
144@@ -21,11 +21,11 @@
145 namespace PetriEngine {
146 class SuccessorGenerator {
147 public:
148- SuccessorGenerator(const PetriNet& net);
149+ SuccessorGenerator(const PetriNet& net, bool is_game = false);
150 SuccessorGenerator(const PetriNet& net, std::vector<std::shared_ptr<PQL::Condition> >& queries);
151 virtual ~SuccessorGenerator();
152 void prepare(const Structures::State* state);
153- bool next(Structures::State& write);
154+ bool next(Structures::State& write, PetriNet::player_t player = PetriNet::ANY);
155 uint32_t fired()
156 {
157 return _suc_tcounter -1;
158@@ -65,6 +65,7 @@
159 const Structures::State* _parent;
160 uint32_t _suc_pcounter;
161 uint32_t _suc_tcounter;
162+ bool _is_game = false;
163
164 friend class ReducingSuccessorGenerator;
165 };
166
167=== modified file 'include/PetriEngine/options.h'
168--- include/PetriEngine/options.h 2020-04-04 14:48:55 +0000
169+++ include/PetriEngine/options.h 2020-10-29 08:34:49 +0000
170@@ -45,6 +45,8 @@
171 bool isCPN = false;
172 uint32_t seed_offset = 0;
173
174+ // for game
175+ bool isGame = false;
176 void print() {
177 if (!printstatistics) {
178 return;
179
180=== modified file 'include/PetriParse/PNMLParser.h'
181--- include/PetriParse/PNMLParser.h 2020-03-02 21:03:24 +0000
182+++ include/PetriParse/PNMLParser.h 2020-10-29 08:34:49 +0000
183@@ -47,6 +47,7 @@
184 std::string id;
185 double x, y;
186 PetriEngine::Colored::GuardExpression_ptr expr;
187+ size_t player;
188 };
189 typedef std::vector<Transition> TransitionList;
190 typedef TransitionList::iterator TransitionIter;
191
192=== modified file 'src/PetriEngine/Colored/ColoredPetriNetBuilder.cpp'
193--- src/PetriEngine/Colored/ColoredPetriNetBuilder.cpp 2020-03-02 21:03:24 +0000
194+++ src/PetriEngine/Colored/ColoredPetriNetBuilder.cpp 2020-10-29 08:34:49 +0000
195@@ -33,19 +33,19 @@
196 }
197 }
198
199- void ColoredPetriNetBuilder::addTransition(const std::string& name, double x, double y) {
200+ void ColoredPetriNetBuilder::addTransition(const std::string& name, const uint32_t player, double x, double y) {
201 if (!_isColored) {
202- _ptBuilder.addTransition(name, x, y);
203+ _ptBuilder.addTransition(name, player, x, y);
204 }
205 }
206
207- void ColoredPetriNetBuilder::addTransition(const std::string& name, const Colored::GuardExpression_ptr& guard, double x, double y) {
208+ void ColoredPetriNetBuilder::addTransition(const std::string& name, const uint32_t player, const Colored::GuardExpression_ptr& guard, double x, double y) {
209 if(_transitionnames.count(name) == 0)
210 {
211 uint32_t next = _transitionnames.size();
212- _transitions.emplace_back(Colored::Transition {name, guard});
213+ _transitions.emplace_back(Colored::Transition {name, guard, player});
214 _transitionnames[name] = next;
215- }
216+ } else if (player != -1) _transitions[_transitionnames[name]].player = player;
217 }
218
219 void ColoredPetriNetBuilder::addInputArc(const std::string& place, const std::string& transition, bool inhibitor, int weight) {
220@@ -72,7 +72,7 @@
221 if(_transitionnames.count(transition) == 0)
222 {
223 std::cout << "Transition '" << transition << "' not found. Adding it." << std::endl;
224- addTransition(transition,0.0,0.0);
225+ addTransition(transition,-1,0.0,0.0);
226 }
227 if(_placenames.count(place) == 0)
228 {
229@@ -97,7 +97,15 @@
230 void ColoredPetriNetBuilder::addColorType(const std::string& id, Colored::ColorType* type) {
231 _colors[id] = type;
232 }
233-
234+ bool ColoredPetriNetBuilder::isGame() const {
235+ for(size_t i = 0; i < _transitions.size(); ++i)
236+ {
237+ if(_transitions[i].player != 0)
238+ return true;
239+ }
240+ return _ptBuilder.isGame();
241+ }
242+
243 void ColoredPetriNetBuilder::sort() {
244
245 }
246@@ -137,7 +145,7 @@
247 size_t i = 0;
248 for (auto& b : gen) {
249 std::string name = transition.name + ";" + std::to_string(i++);
250- _ptBuilder.addTransition(name, 0.0, 0.0);
251+ _ptBuilder.addTransition(name, transition.player, 0.0, 0.0);
252 _pttransitionnames[transition.name].push_back(name);
253 ++_npttransitions;
254 for (auto& arc : transition.arcs) {
255@@ -172,7 +180,7 @@
256 }
257
258 for (auto& transition : _transitions) {
259- _ptBuilder.addTransition(transition.name, 0.0, 0.0);
260+ _ptBuilder.addTransition(transition.name, transition.player, 0.0, 0.0);
261 for (auto& arc : transition.arcs) {
262 try {
263 if (arc.input) {
264
265=== modified file 'src/PetriEngine/PetriNet.cpp'
266--- src/PetriEngine/PetriNet.cpp 2020-03-13 13:35:25 +0000
267+++ src/PetriEngine/PetriNet.cpp 2020-10-29 08:34:49 +0000
268@@ -33,6 +33,7 @@
269
270 PetriNet::PetriNet(uint32_t trans, uint32_t invariants, uint32_t places)
271 : _ninvariants(invariants), _ntransitions(trans), _nplaces(places),
272+ _players(_ntransitions, 1),
273 _transitions(_ntransitions+1),
274 _invariants(_ninvariants),
275 _placeToPtrs(_nplaces+1) {
276@@ -141,6 +142,12 @@
277 uint32_t last = _transitions[id+1].inputs;
278 return std::make_pair(&_invariants[first], &_invariants[last]);
279 }
280+
281+ bool PetriNet::ownedBy(uint32_t id, player_t p) const {
282+ if(p == ANY) return true;
283+ return (p & _players[id]) != 0;
284+ }
285+
286
287 bool PetriNet::fireable(const MarkVal *marking, int transitionIndex)
288 {
289
290=== modified file 'src/PetriEngine/PetriNetBuilder.cpp'
291--- src/PetriEngine/PetriNetBuilder.cpp 2020-03-02 21:03:24 +0000
292+++ src/PetriEngine/PetriNetBuilder.cpp 2020-10-29 08:34:49 +0000
293@@ -59,20 +59,23 @@
294
295 }
296
297- void PetriNetBuilder::addTransition(const string &name,
298+ void PetriNetBuilder::addTransition(const string &name, const uint32_t player,
299 double, double) {
300 if(_transitionnames.count(name) == 0)
301 {
302 uint32_t next = _transitionnames.size();
303 _transitions.emplace_back();
304+ _transitions.back().player = player;
305 _transitionnames[name] = next;
306- }
307+ }
308+ else if(player != -1)
309+ _transitions[_transitionnames[name]].player = player;
310 }
311
312 void PetriNetBuilder::addInputArc(const string &place, const string &transition, bool inhibitor, int weight) {
313 if(_transitionnames.count(transition) == 0)
314 {
315- addTransition(transition,0.0,0.0);
316+ addTransition(transition,-1,0.0,0.0);
317 }
318 if(_placenames.count(place) == 0)
319 {
320@@ -97,7 +100,7 @@
321 void PetriNetBuilder::addOutputArc(const string &transition, const string &place, int weight) {
322 if(_transitionnames.count(transition) == 0)
323 {
324- addTransition(transition,0,0);
325+ addTransition(transition,-1,0.0,0.0);
326 }
327 if(_placenames.count(place) == 0)
328 {
329@@ -309,6 +312,7 @@
330 --place_prod_count[post.place];
331 ++freeinv;
332 }
333+ net->_players[freetrans] = (trans.player > 0) ? 2 : 1;
334
335 trans_idmap[t] = freetrans;
336
337@@ -423,6 +427,15 @@
338
339 return net;
340 }
341+
342+ bool PetriNetBuilder::isGame() const {
343+ for(size_t i = 0; i < _transitions.size(); ++i)
344+ {
345+ if(_transitions[i].player != 0)
346+ return true;
347+ }
348+ return false;
349+ }
350
351 void PetriNetBuilder::sort()
352 {
353
354=== modified file 'src/PetriEngine/SuccessorGenerator.cpp'
355--- src/PetriEngine/SuccessorGenerator.cpp 2020-03-02 21:03:24 +0000
356+++ src/PetriEngine/SuccessorGenerator.cpp 2020-10-29 08:34:49 +0000
357@@ -18,8 +18,8 @@
358 #include <cassert>
359 namespace PetriEngine {
360
361- SuccessorGenerator::SuccessorGenerator(const PetriNet& net)
362- : _net(net), _parent(NULL) {
363+ SuccessorGenerator::SuccessorGenerator(const PetriNet& net, bool is_game)
364+ : _net(net), _parent(NULL), _is_game(is_game) {
365 reset();
366 }
367 SuccessorGenerator::SuccessorGenerator(const PetriNet& net, std::vector<std::shared_ptr<PQL::Condition> >& queries) : SuccessorGenerator(net){}
368@@ -86,7 +86,7 @@
369 }
370 }
371
372- bool SuccessorGenerator::next(Structures::State& write) {
373+ bool SuccessorGenerator::next(Structures::State& write, PetriNet::player_t player) {
374 for (; _suc_pcounter < _net._nplaces; ++_suc_pcounter) {
375 // orphans are currently under "place 0" as a special case
376 if (_suc_pcounter == 0 || (*_parent).marking()[_suc_pcounter] > 0) {
377@@ -95,7 +95,8 @@
378 }
379 uint32_t last = _net._placeToPtrs[_suc_pcounter + 1];
380 for (; _suc_tcounter != last; ++_suc_tcounter) {
381-
382+ if (_is_game && !_net.ownedBy(_suc_tcounter, player))
383+ continue;
384 if (!checkPreset(_suc_tcounter)) continue;
385 memcpy(write.marking(), (*_parent).marking(), _net._nplaces * sizeof (MarkVal));
386 consumePreset(write, _suc_tcounter);
387@@ -108,6 +109,7 @@
388 }
389 _suc_tcounter = std::numeric_limits<uint32_t>::max();
390 }
391+ reset();
392 return false;
393 }
394 }
395
396=== modified file 'src/PetriParse/PNMLParser.cpp'
397--- src/PetriParse/PNMLParser.cpp 2020-03-10 14:09:07 +0000
398+++ src/PetriParse/PNMLParser.cpp 2020-10-29 08:34:49 +0000
399@@ -69,9 +69,9 @@
400 //Add all the transition
401 for (auto & transition : transitions)
402 if (!isColored) {
403- builder->addTransition(transition.id, transition.x, transition.y);
404+ builder->addTransition(transition.id, transition.player, transition.x, transition.y);
405 } else {
406- builder->addTransition(transition.id, transition.expr, transition.x, transition.y);
407+ builder->addTransition(transition.id, transition.player, transition.expr, transition.x, transition.y);
408 }
409
410 //Add all the arcs
411@@ -553,6 +553,7 @@
412 t.y = 0;
413 t.id = element->first_attribute("id")->value();
414 t.expr = nullptr;
415+ t.player = 0;
416
417
418 for (auto it = element->first_node(); it; it = it->next_sibling()) {
419@@ -567,6 +568,12 @@
420 } else if (strcmp(it->name(), "assignments") == 0) {
421 std::cerr << "assignments not supported" << std::endl;
422 exit(ErrorCode);
423+ }
424+ else if (strcmp(it->name(), "player") == 0)
425+ {
426+ string text;
427+ parseValue(it, text);
428+ t.player = atoll(text.c_str());
429 }
430 }
431 //Add transition to list
432
433=== modified file 'src/VerifyPN.cpp'
434--- src/VerifyPN.cpp 2020-04-28 20:13:40 +0000
435+++ src/VerifyPN.cpp 2020-10-29 08:34:49 +0000
436@@ -543,7 +543,8 @@
437 PNMLParser parser;
438 parser.parse(mfile, &builder);
439 options.isCPN = builder.isColored();
440-
441+ options.isGame = builder.isGame();
442+
443 // Close the file
444 mfile.close();
445 return ContinueCode;
446@@ -686,6 +687,33 @@
447 std::cerr << "CPN OverApproximation is only usable on colored models" << std::endl;
448 return UnknownCode;
449 }
450+ if(options.isGame)
451+ {
452+ if(options.cpnOverApprox)
453+ {
454+ std::cerr << "CPN OverApproximation is not available for synthesis" << std::endl;
455+ return UnknownCode;
456+ }
457+ if(options.enablereduction != 0)
458+ {
459+ std::cerr << "Reductions are not available for synthesis" << std::endl;
460+ return UnknownCode;
461+ }
462+ if(options.queryReductionTimeout != 0)
463+ {
464+ std::cerr << "Query-simplification is not available for synthesis" << std::endl;
465+ return UnknownCode;
466+ }
467+ if(options.tar != 0)
468+ {
469+ std::cerr << "The TAR method does not support synthesis" << std::endl;
470+ return UnknownCode;
471+ }
472+ if(options.stubbornreduction) {
473+ std::cerr << "Stubborn reduction is not support for synthesis" << std::endl;
474+ return UnknownCode;
475+ }
476+ }
477 if (options.printstatistics) {
478 std::cout << "Finished parsing model" << std::endl;
479 }
480@@ -824,6 +852,11 @@
481
482 if (options.queryReductionTimeout > 0 && qt > 0)
483 {
484+ if(options.isGame)
485+ {
486+ std::cerr << "Query-simplification is not available for synthesis" << std::endl;
487+ exit(UnknownCode);
488+ }
489 SimplificationContext simplificationContext(qm0, qnet.get(), qt,
490 options.lpsolveTimeout, &cache);
491 try {
492@@ -969,6 +1002,11 @@
493
494 if (options.enablereduction > 0) {
495 // Compute how many times each place appears in the query
496+ if(options.isGame)
497+ {
498+ std::cerr << "Reductions are not available for synthesis" << std::endl;
499+ return UnknownCode;
500+ }
501 builder.startTimer();
502 builder.reduce(queries, results, options.enablereduction, options.trace, nullptr, options.reductionTimeout, options.reductions);
503 printer.setReducer(builder.getReducer());
504@@ -998,6 +1036,11 @@
505 }
506
507 if (ctl_ids.size() > 0) {
508+ if(options.gamemode)
509+ {
510+ std::cerr << "Synthesis-engine does not support CTL" << std::endl;
511+ return UnknownCode;
512+ }
513 options.isctl=true;
514 PetriEngine::Reachability::Strategy reachabilityStrategy=options.strategy;
515
516@@ -1060,6 +1103,11 @@
517
518 if(options.tar && net->numberOfPlaces() > 0)
519 {
520+ if(options.isGame)
521+ {
522+ std::cerr << "The TAR method is not available for synthesis" << std::endl;
523+ return UnknownCode;
524+ }
525 //Create reachability search strategy
526 TARReachabilitySearch strategy(printer, *net, builder.getReducer(), options.kbound);
527
528@@ -1074,6 +1122,11 @@
529 }
530 else
531 {
532+ if(options.gamemode)
533+ {
534+ std::cerr << "Synthesis-engine does not support Reachability" << std::endl;
535+ return UnknownCode;
536+ }
537 ReachabilitySearch strategy(*net, printer, options.kbound);
538
539 // Change default place-holder to default strategy

Subscribers

People subscribed via source and target branches

to all changes: