12#ifndef MCRL2_PBES_DETAIL_STATEGRAPH_LOCAL_RESET_VARIABLES_H
13#define MCRL2_PBES_DETAIL_STATEGRAPH_LOCAL_RESET_VARIABLES_H
15#include "mcrl2/pbes/detail/stategraph_local_algorithm.h"
16#include "mcrl2/pbes/detail/stategraph_reset_variables.h"
20template <
typename Container>
23 std::ostringstream os;
24 for (
auto i = v.begin(); i != v.end(); ++i)
57 auto const& Xinit = m_pbes.initial_state();
58 if (X == Xinit.name())
60 return nth_element(Xinit.parameters(), j);
70 m_occurring_data_parameters.clear();
73 for (
auto& G: m_local_control_flow_graphs)
75 auto const& V = G.vertices;
76 for (
const auto& u: V)
78 auto const& X = u.name();
80 m_occurring_data_parameters[X].insert(p);
85 for (
auto& i: m_occurring_data_parameters)
87 auto const& X = i.first;
88 auto const& eq_X = *find_equation(m_pbes, X);
89 auto const& dp_X = eq_X.data_parameter_indices();
90 i.second = utilities::detail::set_intersection(i.second, std::set<std::size_t>(dp_X.begin(), dp_X.end()));
105 data::data_expression_list e = reset_variable_parameters(x, eq_X, i);
106 return propositional_variable_instantiation(Ye.name(), e);
112 mCRL2log(log::log_level_t::debug) <<
"=== resetting variables to the original PBES ---" << std::endl;
115 std::vector<pbes_equation>& p_eqn = p.equations();
116 const std::vector<stategraph_equation>& s_eqn = m_pbes.equations();
118 for (std::size_t k = 0; k < p_eqn.size(); k++)
120 mCRL2log(log::log_level_t::trace) <<
"--- resetting equation " << p_eqn[k] << std::endl;
121 p_eqn[k].formula() = local_reset_variables(*
this, p_eqn[k].formula(), s_eqn[k]);
134 m_transformed_pbes = m_original_pbes;
136 start_timer(
"reset_variables_to_original");
137 reset_variables_to_original(m_transformed_pbes);
138 finish_timer(
"reset_variables_to_original");
143 return m_transformed_pbes;
169 mCRL2log(log::log_level_t::trace) <<
"<push>" <<
"\n" << x << std::endl;
170 expression_stack.push_back(x);
175 return expression_stack.back();
180 return expression_stack.back();
186 expression_stack.pop_back();
192 push(atermpp::down_cast<pbes_expression>(x));
198 mCRL2log(log::log_level_t::trace) <<
"reset variable " << x <<
" with index " << i <<
" to " << result << std::endl;
259 assert(i < eq_X.predicate_variables().size());
263 const core::identifier_string& X = eq_X.variable().name();
267 std::vector<data::data_expression> e1(e.begin(), e.end());
268 const std::vector<data::variable>& d_Y = eq_Y.parameters();
269 assert(d_Y.size() == Ye.parameters().size());
270 const std::size_t J = m_local_control_flow_graphs.size();
272 auto const& dp_Y = eq_Y.data_parameter_indices();
273 for (std::size_t k: dp_Y)
275 bool relevant =
true;
276 std::set<data::data_expression> condition;
277 for (std::size_t j = 0; j < J; j++)
279 auto const& Vj = m_local_control_flow_graphs[j];
280 auto& Bj = m_belongs[j];
281 default_rules_predicate rules(Vj);
284 auto const& v = Vj.find_vertex(Y);
285 std::size_t p = v.index();
286 auto di = Ye.target().find(p);
287 if (di != Ye.target().end())
289 auto const& q1 = di->second;
290 auto const& u = Vj.find_vertex(local_control_flow_graph_vertex(Y, p, data::undefined_variable(), q1));
291 if (contains(Bj[Y], d_Y[k]) && !contains(u.marking(), d_Y[k]))
297 else if(!v.has_variable())
299 if (contains(Bj[Y], d_Y[k]) && !contains(v.marking(), d_Y[k]))
308 if (contains(Bj[Y], d_Y[k]))
311 for (
const auto& w: Vj.vertices)
313 if (w.name() == Y && w.index() == p)
315 if (contains(w.marking(), d_Y[k]))
321 if (w.has_variable())
323 auto const& r = w.value();
324 condition.insert(data::equal_to(nth_element(e, p), r));
340 e1[k] = default_value(Y, k, e1[k].sort());
344 if (!condition.empty())
346 e1[k] = data::if_(data::lazy::join_or(condition.begin(), condition.end()), default_value(Y, k, e1[k].sort()), nth_element(e, k));
347 mCRL2log(log::log_level_t::trace) <<
" reset copy Y = " << Y <<
" k = " << k <<
" e'[k] = " << e1[k] << std::endl;
351 return data::data_expression_list(e1.begin(), e1.end());
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.
\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.
void execute_postprocessing() override
const pbes & result() const
void reset_variables_to_original(pbes &p)
local_reset_variables_algorithm(const pbes &p, const pbesstategraph_options &options)
data::data_expression default_value(const core::identifier_string &X, std::size_t j, const data::sort_expression &x)
void compute_occurring_data_parameters()
pbes_expression reset_variable(const propositional_variable_instantiation &x, const stategraph_equation &eq_X, std::size_t i)
data::data_expression_list reset_variable_parameters(const propositional_variable_instantiation &x, const stategraph_equation &eq_X, std::size_t i)
const pbes m_original_pbes
const propositional_variable_instantiation & variable() const
const core::identifier_string & name() const
Algorithm class for the local variant of the stategraph algorithm.
stategraph_local_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 data::data_expression_list & parameters() const
#define mCRL2log(LEVEL)
mCRL2log(LEVEL) provides the stream used to log.
std::string print_vector(const Container &v, const std::string &delim)
pbes_expression local_reset_variables(local_reset_variables_algorithm &algorithm, const pbes_expression &x, const stategraph_equation &eq_X)
N.B. It is essential that this traverser uses the same traversal order as the guard_traverser.
local_reset_variables_algorithm & algorithm
void leave(const pbes_system::propositional_variable_instantiation &x)
void leave(const data::data_expression &x)
void leave(const pbes_system::imp &)
const pbes_expression & top() const
void leave(const pbes_system::not_ &)
void leave(const pbes_system::forall &x)
local_reset_traverser(local_reset_variables_algorithm &algorithm_, const stategraph_equation &eq_X_, std::size_t &i_)
void push(const pbes_expression &x)
std::vector< pbes_expression > expression_stack
const stategraph_equation & eq_X
void leave(const pbes_system::and_ &)
void leave(const pbes_system::or_ &)
void leave(const pbes_system::exists &x)