Merge lp:~tapaal-ltl/verifypn/weak-tarjan2 into lp:~tapaal-ltl/verifypn/ltl-model-checker

Proposed by Simon Virenfeldt
Status: Merged
Merged at revision: 237
Proposed branch: lp:~tapaal-ltl/verifypn/weak-tarjan2
Merge into: lp:~tapaal-ltl/verifypn/ltl-model-checker
Diff against target: 248 lines (+64/-33)
8 files modified
include/LTL/LTL_algorithm/ModelChecker.h (+3/-1)
include/LTL/LTL_algorithm/NestedDepthFirstSearch.h (+2/-4)
include/LTL/LTL_algorithm/TarjanModelChecker.h (+4/-2)
include/PetriEngine/PQL/Expressions.h (+11/-18)
src/LTL/LTL_algorithm/ModelChecker.cpp (+2/-2)
src/LTL/LTL_algorithm/TarjanModelChecker.cpp (+18/-4)
src/LTLMain.cpp (+2/-2)
src/PetriEngine/PQL/Expressions.cpp (+22/-0)
To merge this branch: bzr merge lp:~tapaal-ltl/verifypn/weak-tarjan2
Reviewer Review Type Date Requested Status
Nikolaj Jensen Ulrik Approve
Review via email: mp+395141@code.launchpad.net

Description of the change

Implements weak tarjan and is_reachability for LTL formulas

