12#ifndef MCRL2_PBES_DETAIL_STATEGRAPH_GLOBAL_RESET_VARIABLES_H
13#define MCRL2_PBES_DETAIL_STATEGRAPH_GLOBAL_RESET_VARIABLES_H
15#include "mcrl2/pbes/detail/stategraph_global_algorithm.h"
16#include "mcrl2/pbes/detail/stategraph_reset_variables.h"
46 auto const& eq_X = *find_equation(m_pbes, X);
47 auto const& d_X = eq_X.parameters();
48 return std::set<data::variable>(d_X.begin(), d_X.end());
51 template <
typename Graph>
56 mCRL2log(log::log_level_t::debug) <<
"--- compute initial marking ---" << std::endl;
59 for (
auto i = G.begin(); i != G.end(); ++i)
62 std::set<data::variable> dx = propvar_parameters(v.name());
63 v.set_marking(utilities::detail::set_intersection(v.sig(), dx));
64 mCRL2log(log::log_level_t::debug) <<
"vertex " << v <<
" sig = " << core::detail::print_set(v.sig()) <<
" dx = " << core::detail::print_set(dx) <<
"\n";
66 mCRL2log(log::log_level_t::debug) <<
"--- initial control flow marking ---\n" << G.print_marking();
69 std::set<
const typename Graph::vertex_type*> todo;
70 for (
auto i = G.begin(); i != G.end(); ++i)
75 mCRL2log(log::log_level_t::debug) <<
"--- update marking ---" << std::endl;
78 auto const& v = *pick_element(todo);
79 mCRL2log(log::log_level_t::debug) <<
"selected marking todo element " << v << std::endl;
80 std::set<std::size_t> I = v.marking_variable_indices(m_pbes);
82 auto const& incoming_edges = v.incoming_edges();
83 for (
auto ei = incoming_edges.begin(); ei != incoming_edges.end(); ++ei)
85 auto const& u = *ei->first;
86 const std::set<std::size_t>& labels = ei->second;
87 for (std::size_t i: labels)
89 std::size_t last_size = u.marking().size();
90 const stategraph_equation& eq_X = *find_equation(m_pbes, u.name());
91 const propositional_variable_instantiation& Y = eq_X.predicate_variables()[i].variable();
92 std::set<data::variable> dx = propvar_parameters(u.name());
93 mCRL2log(log::log_level_t::debug) <<
" vertex u = " << v <<
" label = " << i <<
" I = " << print_set(I) <<
" u.marking = " << core::detail::print_set(u.marking()) << std::endl;
94 for (std::size_t m: I)
96 const data::data_expression_list& e = Y.parameters();
97 const data::data_expression& e_m = nth_element(e, m);
98 std::set<data::variable> fv = data::find_free_variables(e_m);
99 u.set_marking(utilities::detail::set_union(utilities::detail::set_intersection(fv, dx), u.marking()));
100 mCRL2log(log::log_level_t::debug) <<
" m = " << m <<
" freevars = " << core::detail::print_set(fv) <<
" dx = " << core::detail::print_set(dx) <<
"\n";
102 if (u.marking().size() > last_size)
105 mCRL2log(log::log_level_t::debug) <<
"updated marking " << u.print_marking() <<
" using edge " << pbes_system::pp(Y) <<
"\n";
112 for (
auto i = G.begin(); i != G.end(); ++i)
116 for (
const data::variable& w: eqn.parameters())
118 v.add_marked_parameter(v.marking().find(w) != v.marking().end());
124 template <
typename Vertex>
127 std::size_t N = e_X.size();
128 data::data_expression_list::const_iterator k = u.values().begin();
129 for (std::size_t j = 0; j < N; ++j)
131 if (is_global_control_flow_parameter(Y, j))
133 const predicate_variable& X_i = eq_X.predicate_variables()[i];
134 auto target_j = X_i.target().find(j);
135 if (target_j != X_i.target().end())
137 data::data_expression f_k = *k;
138 if(f_k != target_j->second)
155 mCRL2log(log::log_level_t::debug) <<
"--- resetting variable Y(e) = " << pbes_system::pp(x) <<
" with index " << i << std::endl;
156 assert(eq_X.predicate_variables()[i].variable() == x);
158 std::vector<pbes_expression> phi;
160 std::vector<data::data_expression> e(x.parameters().begin(),x.parameters().end());
163 auto inst = m_control_flow_graph.index(Y);
166 mCRL2log(log::log_level_t::verbose) <<
"Equation " << Y <<
" is not reachable!" << std::endl;
171 mCRL2log(log::log_level_t::debug) <<
" vertex u = " << u << std::endl;
173 if(!location_possibly_reachable(Y, u, e, eq_X, i))
179 std::vector<data::data_expression> r;
180 std::size_t N = u.marked_parameters().size();
181 assert(e.size() == u.marked_parameters().size());
182 auto k = u.values().begin();
183 data::data_expression condition = data::true_();
184 for (std::size_t j = 0; j < N; ++j)
186 mCRL2log(log::log_level_t::debug) <<
" j = " << j;
187 if (is_global_control_flow_parameter(Y, j))
189 mCRL2log(log::log_level_t::debug) <<
" CFP(Y, j) = true";
190 const data::data_expression& f_k = *k++;
191 const predicate_variable& X_i = eq_X.predicate_variables()[i];
192 if (X_i.target().find(j) == X_i.target().end() || !m_simplify)
194 condition = data::lazy::and_(condition, data::equal_to(e[j], f_k));
196 mCRL2log(log::log_level_t::debug) <<
" target(X, i, j) = false";
197 mCRL2log(log::log_level_t::debug) <<
" c := c && " << data::pp(data::equal_to(e[j], f_k));
201 r.push_back(X_i.target().find(j)->second);
203 mCRL2log(log::log_level_t::debug) <<
" r := r <| " << data::pp(r.back());
206 else if (u.is_marked_parameter(j))
208 mCRL2log(log::log_level_t::debug) <<
" e[j] is in marking(u)";
209 mCRL2log(log::log_level_t::debug) <<
" r := r <| " << data::pp(e[j]);
214 mCRL2log(log::log_level_t::debug) <<
" default parameter ";
215 mCRL2log(log::log_level_t::debug) <<
" r := r <| " << data::pp(default_value(e[j].sort()));
216 r.push_back(default_value(e[j].sort()));
218 mCRL2log(log::log_level_t::debug) << std::endl;
220 propositional_variable_instantiation Yr(Y, data::data_expression_list(r.begin(),r.end()));
223 condition = m_datar(condition);
224 if (condition != data::false_())
226 phi.push_back(imp(atermpp::down_cast<pbes_expression>(condition), Yr));
231 phi.push_back(imp(atermpp::down_cast<pbes_expression>(condition), Yr));
234 return join_and(phi.begin(), phi.end());
240 mCRL2log(log::log_level_t::debug) <<
"--- resetting variables to the original PBES ---" << std::endl;
243 std::vector<pbes_equation>& p_eqn = p.equations();
244 const std::vector<stategraph_equation>& s_eqn = m_pbes.equations();
246 for (std::size_t k = 0; k < p_eqn.size(); k++)
249 p_eqn[k].formula() = reset_variables(*
this, p_eqn[k].formula(), s_eqn[k]);
256 pbes_system::pbes_rewrite(p, pbesr);
268 start_timer(
"compute_global_control_flow_marking");
269 compute_global_control_flow_marking(m_control_flow_graph);
270 finish_timer(
"compute_global_control_flow_marking");
271 mCRL2log(log::log_level_t::verbose) <<
"Computed control flow marking" << std::endl;
272 mCRL2log(log::log_level_t::debug) <<
"--- control flow marking ---\n" << m_control_flow_graph.print_marking();
273 m_transformed_pbes = m_original_pbes;
274 reset_variables_to_original(m_transformed_pbes);
279 return m_transformed_pbes;
306 mCRL2log(log::log_level_t::trace) <<
"<push>" <<
"\n" << x << std::endl;
307 expression_stack.push_back(x);
312 return expression_stack.back();
317 return expression_stack.back();
323 expression_stack.pop_back();
329 push(atermpp::down_cast<pbes_expression>(x));
335 mCRL2log(log::log_level_t::debug) <<
"reset variable " << pbes_system::pp(x) <<
" with index " << i <<
" to " << pbes_system::pp(result) << std::endl;
aterm(const aterm &other) noexcept=default
This class has user-declared copy constructor so declare default copy and move operators.
A unordered_map class in which aterms can be stored.
Components for generating an arbitrary element of a sort.
data_expression operator()(const sort_expression &sort)
Returns a representative of a sort.
Rewriter that operates on data expressions.
\brief The and operator for pbes expressions
and_(const pbes_expression &left, const pbes_expression &right)
\brief Constructor Z14.
Adds the reset variables procedure to the stategraph algorithm.
global_reset_variables_algorithm(const pbes &p, const pbesstategraph_options &options)
pbes_expression reset_variable(const propositional_variable_instantiation &x, const stategraph_equation &eq_X, std::size_t i)
bool location_possibly_reachable(const core::identifier_string &Y, const Vertex &u, const std::vector< data::data_expression > &e_X, const stategraph_equation &eq_X, std::size_t i)
std::set< data::variable > propvar_parameters(const core::identifier_string &X) const
void compute_global_control_flow_marking(Graph &G)
void execute_core() override
void reset_variables_to_original(pbes &p)
const pbes & result() const
data::data_expression default_value(const data::sort_expression &x)
const pbes & m_original_pbes
Algorithm class for the global variant of the stategraph algorithm.
stategraph_global_algorithm(const pbes &p, const pbesstategraph_options &options)
\brief The existential quantification operator for pbes expressions
exists(const data::variable_list &variables, const pbes_expression &body)
\brief Constructor Z14.
const data::variable_list & variables() const
\brief The universal quantification operator for pbes expressions
forall(const data::variable_list &variables, const pbes_expression &body)
\brief Constructor Z14.
const data::variable_list & variables() const
\brief The implication operator for pbes expressions
imp(const pbes_expression &left, const pbes_expression &right)
\brief Constructor Z14.
\brief The not operator for pbes expressions
not_(const atermpp::aterm &term)
\brief The or operator for pbes expressions
or_(const pbes_expression &left, const pbes_expression &right)
\brief Constructor Z14.
parameterized boolean equation system
\brief A propositional variable instantiation
const core::identifier_string & name() const
#define mCRL2log(LEVEL)
mCRL2log(LEVEL) provides the stream used to log.
pbes_expression reset_variables(global_reset_variables_algorithm &algorithm, const pbes_expression &x, const stategraph_equation &eq_X)
reset propositional variables N.B. It is essential that this traverser uses the same traversal order ...
void leave(const pbes_system::propositional_variable_instantiation &x)
const stategraph_equation & eq_X
reset_traverser(global_reset_variables_algorithm &algorithm_, const stategraph_equation &eq_X_, std::size_t &i_)
const pbes_expression & top() const
void leave(const pbes_system::not_ &)
void leave(const pbes_system::imp &)
void leave(const data::data_expression &x)
void leave(const pbes_system::and_ &)
std::vector< pbes_expression > expression_stack
void leave(const pbes_system::or_ &)
global_reset_variables_algorithm & algorithm
void push(const pbes_expression &x)
void leave(const pbes_system::forall &x)
void leave(const pbes_system::exists &x)
A rewriter that simplifies boolean expressions in a term, and rewrites data expressions using DataRew...