mCRL2
Loading...
Searching...
No Matches
remove_parameters.h
Go to the documentation of this file.
1// Author(s): Wieger Wesselink
2// Copyright: see the accompanying file COPYING.
3//
4// Distributed under the Boost Software License, Version 1.0.
5// (See accompanying file LICENSE_1_0.txt or copy at
6// http://www.boost.org/LICENSE_1_0.txt)
7//
10
11#ifndef MCRL2_PBES_REMOVE_PARAMETERS_H
12#define MCRL2_PBES_REMOVE_PARAMETERS_H
13
14#include "mcrl2/pbes/builder.h"
15
16namespace mcrl2
17{
18
19namespace pbes_system
20{
21
23namespace detail
24{
25
30template <typename Term>
31atermpp::term_list<Term> remove_elements(const atermpp::term_list<Term>& l, const std::vector<std::size_t>& to_be_removed)
32{
33 assert(std::is_sorted(to_be_removed.begin(), to_be_removed.end()));
34 std::size_t index = 0;
35 std::vector<Term> result;
36 auto j = to_be_removed.begin();
37 for (auto i = l.begin(); i != l.end(); ++i, ++index)
38 {
39 if (j != to_be_removed.end() && index == *j)
40 {
41 ++j;
42 }
43 else
44 {
45 result.push_back(*i);
46 }
47 }
48 return atermpp::term_list<Term>(result.begin(),result.end());
49}
50
51template <typename Derived>
52struct remove_parameters_builder: public pbes_system::pbes_expression_builder<Derived>
53{
54 typedef pbes_system::pbes_expression_builder<Derived> super;
55 using super::enter;
56 using super::leave;
57 using super::update;
58 using super::apply;
59
60 const std::vector<std::size_t>& to_be_removed;
61
62 remove_parameters_builder(const std::vector<std::size_t>& to_be_removed_)
63 : to_be_removed(to_be_removed_)
64 {}
65
66 template <class T>
67 void apply(T& result, const propositional_variable& x)
68 {
69 make_propositional_variable(result, x.name(), detail::remove_elements(x.parameters(), to_be_removed));
70 }
71
72 template <class T>
73 void apply(T& result, const propositional_variable_instantiation& x)
74 {
75 make_propositional_variable_instantiation(result, x.name(), detail::remove_elements(x.parameters(), to_be_removed));
76 }
77
78 void update(pbes_equation& x)
79 {
81 static_cast<Derived&>(*this).apply(variable, x.variable());
82 x.variable() = variable;
83 pbes_expression formula;
84 static_cast<Derived&>(*this).apply(formula, x.formula());
85 x.formula() = formula;
86 }
87
88 void update(pbes& x)
89 {
90 static_cast<Derived&>(*this).update(x.equations());
91 propositional_variable_instantiation initial_state;
92 static_cast<Derived&>(*this).apply(initial_state, x.initial_state());
93 x.initial_state() = initial_state;
94 static_cast<Derived&>(*this).update(x.global_variables());
95 }
96};
97
98
99} // namespace detail
101
106template <typename T>
107T remove_parameters(const T& x,
108 const std::vector<std::size_t>& to_be_removed,
109 typename std::enable_if< std::is_base_of< atermpp::aterm, T >::value>::type* = nullptr
110 )
111{
112 T result;
113 core::make_apply_builder_arg1<detail::remove_parameters_builder>(to_be_removed).apply(result, x);
114 return result;
115}
116
121template <typename T>
123 const std::vector<std::size_t>& to_be_removed,
124 typename std::enable_if< !std::is_base_of< atermpp::aterm, T >::value>::type* = 0
125 )
126{
127 core::make_apply_builder_arg1<detail::remove_parameters_builder>(to_be_removed).update(x);
128}
129
131namespace detail
132{
133
134template <typename Derived>
135struct map_based_remove_parameters_builder: public pbes_expression_builder<Derived>
136{
137 typedef pbes_expression_builder<Derived> super;
138 using super::enter;
139 using super::leave;
140 using super::update;
141 using super::apply;
142
143 const std::map<core::identifier_string, std::vector<std::size_t> >& to_be_removed;
144
145 map_based_remove_parameters_builder(const std::map<core::identifier_string, std::vector<std::size_t> >& to_be_removed_)
146 : to_be_removed(to_be_removed_)
147 {}
148
149 // to prevent default operator() being called
150 template <class T>
151 void apply(T& result, const data::data_expression& x)
152 {
153 result = x;
154 }
155
156 template <class T>
157 void apply(T& result, const propositional_variable& x)
158 {
159 auto i = to_be_removed.find(x.name());
160 if (i == to_be_removed.end())
161 {
162 result = x;
163 return;
164 }
165 result = remove_parameters(x, i->second);
166 }
167
168 template <class T>
169 void apply(T& result, const propositional_variable_instantiation& x)
170 {
171 auto i = to_be_removed.find(x.name());
172 if (i == to_be_removed.end())
173 {
174 result = x;
175 }
176 else
177 {
178 result = remove_parameters(x, i->second);
179 }
180 }
181
182 void update(pbes_equation& x)
183 {
184 propositional_variable variable;
185 static_cast<Derived&>(*this).apply(variable, x.variable());
186 x.variable() = variable;
187 pbes_expression formula;
188 static_cast<Derived&>(*this).apply(formula, x.formula());
189 x.formula() = formula;
190 }
191
192 void update(pbes& x)
193 {
194 static_cast<Derived&>(*this).update(x.equations());
195 propositional_variable_instantiation initial_state;
196 static_cast<Derived&>(*this).apply(initial_state, x.initial_state());
197 x.initial_state() = initial_state;
198 }
199};
200} // namespace detail
202
207template <typename T>
208T remove_parameters(const T& x,
209 const std::map<core::identifier_string, std::vector<std::size_t> >& to_be_removed,
210 typename std::enable_if< std::is_base_of< atermpp::aterm, T >::value>::type* = nullptr
211 )
212{
213 T result;
214 core::make_apply_builder_arg1<detail::map_based_remove_parameters_builder>(to_be_removed).apply(result, x);
215 return result;
216}
217
223template <typename T>
225 const std::map<core::identifier_string, std::vector<std::size_t> >& to_be_removed,
226 typename std::enable_if< !std::is_base_of< atermpp::aterm, T >::value>::type* = nullptr
227 )
228{
229 core::make_apply_builder_arg1<detail::map_based_remove_parameters_builder>(to_be_removed).update(x);
230}
231
233namespace detail
234{
235
236template <typename Derived>
237struct set_based_remove_parameters_builder: public pbes_expression_builder<Derived>
238{
239 typedef pbes_expression_builder<Derived> super;
240 using super::enter;
241 using super::leave;
242 using super::update;
243 using super::apply;
244
245 const std::set<data::variable>& to_be_removed;
246
247 set_based_remove_parameters_builder(const std::set<data::variable>& to_be_removed_)
248 : to_be_removed(to_be_removed_)
249 {}
250
251 void remove_parameters(std::set<data::variable>& x) const
252 {
253 for (auto i = to_be_removed.begin(); i != to_be_removed.end(); ++i)
254 {
255 x.erase(*i);
256 }
257 }
258
259 void apply_(data::variable_list& result, const data::variable_list& l) const
260 {
261 using utilities::detail::contains;
262
263 std::vector<data::variable> result_vec;
264 for (const data::variable& v: l)
265 {
266 if (!contains(to_be_removed, v))
267 {
268 result_vec.push_back(v);
269 }
270 }
271 result = data::variable_list(result_vec.begin(), result_vec.end());
272 }
273
274 template <class T>
275 void apply(T& result, const data::assignment_list& l) const
276 {
277 using utilities::detail::contains;
278 std::vector<data::assignment> a(l.begin(), l.end());
279 a.erase(std::remove_if(a.begin(), a.end(), [&](const data::assignment& y) { return contains(to_be_removed, y.lhs()); }), a.end());
280 result = data::assignment_list(a.begin(), a.end());
281 }
282
283 template <class T>
284 void apply(T& result, const propositional_variable& x)
285 {
286 data::variable_list vars;
287 static_cast<Derived&>(*this).apply_(vars, x.parameters()); // Underscore is nasty trick to select the correct apply.
288 make_propositional_variable(result, x.name(), vars);
289 }
290
291 void update(pbes_equation& x)
292 {
293 propositional_variable variable;
294 static_cast<Derived&>(*this).apply(variable, x.variable());
295 x.variable() = variable;
296 pbes_expression formula;
297 static_cast<Derived&>(*this).apply(formula, x.formula());
298 x.formula() = formula;
299 }
300
301 void update(pbes& x)
302 {
303 static_cast<Derived&>(*this).update(x.equations());
304 propositional_variable_instantiation initial_state;
305 static_cast<Derived&>(*this).apply(initial_state, x.initial_state());
306 x.initial_state() = initial_state;
307 remove_parameters(x.global_variables());
308 }
309};
310} // namespace detail
312
317template <typename T>
318T remove_parameters(const T& x,
319 const std::set<data::variable>& to_be_removed,
320 typename std::enable_if< std::is_base_of< atermpp::aterm, T >::value>::type* = 0
321 )
322{
323 T result;
324 core::make_apply_builder_arg1<detail::set_based_remove_parameters_builder>(to_be_removed).apply(result, x);
325 return result;
326}
327
332template <typename T>
334 const std::set<data::variable>& to_be_removed,
335 typename std::enable_if< !std::is_base_of< atermpp::aterm, T >::value>::type* = nullptr
336 )
337{
338 core::make_apply_builder_arg1<detail::set_based_remove_parameters_builder>(to_be_removed).update(x);
339}
340
341
343// used in pbes.h
344inline
345void remove_pbes_parameters(pbes& x,
346 const std::set<data::variable>& to_be_removed
347 )
348{
349 remove_parameters(x, to_be_removed);
350}
352
353} // namespace pbes_system
354
355} // namespace mcrl2
356
357#endif // MCRL2_PBES_REMOVE_PARAMETERS_H
Term containing a string.
A list of aterm objects.
Definition aterm_list.h:24
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
void remove_parameters(Object &x, const std::set< data::variable > &to_be_removed)
Rewrites an LPS data type.
Definition remove.h:190
T remove_parameters(const T &x, const std::vector< std::size_t > &to_be_removed, typename std::enable_if< std::is_base_of< atermpp::aterm, T >::value >::type *=nullptr)
Removes parameters from propositional variable instantiations in a pbes expression.
void make_propositional_variable(atermpp::aterm &t, const ARGUMENTS &... args)
void make_propositional_variable_instantiation(atermpp::aterm &t, const ARGUMENTS &... args)
pbes_expression formula(std::set< identifier_t > const &v, const owner_t owner, const std::string &prefix="X")
Definition pg_parse.h:54
pbes_system::propositional_variable propositional_variable
The propositional variable is taken from a pbes_system.
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
add your file description here.