mCRL2
Loading...
Searching...
No Matches
bes_algorithm.h
Go to the documentation of this file.
1// Author(s): Jeroen Keiren
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/detail/bes_algorithm.h
10/// \brief Add your file description here.
11
12#ifndef MCRL2_PBES_DETAIL_BES_ALGORITHM_H
13#define MCRL2_PBES_DETAIL_BES_ALGORITHM_H
14
15#include "mcrl2/pbes/find.h"
16#include "mcrl2/pbes/print.h"
17
18namespace mcrl2::pbes_system::detail
19{
20
21/// \brief Algorithm class for algorithms on linear process specifications.
23{
24 protected:
25 /// \brief The specification that is processed by the algorithm
27
28 public:
29 /// \brief Constructor
31 : m_bes(bes)
32 {}
33
34 /// \brief Flag for verbose output
35 bool verbose() const
36 {
37 return mCRL2logEnabled(log::log_level_t::verbose);
38 }
39
40 /// \brief Perform reachability analysis on equations of m_bes, and remove
41 /// those that are unreachable.
43 {
44 std::deque<propositional_variable_instantiation> todo;
45 std::set<propositional_variable_instantiation> reachable;
46
47 // For efficiency reasons, store equation X = phi as mapping X -> X = phi
48 std::map<propositional_variable_instantiation, pbes_equation> equations;
49 for(const pbes_equation& e: m_bes.equations())
50 {
51 equations[propositional_variable_instantiation(e.variable().name())] = e;
52 }
53
54 reachable = find_propositional_variable_instantiations(m_bes.initial_state());
55 todo.insert(todo.end(), reachable.begin(), reachable.end());
56
57 while(!todo.empty())
58 {
59 pbes_equation eqn = equations[todo.front()];
60 todo.pop_front();
61 std::set<propositional_variable_instantiation> occ = find_propositional_variable_instantiations(eqn.formula());
62 for(const propositional_variable_instantiation& v: occ)
63 {
64 bool fresh = reachable.insert(v).second;
65 if(fresh)
66 {
67 todo.push_back(v);
68 }
69 }
70 }
71
72 if(reachable.size() == m_bes.equations().size())
73 {
74 return true;
75 }
76
77 std::vector<pbes_equation> reachable_equations;
78 std::set<propositional_variable> unreachable_equations;
79 for (auto& i: m_bes.equations())
80 {
81 if (reachable.find(propositional_variable_instantiation(i.variable().name())) != reachable.end())
82 {
83 reachable_equations.insert(reachable_equations.end(), i);
84 }
85 else
86 {
87 unreachable_equations.insert(i.variable());
88 }
89 }
90
91 m_bes.equations() = reachable_equations;
92
93 mCRL2log(log::log_level_t::verbose) << "Removed the following unreachable equations: " << pbes_system::pp(unreachable_equations) << std::endl;
94
95 return false;
96 }
97
98};
99
100} // namespace mcrl2::pbes_system::detail
101
102#endif // MCRL2_PBES_DETAIL_BES_ALGORITHM_H
Algorithm class for algorithms on linear process specifications.
bool verbose() const
Flag for verbose output.
pbes & m_bes
The specification that is processed by the algorithm.
bool remove_unreachable_equations()
Perform reachability analysis on equations of m_bes, and remove those that are unreachable.
parameterized boolean equation system
Definition pbes.h:54
#define mCRL2log(LEVEL)
mCRL2log(LEVEL) provides the stream used to log.
Definition logger.h:435