To post a comment you must log in.
Revision history for this message
Nikolaj Jensen Ulrik (waefwerf) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'include/LTL/LTL_algorithm/ModelChecker.h'
2--- include/LTL/LTL_algorithm/ModelChecker.h 2020-11-11 12:50:38 +0000
3+++ include/LTL/LTL_algorithm/ModelChecker.h 2020-12-10 12:09:22 +0000
4@@ -12,7 +12,7 @@
5 namespace LTL {
6 class ModelChecker {
7 public:
8- ModelChecker(const PetriEngine::PetriNet& net, PetriEngine::PQL::Condition_ptr);
9+ ModelChecker(const PetriEngine::PetriNet& net, PetriEngine::PQL::Condition_ptr, const bool shortcircuitweak);
10 virtual bool isSatisfied() = 0;
11
12 virtual ~ModelChecker() = default;
13@@ -23,6 +23,8 @@
14 PetriEngine::PQL::Condition_ptr formula;
15
16 size_t _discovered = 0;
17+ const bool shortcircuitweak;
18+ bool is_weak = false;
19 };
20 }
21
22
23=== modified file 'include/LTL/LTL_algorithm/NestedDepthFirstSearch.h'
24--- include/LTL/LTL_algorithm/NestedDepthFirstSearch.h 2020-11-18 12:49:59 +0000
25+++ include/LTL/LTL_algorithm/NestedDepthFirstSearch.h 2020-12-10 12:09:22 +0000
26@@ -20,8 +20,8 @@
27 class NestedDepthFirstSearch : public ModelChecker {
28 public:
29 NestedDepthFirstSearch(const PetriNet &net, PetriEngine::PQL::Condition_ptr ptr, const bool shortcircuitweak)
30- : ModelChecker(net, ptr), factory{net, successorGenerator->initial_buchi_state()},
31- states(net, 0, (int)net.numberOfPlaces() + 1), shortcircuitweak(shortcircuitweak) {}
32+ : ModelChecker(net, ptr, shortcircuitweak), factory{net, successorGenerator->initial_buchi_state()},
33+ states(net, 0, (int)net.numberOfPlaces() + 1) {}
34
35 bool isSatisfied() override;
36
37@@ -40,8 +40,6 @@
38
39 State *seed;
40 bool violation = false;
41- bool is_weak = false;
42- const bool shortcircuitweak;
43
44 void dfs();
45
46
47=== modified file 'include/LTL/LTL_algorithm/TarjanModelChecker.h'
48--- include/LTL/LTL_algorithm/TarjanModelChecker.h 2020-12-10 10:06:53 +0000
49+++ include/LTL/LTL_algorithm/TarjanModelChecker.h 2020-12-10 12:09:22 +0000
50@@ -21,8 +21,8 @@
51 template <bool SaveTrace>
52 class TarjanModelChecker : public ModelChecker {
53 public:
54- TarjanModelChecker(const PetriEngine::PetriNet &net, const Condition_ptr &cond)
55- : ModelChecker(net, cond), factory(net, successorGenerator->initial_buchi_state()),
56+ TarjanModelChecker(const PetriEngine::PetriNet &net, const Condition_ptr &cond, const bool shortcircuitweak)
57+ : ModelChecker(net, cond, shortcircuitweak), factory(net, successorGenerator->initial_buchi_state()),
58 seen(net, 0, (int) net.numberOfPlaces() + 1) {
59 chash.fill(std::numeric_limits<idx_t>::max());
60 }
61@@ -84,6 +84,8 @@
62 void update(idx_t to);
63
64 bool nexttrans(State &state, State& parent, DEntry &delem);
65+
66+ void popCStack();
67 };
68 extern template class TarjanModelChecker<true>;
69 extern template class TarjanModelChecker<false>;
70
71=== modified file 'include/PetriEngine/PQL/Expressions.h'
72--- include/PetriEngine/PQL/Expressions.h 2020-12-04 11:14:38 +0000
73+++ include/PetriEngine/PQL/Expressions.h 2020-12-10 12:09:22 +0000
74@@ -439,10 +439,7 @@
75
76 Retval simplify(SimplificationContext& context) const override;
77
78- bool isReachability(uint32_t depth) const override {
79- // TODO implement
80- assert(false); std::cerr << "TODO implement" << std::endl; exit(0);
81- }
82+ bool isReachability(uint32_t depth) const override;
83 Condition_ptr prepareForReachability(bool negated) const override {
84 // TODO implement
85 assert(false); std::cerr << "TODO implement" << std::endl; exit(0);
86@@ -475,10 +472,7 @@
87 Result evaluate(const EvaluationContext& context) override;
88
89 Retval simplify(SimplificationContext& context) const override;
90- bool isReachability(uint32_t depth) const override {
91- // TODO implement
92- assert(false); std::cerr << "TODO implement" << std::endl; exit(0);
93- }
94+ bool isReachability(uint32_t depth) const override;
95 Condition_ptr prepareForReachability(bool negated) const override {
96 // TODO implement
97 assert(false); std::cerr << "TODO implement" << std::endl; exit(0);
98@@ -506,10 +500,9 @@
99 Result evaluate(const EvaluationContext &context) override;
100
101 bool isReachability(uint32_t depth) const override {
102- // TODO implement
103- assert(false);
104- std::cerr << "TODO implement" << std::endl;
105- exit(0);
106+ // This could potentially be a reachability formula if the parent is an A.
107+ // This case is however already handled by ACondition.
108+ return false;
109 }
110
111 Condition_ptr prepareForReachability(bool negated) const override {
112@@ -557,10 +550,11 @@
113 Result evaluate(const EvaluationContext& context) override;
114
115 Retval simplify(SimplificationContext& context) const override;
116- bool isReachability(uint32_t depth) const override {
117- // TODO implement
118- assert(false); std::cerr << "TODO implement" << std::endl; exit(0);
119- }
120+ bool isReachability(uint32_t depth) const override {
121+ // This could potentially be a reachability formula if the parent is an E.
122+ // This case is however already handled by ECondition.
123+ return false;
124+ }
125 Condition_ptr prepareForReachability(bool negated) const override {
126 // TODO implement
127 assert(false); std::cerr << "TODO implement" << std::endl; exit(0);
128@@ -587,8 +581,7 @@
129 using SimpleQuantifierCondition::SimpleQuantifierCondition;
130
131 bool isReachability(uint32_t depth) const override {
132- // TODO implement
133- assert(false); std::cerr << "TODO implement" << std::endl; exit(0);
134+ return false;
135 }
136 Condition_ptr prepareForReachability(bool negated) const override {
137 // TODO implement
138
139=== modified file 'src/LTL/LTL_algorithm/ModelChecker.cpp'
140--- src/LTL/LTL_algorithm/ModelChecker.cpp 2020-10-16 12:11:46 +0000
141+++ src/LTL/LTL_algorithm/ModelChecker.cpp 2020-12-10 12:09:22 +0000
142@@ -7,8 +7,8 @@
143 #include <utility>
144
145 namespace LTL {
146- ModelChecker::ModelChecker(const PetriEngine::PetriNet& net, PetriEngine::PQL::Condition_ptr condition)
147- : net(net), formula(condition)
148+ ModelChecker::ModelChecker(const PetriEngine::PetriNet& net, PetriEngine::PQL::Condition_ptr condition, const bool shortcircuitweak)
149+ : net(net), formula(condition), shortcircuitweak(shortcircuitweak)
150 {
151
152 successorGenerator = std::make_unique<ProductSuccessorGenerator>(net, condition);
153
154=== modified file 'src/LTL/LTL_algorithm/TarjanModelChecker.cpp'
155--- src/LTL/LTL_algorithm/TarjanModelChecker.cpp 2020-12-10 10:06:53 +0000
156+++ src/LTL/LTL_algorithm/TarjanModelChecker.cpp 2020-12-10 12:09:22 +0000
157@@ -21,6 +21,8 @@
158
159 template<bool SaveTrace>
160 bool TarjanModelChecker<SaveTrace>::isSatisfied() {
161+ is_weak = successorGenerator->is_weak();
162+ std::cerr << "Is weak: " << is_weak << std::endl;
163 std::vector<State> initial_states;
164 successorGenerator->makeInitialState(initial_states);
165 State working = factory.newState();
166@@ -128,10 +130,14 @@
167 dstack.pop();
168 if (cstack[p].lowlink == p) {
169 while (cstack.size() > p) {
170- auto h = hash(cstack.back().stateid);
171- store.insert(cstack.back().stateid);
172- chash[h] = cstack.back().next;
173- cstack.pop_back();
174+ popCStack();
175+ }
176+ } else if (is_weak) {
177+ State state = factory.newState();
178+ seen.decode(state, cstack[p].stateid);
179+ if(!successorGenerator->isAccepting(state)){
180+ popCStack();
181+ weakskip = true;
182 }
183 }
184 if (!astack.empty() && p == astack.top()) {
185@@ -143,6 +149,14 @@
186 }
187
188 template<bool SaveTrace>
189+ void TarjanModelChecker<SaveTrace>::popCStack(){
190+ auto h = hash(cstack.back().stateid);
191+ store.insert(cstack.back().stateid);
192+ chash[h] = cstack.back().next;
193+ cstack.pop_back();
194+ }
195+
196+ template<bool SaveTrace>
197 void TarjanModelChecker<SaveTrace>::update(idx_t to) {
198 const auto from = dstack.top().pos;
199 if (cstack[to].lowlink <= cstack[from].lowlink) {
200
201=== modified file 'src/LTLMain.cpp'
202--- src/LTLMain.cpp 2020-12-04 11:14:38 +0000
203+++ src/LTLMain.cpp 2020-12-10 12:09:22 +0000
204@@ -739,9 +739,9 @@
205 break;
206 case LTL::Algorithm::Tarjan:
207 if (options.trace)
208- modelChecker = std::make_unique<LTL::TarjanModelChecker<true>>(*net, negated_formula);
209+ modelChecker = std::make_unique<LTL::TarjanModelChecker<true>>(*net, negated_formula, true);
210 else
211- modelChecker = std::make_unique<LTL::TarjanModelChecker<false>>(*net, negated_formula);
212+ modelChecker = std::make_unique<LTL::TarjanModelChecker<false>>(*net, negated_formula, true);
213 break;
214 }
215 satisfied = negate_answer ^ modelChecker->isSatisfied();
216
217=== modified file 'src/PetriEngine/PQL/Expressions.cpp'
218--- src/PetriEngine/PQL/Expressions.cpp 2020-11-19 11:20:22 +0000
219+++ src/PetriEngine/PQL/Expressions.cpp 2020-12-10 12:09:22 +0000
220@@ -2994,6 +2994,28 @@
221 bool AFCondition::isReachability(uint32_t depth) const {
222 return false;
223 }
224+
225+ bool ECondition::isReachability(uint32_t depth) const {
226+ if (depth != 0) {
227+ return false;
228+ }
229+
230+ if (auto cond = dynamic_cast<FCondition*>(_cond.get())) {
231+ // EF is a reachability formula so skip checking the F.
232+ return cond[0].isReachability(depth + 1);
233+ }
234+ return _cond->isReachability(depth + 1);
235+ }
236+
237+ bool ACondition::isReachability(uint32_t depth) const {
238+ if (depth != 0) {
239+ return false;
240+ }
241+ if (auto cond = dynamic_cast<GCondition*>(_cond.get())) {
242+ return cond[0].isReachability(depth + 1);
243+ }
244+ return _cond->isReachability(depth + 1);
245+ }
246
247 bool UntilCondition::isReachability(uint32_t depth) const {
248 return false;

Subscribers

People subscribed via source and target branches

to all changes: