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//
9/// \file mcrl2/pbes/pbesinst_find_loops.h
10/// \brief add your file description here.
11
12#ifndef MCRL2_PBES_PBESINST_FIND_LOOPS_H
13#define MCRL2_PBES_PBESINST_FIND_LOOPS_H
14
15#include "mcrl2/pbes/pbesinst_lazy.h"
16#include "mcrl2/pbes/pbessolve_attractors.h"
17#include "mcrl2/pbes/simple_structure_graph.h"
18#include "mcrl2/pbes/structure_graph_builder.h"
19
20
21
22
23
24namespace mcrl2::pbes_system::detail {
25
26inline
28 const vertex_set& U,
29 structure_graph::index_type v,
30 structure_graph::index_type w,
31 std::size_t p,
33)
34{
35 const auto& w_ = G.find_vertex(w);
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 {
59 global_strategy<simple_structure_graph>(G).set_strategy(w, u == v ? v : u);
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
92 for (const propositional_variable_instantiation& X: todo.elements())
93 {
94 structure_graph::index_type u = graph_builder.find_vertex(X);
95 todo_[u] = true;
96 }
97
98 // compute done
99 vertex_set done(n);
100 for (const propositional_variable_instantiation& X: discovered)
101 {
102 structure_graph::index_type u = graph_builder.find_vertex(X);
103 if (!todo_[u])
104 {
105 done.insert(u);
106 }
107 }
108
109 std::unordered_map<structure_graph::index_type, bool> visited;
110 bool b0 = false;
111 bool b1 = false;
112
113 for (structure_graph::index_type u: done.vertices())
114 {
115 const auto& u_ = G.find_vertex(u);
116 assert(u_.rank != data::undefined_index());
117
118 mCRL2log(log::debug) << "--- choose u = " << u << std::endl;
119 auto i = visited.find(u);
120 if (i != visited.end())
121 {
122 visited[u] = false;
123 }
124 bool b = find_loop(G, done, u, u, u_.rank, visited);
125 visited[u] = b;
126 if (b)
127 {
128 if (u_.rank % 2 == 0)
129 {
130 S[0].insert(u);
131 b0 = true;
132 insertion_count++;
133 mCRL2log(log::debug) << "Find loops: insert vertex " << u << " in S[0]" << std::endl;
134 }
135 else
136 {
137 S[1].insert(u);
138 b1 = true;
139 insertion_count++;
140 mCRL2log(log::debug) << "Find loops: insert vertex " << u << " in S[1]" << std::endl;
141 }
142 }
143 if (b0)
144 {
145 S[0] = attr_default_with_tau(G, S[0], 0, tau);
146 }
147 if (b1)
148 {
149 S[1] = attr_default_with_tau(G, S[1], 1, tau);
150 }
151 }
152
153 mCRL2log(log::debug) << "Find loops: (iteration " << iteration_count << ") inserted " << insertion_count << " vertices." << std::endl;
154}
155
156} // namespace mcrl2::pbes_system::detail
157
158
159
160
161
162#endif // MCRL2_PBES_PBESINST_FIND_LOOPS_H
\brief A propositional variable instantiation
const vertex & find_vertex(index_type u) const
#define mCRL2log(LEVEL)
mCRL2log(LEVEL) provides the stream used to log.
Definition logger.h:393
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)
index_type find_vertex(const pbes_expression &x) const
void insert(structure_graph::index_type u)
bool contains(structure_graph::index_type u) const