mCRL2
Loading...
Searching...
No Matches
pbesinst_fatal_attractors.h
Go to the documentation of this file.
1// Author(s): Wieger Wesselink
2// Copyright: see the accompanying file COPYING or copy at
3// https://github.com/mCRL2org/mCRL2/blob/master/COPYING
4//
5// Distributed under the Boost Software License, Version 1.0.
6// (See accompanying file LICENSE_1_0.txt or copy at
7// http://www.boost.org/LICENSE_1_0.txt)
8//
9/// \file mcrl2/pbes/pbesinst_fatal_attractors.h
10/// \brief add your file description here.
11
12#ifndef MCRL2_PBES_PBESINST_FATAL_ATTRACTORS_H
13#define MCRL2_PBES_PBESINST_FATAL_ATTRACTORS_H
14
15#include "mcrl2/pbes/pbessolve_attractors.h"
16#include "mcrl2/pbes/simple_structure_graph.h"
17
18
19
20
21
22namespace mcrl2::pbes_system::detail {
23
24template <typename StructureGraph, typename Compare>
25deque_vertex_set attr_min_rank_todo_generic(const StructureGraph& G, const vertex_set& A, const vertex_set& U, std::size_t j, Compare compare)
26{
27 std::size_t n = G.extent();
28 deque_vertex_set todo(n);
29 for (auto v: A.vertices())
30 {
31 for (auto u: G.predecessors(v))
32 {
33 if (U.contains(u) && compare(G.rank(u), j) && !A.contains(u))
34 {
35 todo.insert(u);
36 }
37 }
38 }
39 return todo;
40}
41
42template <typename StructureGraph>
43deque_vertex_set attr_min_rank_original_todo(const StructureGraph& G, const vertex_set& A, const vertex_set& U, std::size_t j)
44{
45 std::size_t n = G.extent();
46 deque_vertex_set todo(n);
47 for (auto v: A.vertices())
48 {
49 for (auto u: G.predecessors(v))
50 {
51 if (U.contains(u) && G.rank(u) >= j)
52 {
53 todo.insert(u);
54 }
55 }
56 }
57 return todo;
58}
59
60inline
62{
63 auto i = U_rank_map.find(j);
64 if (i == U_rank_map.end())
65 {
67 }
68 i->second.insert(u);
69}
70
71template <typename StructureGraph>
73{
74 std::size_t n = G.extent();
75
76 // compute U_j_map, such that U_j_map[j] = U_j
79 {
80 std::size_t j = G.rank(u);
81 if (j == data::undefined_index())
82 {
83 continue;
84 }
85 auto alpha = j % 2;
87 {
88 continue;
89 }
91 }
92 return U_j_map;
93}
94
95// Computes an attractor set, by extending A. Only predecessors in U are considered with a rank of at least j.
96// alpha = 0: disjunctive
97// alpha = 1: conjunctive
98// StructureGraph is either structure_graph or simple_structure_graph
99template <typename StructureGraph, typename Compare>
101{
102 // put all predecessors of elements in A in todo
104
105 while (!todo.is_empty())
106 {
107 // N.B. Use a breadth first search, to minimize counter examples
108 auto u = todo.pop_front();
109
110 if (G.decoration(u) == alpha || includes_successors(G, u, A))
111 {
113
114 A.insert(u);
115
116 for (auto v: G.predecessors(u))
117 {
118 if (U.contains(v) && (compare(G.rank(v), j) || (G.rank(v) == data::undefined_index() && G.decoration(v) <= 1)) && !A.contains(v))
119 {
120 todo.insert(v);
121 }
122 }
123 }
124 }
125
126 return A;
127}
128
129// calculation_steps is used to count how many steps are required to calculate a fatal_attractor.
130template <typename Compare>
132 std::array<vertex_set, 2>& S,
137 )
138{
139 mCRL2log(log::debug) << "\n === fatal attractors (equation " << equation_count << ") ===\n" << G << std::endl;
140 mCRL2log(log::debug) << " S0 = " << S[0] << std::endl;
141 mCRL2log(log::debug) << " S1 = " << S[1] << std::endl;
142
143 // count the number of insertions in the sets S[0] and S[1]
145 std::size_t n = G.extent();
146
147 // compute V
148 vertex_set V(n);
149 for (std::size_t u = 0; u < n; u++)
150 {
152 V.insert(u);
153 }
154
155 // compute U_j_map, such that U_j_map[j] = U_j
157
158 S[0] = attr_default_with_tau(G, S[0], 0, tau);
159 S[1] = attr_default_with_tau(G, S[1], 1, tau);
160
161 for (auto& p: U_j_map)
162 {
163 std::size_t j = p.first;
164 auto alpha = j % 2;
165 mCRL2log(log::debug) << " --- iteration j = " << j << " ---" << std::endl;
166
168 U_j = set_minus(U_j, S[1 - alpha]);
169 mCRL2log(log::debug) << " U_" << std::to_string(j) << " = " << U_j << std::endl;
173
174 while (X != Y)
175 {
177 mCRL2log(log::debug) << " X = " << X << std::endl;
178 mCRL2log(log::debug) << " Y = " << Y << std::endl;
180 Y = set_minus(Y, attr_default(G, set_minus(Y, X), 1 - alpha));
181 }
182 mCRL2log(log::debug) << " X (final) = " << X << std::endl;
183
184 // set strategy for v \in X \ S[alpha]
186 {
188 if (S[alpha].contains(v))
189 {
190 continue;
191 }
193 {
194 if (U_j.contains(v))
195 {
196 auto w = find_successor_in(G, v, Y);
198 }
199 else
200 {
201 auto tau_v = G.find_vertex(v).strategy;
203 }
204 }
205 }
206
207 // S_alpha := S_alpha U X
209 {
212 S[alpha].insert(x);
213 mCRL2log(log::debug) << " insert vertex " << x << " in S" << alpha << std::endl;
214 }
215
217 }
218 mCRL2log(log::debug) << "\n === result of fatal attractors (equation " << equation_count << ") ===" << std::endl;
219 mCRL2log(log::debug) << " S0 = " << S[0] << std::endl;
220 mCRL2log(log::debug) << " S1 = " << S[1] << std::endl;
221 mCRL2log(log::debug) << " tau0 = " << print_strategy_vector(S[0], tau[0]) << std::endl;
222 mCRL2log(log::debug) << " tau1 = " << print_strategy_vector(S[1], tau[1]) << std::endl;
223 mCRL2log(log::debug) << " inserted " << insertion_count << " vertices." << std::endl;
224}
225
226inline
228 std::array<vertex_set, 2>& S,
232 )
233{
235}
236
237// calculation_steps returns how many steps were needed to find the loops.
238inline
240 std::array<vertex_set, 2>& S,
244)
245{
247}
248
249// Computes an attractor set, by extending A. Only predecessors in U are considered with a rank of at least j.
250// alpha = 0: disjunctive
251// alpha = 1: conjunctive
252// StructureGraph is either structure_graph or simple_structure_graph
253// This version is based on the work of Michael Huth, Jim Huan-Pu Kuo, and Nir Piterman.
254template <typename StructureGraph>
256{
257 // put all predecessors of elements in A in todo
259
260 vertex_set X(A.extent());
261 for (auto u: todo.vertices())
262 {
263 if (A.contains(u) && (G.decoration(u) == alpha || includes_successors(G, u, A)))
264 {
265 X.insert(u);
266 }
267 }
268
269 while (!todo.is_empty())
270 {
271 // N.B. Use a breadth first search, to minimize counter examples
272 auto u = todo.pop_front();
273
275 {
277
278 X.insert(u);
279
280 for (auto v: G.predecessors(u))
281 {
282 if (U.contains(v) && (G.rank(v) >= j || (G.rank(v) == data::undefined_index() && G.decoration(v) <= 1)) && !X.contains(v))
283 {
284 todo.insert(v);
285 }
286 }
287 }
288 }
289
290 return X;
291}
292
293inline
295 std::array<vertex_set, 2>& S,
298)
299{
300 mCRL2log(log::debug) << "\n === fatal attractors original (equation " << equation_count << ") ===\n" << G << std::endl;
301 mCRL2log(log::debug) << " S0 = " << S[0] << std::endl;
302 mCRL2log(log::debug) << " S1 = " << S[1] << std::endl;
303
304 // count the number of insertions in the sets S[0] and S[1]
306 std::size_t n = G.extent();
307
308 // compute V
309 vertex_set V(n);
310 for (std::size_t u = 0; u < n; u++)
311 {
312 V.insert(u);
313 }
314
315 // compute U_j_map, such that U_j_map[j] = U_j
317
318 S[0] = attr_default_with_tau(G, S[0], 0, tau);
319 S[1] = attr_default_with_tau(G, S[1], 1, tau);
320
321 for (auto& p: U_j_map)
322 {
323 std::size_t j = p.first;
324 auto alpha = j % 2;
325 mCRL2log(log::debug) << " --- iteration j = " << j << " ---" << std::endl;
326
328 U_j = set_minus(U_j, S[1 - alpha]);
329
330 vertex_set X(n);
331
332 while (!U_j.is_empty() && U_j != X)
333 {
334 mCRL2log(log::debug) << " U_" + std::to_string(j) << " = " << U_j << std::endl;
335 X = U_j;
336 mCRL2log(log::debug) << " X = " << X << std::endl;
337 mCRL2log(log::debug) << " X U S_" + std::to_string(alpha) << " = " << set_union(X, S[alpha]) << std::endl;
339 mCRL2log(log::debug) << " Y = " << Y << std::endl;
340 mCRL2log(log::debug) << " U_" + std::to_string(j) << " is " << (is_subset_of(U_j, Y) ? "a" : "no") << " subset of Y" << std::endl;
341 if (is_subset_of(U_j, Y))
342 {
343 // set strategy for v \in Y \ S[alpha]
345 {
346 if (S[alpha].contains(v))
347 {
348 continue;
349 }
351 {
352 if (U_j.contains(v))
353 {
354 auto w = find_successor_in(G, v, Y);
356 }
357 else
358 {
359 auto tau_v = G.find_vertex(v).strategy;
361 }
362 }
363 }
364
365 // S_alpha := S_alpha U Y
367 {
369 S[alpha].insert(y);
370 mCRL2log(log::debug) << " insert vertex " << y << " in S" << alpha << std::endl;
371 }
372
374 break;
375 }
376 else
377 {
379 }
380 }
381 }
382 mCRL2log(log::debug) << "\n === result of fatal attractors original (equation " << equation_count << ") ===" << std::endl;
383 mCRL2log(log::debug) << " S0 = " << S[0] << std::endl;
384 mCRL2log(log::debug) << " S1 = " << S[1] << std::endl;
385 mCRL2log(log::debug) << " tau0 = " << print_strategy_vector(S[0], tau[0]) << std::endl;
386 mCRL2log(log::debug) << " tau1 = " << print_strategy_vector(S[1], tau[1]) << std::endl;
387 mCRL2log(log::debug) << " inserted " << insertion_count << " vertices." << std::endl;
388}
389
390} // namespace mcrl2::pbes_system::detail
391
392
393
394
395
396#endif // MCRL2_PBES_PBESINST_FATAL_ATTRACTORS_H
#define mCRL2log(LEVEL)
mCRL2log(LEVEL) provides the stream used to log.
Definition logger.h:393
void insert_in_rank_map(std::map< std::size_t, vertex_set > &U_rank_map, structure_graph::index_type u, std::size_t j, std::size_t n)
deque_vertex_set attr_min_rank_original_todo(const StructureGraph &G, const vertex_set &A, const vertex_set &U, std::size_t j)
deque_vertex_set attr_min_rank_todo_generic(const StructureGraph &G, const vertex_set &A, const vertex_set &U, std::size_t j, Compare compare)