mCRL2
Loading...
Searching...
No Matches
remove.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//
11
12#ifndef MCRL2_LPS_REMOVE_H
13#define MCRL2_LPS_REMOVE_H
14
15#include "mcrl2/lps/replace.h"
16
17namespace mcrl2
18{
19
20namespace lps
21{
22
23namespace detail
24{
25
28{
29 bool operator()(const summand_base& s) const
30 {
31 return s.condition() == data::sort_bool::false_();
32 }
33};
34
39{
41
43 : m_data_spec(data_spec)
44 {}
45
46 bool operator()(const data::sort_expression& s) const
47 {
48 auto const& constructors = m_data_spec.constructors(s);
49 if (constructors.size() != 1)
50 {
51 return false;
52 }
53 return !is_function_sort(constructors.front().sort());
54 }
55};
56
60struct remove_parameters_builder: public data_expression_builder<remove_parameters_builder>
61{
63 using super::enter;
64 using super::leave;
65 using super::apply;
66 using super::update;
67
68 const std::set<data::variable>& to_be_removed;
70
71 remove_parameters_builder(const std::set<data::variable>& to_be_removed_)
72 : to_be_removed(to_be_removed_)
73 {}
74
76 void update(std::set<data::variable>& x)
77 {
78 for (const data::variable& v: to_be_removed)
79 {
80 x.erase(v);
81 }
82 }
83
85 template <class T>
87 {
89
90 std::vector<data::variable> result_vec;
91 for (const data::variable& v: x)
92 {
93 if (!contains(to_be_removed, v))
94 {
95 result_vec.push_back(v);
96 }
97 }
98 result = data::variable_list(result_vec.begin(), result_vec.end());
99 }
100
103 template <class T>
105 {
107 std::vector<data::assignment> a(x.begin(), x.end());
108 a.erase(std::remove_if(a.begin(), a.end(), [&](const data::assignment& y) { return contains(to_be_removed, y.lhs()); }), a.end());
109 result = data::assignment_list(a.begin(), a.end());
110 }
111
115 {
116 super::update(x);
117 data::variable_list parameters;
118 apply(parameters, x.process_parameters());
119 x.process_parameters() = parameters;
120 }
121
125 {
126 super::update(x);
127 data::variable_list parameters;
128 apply(parameters, x.process_parameters());
129 x.process_parameters() = parameters;
130 }
131
134 {
136
137 assert(e.size() == process_parameters.size());
138 std::vector<data::data_expression> result;
139 auto pi = process_parameters.begin();
140 auto ei = e.begin();
141 for (; pi != process_parameters.end(); ++pi, ++ei)
142 {
143 if (!contains(to_be_removed, *pi))
144 {
145 result.push_back(*ei);
146 }
147 }
148 return data::data_expression_list(result.begin(), result.end());
149 }
150
151 template <class T>
152 void apply(T& result, const process_initializer& x)
153 {
154 auto expressions = remove_expressions(x.expressions());
155 result = process_initializer(expressions);
156 }
157
158 template <class T>
159 void apply(T& result, const stochastic_process_initializer& x)
160 {
161 auto expressions = remove_expressions(x.expressions());
162 lps::stochastic_distribution distribution;
163 super::apply(distribution, x.distribution());
164 result = stochastic_process_initializer(expressions, distribution);
165 }
166
170 {
172 super::update(x);
174 }
175
179 {
181 super::update(x);
183 }
184};
185
186} // namespace detail
187
189template <typename Object>
190void remove_parameters(Object& x, const std::set<data::variable>& to_be_removed)
191{
192 detail::remove_parameters_builder f(to_be_removed);
193 f.update(x);
194}
195
198template <typename Specification>
199void remove_trivial_summands(Specification& spec)
200{
201 auto& v = spec.process().action_summands();
202 v.erase(std::remove_if(v.begin(), v.end(), lps::detail::is_trivial_summand()), v.end());
203
204 deadlock_summand_vector& w = spec.process().deadlock_summands();
205 w.erase(std::remove_if(w.begin(), w.end(), lps::detail::is_trivial_summand()), w.end());
206}
207
210template <typename Specification>
211void remove_singleton_sorts(Specification& spec)
212{
214 std::set<data::variable> to_be_removed;
215 for (const data::variable& v: spec.process().process_parameters())
216 {
217 if (lps::detail::is_singleton_sort(spec.data())(v.sort()))
218 {
219 sigma[v] = *spec.data().constructors(v.sort()).begin();
220 to_be_removed.insert(v);
221 }
222 }
223 lps::replace_variables(spec, sigma);
224 lps::remove_parameters(spec, to_be_removed);
225}
226
228inline
230{
232
233 std::vector<data::assignment> result;
234 for (const data::assignment& a: assignments)
235 {
236 if (a.lhs() != a.rhs() || contains(do_not_remove, a.lhs()))
237 {
238 result.push_back(a);
239 }
240 }
241 return data::assignment_list(result.begin(), result.end());
242}
243
246template <typename Specification>
247void remove_redundant_assignments(Specification& lpsspec)
248{
249 auto& summands = lpsspec.process().action_summands();
250 for (auto i = summands.begin(); i != summands.end(); ++i)
251 {
252 i->assignments() = remove_redundant_assignments(i->assignments(), i->summation_variables());
253 }
254}
255
256} // namespace lps
257
258} // namespace mcrl2
259
260#endif // MCRL2_LPS_REMOVE_H
size_type size() const
Returns the size of the term_list.
Definition aterm_list.h:256
const_iterator end() const
Returns a const_iterator pointing to the end of the term_list.
Definition aterm_list.h:282
const_iterator begin() const
Returns a const_iterator pointing to the beginning of the term_list.
Definition aterm_list.h:275
\brief Assignment of a data expression to a variable
Definition assignment.h:91
const function_symbol_vector & constructors() const
Gets all constructors including those that are system defined.
Generic substitution function. The substitution is stored as a mapping of variables to expressions....
\brief A sort expression
\brief A data variable
Definition variable.h:28
const data::variable_list & process_parameters() const
Returns the sequence of process parameters.
data::data_expression_list expressions() const
const std::set< data::variable > & global_variables() const
Returns the declared free variables of the LPS.
const LinearProcess & process() const
Returns the linear process of the specification.
Linear process specification.
\brief A stochastic distribution
const stochastic_distribution & distribution() const
Base class for LPS summands.
Definition summand.h:25
const data::data_expression & condition() const
Returns the condition expression.
Definition summand.h:60
static RewriterCompilingJitty::substitution_type & sigma(RewriterCompilingJitty *this_rewriter)
add your file description here.
const function_symbol & false_()
Constructor for function symbol false.
Definition bool.h:109
atermpp::term_list< data_expression > data_expression_list
\brief list of data_expressions
atermpp::term_list< variable > variable_list
\brief list of variables
bool is_function_sort(const atermpp::aterm &x)
Returns true if the term t is a function sort.
atermpp::term_list< assignment > assignment_list
\brief list of assignments
Definition assignment.h:146
std::vector< deadlock_summand > deadlock_summand_vector
\brief vector of deadlock_summands
void remove_parameters(Object &x, const std::set< data::variable > &to_be_removed)
Rewrites an LPS data type.
Definition remove.h:190
void remove_singleton_sorts(Specification &spec)
Removes parameters with a singleton sort from a linear process specification.
Definition remove.h:211
data::assignment_list remove_redundant_assignments(const data::assignment_list &assignments, const data::variable_list &do_not_remove)
Removes assignments of the form x := x from v for variables x that are not contained in do_not_remove...
Definition remove.h:229
void remove_trivial_summands(Specification &spec)
Removes summands with condition equal to false from a linear process specification.
Definition remove.h:199
bool contains(const atermpp::indexed_set< Key, ThreadSafe, Hash, Equals, Allocator, KeyTable > &c, const typename atermpp::indexed_set< Key, ThreadSafe, Hash, Equals, Allocator, KeyTable >::key_type &v, const std::size_t thread_index=0)
Definition indexed_set.h:86
A class that takes a linear process specification and checks all tau-summands of that LPS for conflue...
Definition indexed_set.h:72
void apply(T &result, const data::variable &x)
Definition builder.h:443
Function object that checks if a sort is a singleton sort. Note that it is an approximation,...
Definition remove.h:39
is_singleton_sort(const data::data_specification &data_spec)
Definition remove.h:42
bool operator()(const data::sort_expression &s) const
Definition remove.h:46
const data::data_specification & m_data_spec
Definition remove.h:40
Function object that checks if a summand has a false condition.
Definition remove.h:28
bool operator()(const summand_base &s) const
Definition remove.h:29
Traverser for removing parameters from LPS data types. These parameters can be either process paramet...
Definition remove.h:61
void apply(atermpp::term_list< T > &result, const data::assignment_list &x)
Removes parameters from a list of assignments. Assignments to removed parameters are removed.
Definition remove.h:104
void apply(T &result, const stochastic_process_initializer &x)
Definition remove.h:159
void apply(T &result, const process_initializer &x)
Definition remove.h:152
void update(std::set< data::variable > &x)
Removes parameters from a set container.
Definition remove.h:76
const std::set< data::variable > & to_be_removed
Definition remove.h:68
void apply(atermpp::term_list< T > &result, const data::variable_list &x)
Removes parameters from a list of variables.
Definition remove.h:86
void update(linear_process &x)
Removes parameters from a linear_process.
Definition remove.h:114
data_expression_builder< remove_parameters_builder > super
Definition remove.h:62
data::data_expression_list remove_expressions(const data::data_expression_list &e)
Removes expressions from e at the corresponding positions of process_parameters.
Definition remove.h:133
void update(stochastic_specification &x)
Removes parameters from a linear process specification.
Definition remove.h:178
void update(specification &x)
Removes parameters from a linear process specification.
Definition remove.h:169
remove_parameters_builder(const std::set< data::variable > &to_be_removed_)
Definition remove.h:71
void update(stochastic_linear_process &x)
Removes parameters from a linear_process.
Definition remove.h:124