mCRL2
Loading...
Searching...
No Matches
pbesinst_find_loops.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//
11
12#ifndef MCRL2_PBES_PBESINST_FIND_LOOPS_H
13#define MCRL2_PBES_PBESINST_FIND_LOOPS_H
14
19
20namespace mcrl2 {
21
22namespace pbes_system {
23
24namespace detail {
25
26inline
28 const vertex_set& U,
31 std::size_t p,
32 std::unordered_map<structure_graph::index_type, bool>& visited
33)
34{
35 const auto& w_ = G.find_vertex(w);
36 if (w_.decoration == structure_graph::d_true || w_.decoration == structure_graph::d_false)
37 {
38 return false;
39 }
40 if (w_.rank != data::undefined_index() && w_.rank != p)
41 {
42 return false;
43 }
44 auto i = visited.find(w);
45 if (i != visited.end())
46 {
47 return i->second;
48 }
49
50 if (U.contains(w))
51 {
52 visited[w] = false;
53 if (w_.decoration == structure_graph::d_none || w_.decoration == p % 2)
54 {
55 for (structure_graph::index_type u: w_.successors)
56 {
57 if (u == v || find_loop(G, U, v, u, p, visited))
58 {
60 visited[w] = true;
61 mCRL2log(log::debug) << " case 1: found a loop starting in " << v << " with current vertex w = " << w << std::endl;
62 return true;
63 }
64 }
65 }
66 else
67 {
68 return false;
69 }
70 }
71 return false;
72}
73
74template <class Container>
76 const Container& discovered,
77 const pbesinst_lazy_todo& todo, std::array<vertex_set, 2>& S,
78 std::array<strategy_vector, 2>& tau, std::size_t iteration_count,
79 const detail::structure_graph_builder& graph_builder
80 )
81{
82 mCRL2log(log::debug) << "Apply find loops (iteration " << iteration_count << ") to graph:\n" << G << std::endl;
83
84 // count the number of insertions in the sets S[0] and S[1]
85 std::size_t insertion_count = 0;
86
87 std::size_t n = S[0].extent();
88
89 // compute todo_
90 boost::dynamic_bitset<> todo_(n);
91 /* for (const propositional_variable_instantiation& X: todo.all_elements()) range::join does not seem to work.
92 Hence split in todo.elements() and todo.irrelevant_elements() below.
93 {
94 structure_graph::index_type u = graph_builder.find_vertex(X);
95 todo_[u] = true;
96 } */
97
99 {
100 structure_graph::index_type u = graph_builder.find_vertex(X);
101 todo_[u] = true;
102 }
103
105 {
106 structure_graph::index_type u = graph_builder.find_vertex(X);
107 todo_[u] = true;
108 }
109
110 // compute done
111 vertex_set done(n);
112 for (const propositional_variable_instantiation& X: discovered)
113 {
114 structure_graph::index_type u = graph_builder.find_vertex(X);
115 if (!todo_[u])
116 {
117 done.insert(u);
118 }
119 }
120
121 std::unordered_map<structure_graph::index_type, bool> visited;
122 bool b0 = false;
123 bool b1 = false;
124
126 {
127 const auto& u_ = G.find_vertex(u);
128 assert(u_.rank != data::undefined_index());
129
130 mCRL2log(log::debug) << "--- choose u = " << u << std::endl;
131 auto i = visited.find(u);
132 if (i != visited.end())
133 {
134 visited[u] = false;
135 }
136 bool b = find_loop(G, done, u, u, u_.rank, visited);
137 visited[u] = b;
138 if (b)
139 {
140 if (u_.rank % 2 == 0)
141 {
142 S[0].insert(u);
143 b0 = true;
144 insertion_count++;
145 mCRL2log(log::debug) << "Find loops: insert vertex " << u << " in S[0]" << std::endl;
146 }
147 else
148 {
149 S[1].insert(u);
150 b1 = true;
151 insertion_count++;
152 mCRL2log(log::debug) << "Find loops: insert vertex " << u << " in S[1]" << std::endl;
153 }
154 }
155 if (b0)
156 {
157 S[0] = attr_default_with_tau(G, S[0], 0, tau);
158 }
159 if (b1)
160 {
161 S[1] = attr_default_with_tau(G, S[1], 1, tau);
162 }
163 }
164
165 mCRL2log(log::debug) << "Find loops: (iteration " << iteration_count << ") inserted " << insertion_count << " vertices." << std::endl;
166}
167
168} // namespace detail
169
170} // namespace pbes_system
171
172} // namespace mcrl2
173
174#endif // MCRL2_PBES_PBESINST_FIND_LOOPS_H
const atermpp::deque< propositional_variable_instantiation > & elements() const
const std::unordered_set< propositional_variable_instantiation > & irrelevant_elements() const
\brief A propositional variable instantiation
#define mCRL2log(LEVEL)
mCRL2log(LEVEL) provides the stream used to log.
Definition logger.h:391
constexpr std::size_t undefined_index()
Returns an index that corresponds to 'undefined'.
Definition undefined.h:27
void find_loops(const simple_structure_graph &G, const Container &discovered, const pbesinst_lazy_todo &todo, std::array< vertex_set, 2 > &S, std::array< strategy_vector, 2 > &tau, std::size_t iteration_count, const detail::structure_graph_builder &graph_builder)
bool find_loop(const simple_structure_graph &G, const vertex_set &U, structure_graph::index_type v, structure_graph::index_type w, std::size_t p, std::unordered_map< structure_graph::index_type, bool > &visited)
vertex_set attr_default_with_tau(const StructureGraph &G, vertex_set A, std::size_t alpha, std::array< strategy_vector, 2 > &tau)
A class that takes a linear process specification and checks all tau-summands of that LPS for conflue...
Definition indexed_set.h:72
add your file description here.
add your file description here.
index_type find_vertex(const pbes_expression &x) const
void set_strategy(structure_graph::index_type u, structure_graph::index_type v)
void insert(structure_graph::index_type u)
bool contains(structure_graph::index_type u) const
const std::vector< structure_graph::index_type > & vertices() const
add your file description here.