mCRL2
Loading...
Searching...
No Matches
pbessolve_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/pbessolve_attractors.h
10/// \brief add your file description here.
11
12#ifndef MCRL2_PBES_PBESSOLVE_ATTRACTORS_H
13#define MCRL2_PBES_PBESSOLVE_ATTRACTORS_H
14
15#include "mcrl2/pbes/pbessolve_vertex_set.h"
16
17namespace mcrl2::pbes_system {
18
19// Does not set a strategy
21{
22 static void set_strategy(structure_graph::index_type /* u */, structure_graph::index_type /* v */)
23 {}
24};
25
26// Puts strategy annotations in the strategy attributes of the nodes of graph G
27template <typename StructureGraph>
29{
30 const StructureGraph& G;
31
32 explicit global_strategy(const StructureGraph& G_)
33 : G(G_)
34 {}
35
36 void set_strategy(structure_graph::index_type u, structure_graph::index_type v)
37 {
38 if (v == undefined_vertex())
39 {
40 mCRL2log(log::debug) << "Error: undefined strategy for node " << u << std::endl;
41 }
42 mCRL2log(log::debug) << " set tau[" << u << "] = " << v << std::endl;
43 G.find_vertex(u).strategy = v;
44 }
45};
46
47// Puts strategy annotations in tau[alpha]
49{
50 std::array<strategy_vector, 2>& tau;
52
53 local_strategy(std::array<strategy_vector, 2>& tau_, std::size_t alpha_)
54 : tau(tau_), alpha(alpha_)
55 {}
56
57 void set_strategy(structure_graph::index_type u, structure_graph::index_type v)
58 {
59 if (v == undefined_vertex())
60 {
61 mCRL2log(log::debug) << "Error: undefined strategy for node " << u << std::endl;
62 }
63 mCRL2log(log::debug) << " set tau" << alpha << "[" << u << "] = " << v << std::endl;
64 tau[alpha][u] = v;
65 }
66};
67
68// Combination of global and local strategy
69template <typename StructureGraph>
71{
72 global_strategy<StructureGraph> global;
74
75 global_local_strategy(const StructureGraph& G, std::array<strategy_vector, 2>& tau, std::size_t alpha)
76 : global(G), local(tau, alpha)
77 {}
78
79 void set_strategy(structure_graph::index_type u, structure_graph::index_type v)
80 {
81 global.set_strategy(u, v);
82 local.set_strategy(u, v);
83 }
84};
85
86// Returns true if succ(u) \subseteq A
87template <typename StructureGraph, typename VertexSet>
88bool includes_successors(const StructureGraph& G, typename StructureGraph::index_type u, const VertexSet& A)
89{
90 for (auto v: G.successors(u))
91 {
92 if (!A.contains(v))
93 {
94 return false;
95 }
96 }
97 return true;
98}
99
100// Returns pred(A) \ A
101template <typename StructureGraph>
102deque_vertex_set exclusive_predecessors(const StructureGraph& G, const vertex_set& A)
103{
104 // put all predecessors of elements in A in todo
105 deque_vertex_set todo(G.all_vertices().size());
106 for (auto u: A.vertices())
107 {
108 for (auto v: G.predecessors(u))
109 {
110 if (!A.contains(v))
111 {
112 todo.insert(v);
113 }
114 }
115 }
116 return todo;
117}
118
119// Inserts pred(u) \ A into todo
120template <typename StructureGraph>
121void insert_predecessors(const StructureGraph& G, structure_graph::index_type u, const vertex_set& A, deque_vertex_set& todo)
122{
123 for (auto v: G.predecessors(u))
124 {
125 if (!A.contains(v))
126 {
127 todo.insert(v);
128 }
129 }
130}
131
132// Computes an attractor set, by extending A.
133// alpha = 0: disjunctive
134// alpha = 1: conjunctive
135// StructureGraph is either structure_graph or simple_structure_graph
136// Strategy is either no_strategy, global_strategy, local_strategy or global_local_strategy
137template <typename StructureGraph, typename Strategy>
138vertex_set attr_default_generic(const StructureGraph& G, vertex_set A, std::size_t alpha, Strategy tau)
139{
140 deque_vertex_set todo = exclusive_predecessors(G, A);
141
142 while (!todo.is_empty())
143 {
144 // N.B. Use a breadth first search, to minimize counter examples
145 auto u = todo.pop_front();
146
147 if (G.decoration(u) == alpha || includes_successors(G, u, A))
148 {
149 tau.set_strategy(u, find_successor_in(G, u, A));
150 A.insert(u);
151 insert_predecessors(G, u, A, todo);
152 }
153 }
154
155 return A;
156}
157
158// Computes an attractor set, by extending A.
159// alpha = 0: disjunctive
160// alpha = 1: conjunctive
161// StructureGraph is either structure_graph or simple_structure_graph
162template <typename StructureGraph>
163vertex_set attr_default(const StructureGraph& G, vertex_set A, std::size_t alpha)
164{
165 return attr_default_generic(G, A, alpha, global_strategy<StructureGraph>(G));
166}
167
168// Variant of attr_default that does not set any strategies.
169template <typename StructureGraph>
170vertex_set attr_default_no_strategy(const StructureGraph& G, vertex_set A, std::size_t alpha)
171{
172 return attr_default_generic(G, A, alpha, no_strategy());
173}
174
175// Computes an attractor set, by extending A.
176// alpha = 0: disjunctive
177// alpha = 1: conjunctive
178// StructureGraph is either structure_graph or simple_structure_graph
179template <typename StructureGraph>
180vertex_set attr_default_with_tau(const StructureGraph& G, vertex_set A, std::size_t alpha, std::array<strategy_vector, 2>& tau)
181{
182 return attr_default_generic(G, A, alpha, global_local_strategy<StructureGraph>(G, tau, alpha));
183}
184
185} // namespace mcrl2::pbes_system
186
187
188
189#endif // MCRL2_PBES_PBESSOLVE_ATTRACTORS_H
#define mCRL2log(LEVEL)
mCRL2log(LEVEL) provides the stream used to log.
Definition logger.h:393
constexpr unsigned int undefined_vertex()
deque_vertex_set exclusive_predecessors(const StructureGraph &G, const vertex_set &A)
bool includes_successors(const StructureGraph &G, typename StructureGraph::index_type u, const VertexSet &A)
vertex_set attr_default(const StructureGraph &G, vertex_set A, std::size_t alpha)
vertex_set attr_default_generic(const StructureGraph &G, vertex_set A, std::size_t alpha, Strategy tau)
vertex_set attr_default_no_strategy(const StructureGraph &G, vertex_set A, std::size_t alpha)
void insert_predecessors(const StructureGraph &G, structure_graph::index_type u, const vertex_set &A, deque_vertex_set &todo)
vertex_set attr_default_with_tau(const StructureGraph &G, vertex_set A, std::size_t alpha, std::array< strategy_vector, 2 > &tau)
void insert(structure_graph::index_type u)
structure_graph::index_type pop_front()
global_local_strategy(const StructureGraph &G, std::array< strategy_vector, 2 > &tau, std::size_t alpha)
void set_strategy(structure_graph::index_type u, structure_graph::index_type v)
global_strategy< StructureGraph > global
global_strategy(const StructureGraph &G_)
void set_strategy(structure_graph::index_type u, structure_graph::index_type v)
void set_strategy(structure_graph::index_type u, structure_graph::index_type v)
std::array< strategy_vector, 2 > & tau
local_strategy(std::array< strategy_vector, 2 > &tau_, std::size_t alpha_)
static void set_strategy(structure_graph::index_type, structure_graph::index_type)
void insert(structure_graph::index_type u)
bool contains(structure_graph::index_type u) const