mCRL2
Loading...
Searching...
No Matches
gauss_elimination_algorithm.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/gauss_elimination_algorithm.h
10/// \brief Gauss elimination algorithm for pbes equation systems.
11
12#ifndef MCRL2_PBES_GAUSS_ELIMINATION_ALGORITHM_H
13#define MCRL2_PBES_GAUSS_ELIMINATION_ALGORITHM_H
14
15#include "mcrl2/pbes/replace.h"
16
17namespace mcrl2::pbes_system
18{
19
20/// \brief Algorithm class for the Gauss elimination algorithm for solving
21/// systems of (P)BES equations.
22
23template <typename ExpressionTraits>
25{
26 public:
27 using expression_type = typename ExpressionTraits::expression_type;
28 using variable_type = typename ExpressionTraits::variable_type;
29 using equation_type = typename ExpressionTraits::equation_type;
30
31 protected:
32
34 {
35 return ExpressionTraits::print(eq);
36 }
37
38 template <typename Iter>
40 {
41 std::ostringstream out;
42 for (Iter i = first; i != last; ++i)
43 {
44 out << " " << print_equation(*i) << std::endl;
45 }
46 return out.str();
47 }
48
49 public:
50 /// \brief Runs the algorithm. Applies Gauss elimination to the sequence of pbes equations [first, last).
51 /// \param first Start of a range of pbes equations
52 /// \param last End of a range of pbes equations
53 /// \param solve An equation solver
54
55 template <typename Iter, typename FixpointEquationSolver>
56 void run(Iter first, Iter last, FixpointEquationSolver solve)
57 {
58 mCRL2log(log::debug) << "equations before solving\n" << print_equations(first, last);
59 if (first == last)
60 {
61 return;
62 }
63
64 Iter i = last;
65 while (i != first)
66 {
67 --i;
68 mCRL2log(log::verbose) << "solving equation\n before: " << print_equation(*i);
69 solve(*i);
70 mCRL2log(log::verbose) << " after: " << print_equation(*i) << "\n";
71 for (Iter j = first; j != i; ++j)
72 {
73 j->formula() = ExpressionTraits::substitute(j->formula(), i->variable(), i->formula());
74 }
75 mCRL2log(log::trace) << "equations after substitution\n" << print_equations(first, last);
76 }
77 mCRL2log(log::debug) << "equations after solving\n" << print_equations(first, last);
78 }
79};
80
81/// \brief Approximation algorithm
82
83template <typename BooleanExpressionTraits, typename Compare>
85{
86 Compare m_compare;
87
88 approximate(Compare compare)
89 : m_compare(compare)
90 {
91 }
92
93 void operator()(typename BooleanExpressionTraits::equation_type& eq) const
94 {
95 using tr = BooleanExpressionTraits;
96 using expression_type = typename BooleanExpressionTraits::expression_type;
97 using variable_type = typename BooleanExpressionTraits::variable_type;
98
99 const expression_type& phi = eq.formula();
100 const variable_type& X = eq.variable();
101 expression_type next = eq.symbol() == tr::nu() ? tr::true_() : tr::false_();
102 expression_type prev;
103 do
104 {
105 prev = next;
106 next = tr::substitute(phi, X, prev);
107 }
108 while (!m_compare(prev, next));
109 eq.formula() = prev;
110 }
111};
112
113} // namespace mcrl2::pbes_system
114
115#endif // MCRL2_PBES_GAUSS_ELIMINATION_ALGORITHM_H
Algorithm class for the Gauss elimination algorithm for solving systems of (P)BES equations.
void run(Iter first, Iter last, FixpointEquationSolver solve)
Runs the algorithm. Applies Gauss elimination to the sequence of pbes equations [first,...
std::string print_equation(const equation_type &eq) const
std::string print_equations(Iter first, Iter last) const
#define mCRL2log(LEVEL)
mCRL2log(LEVEL) provides the stream used to log.
Definition logger.h:393
void operator()(typename BooleanExpressionTraits::equation_type &eq) const