mCRL2
Loading...
Searching...
No Matches
allow_set.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_PROCESS_ALLOW_SET_H
13#define MCRL2_PROCESS_ALLOW_SET_H
14
17
18namespace mcrl2 {
19
20namespace process {
21
22struct allow_set;
23std::ostream& operator<<(std::ostream& out, const allow_set& x);
24
29{
32 std::set<core::identifier_string> I;
33
34 bool is_empty() const
35 {
36 return A.empty() && I.empty();
37 }
38
40 {
41 if (!A.empty())
42 {
43 return *A.begin();
44 }
45 if (!I.empty())
46 {
48 alpha.insert(*I.begin());
49 return alpha;
50 }
51 throw mcrl2::runtime_error("cannot pick element from empty allow_set!");
52 }
53
55 {
57 for (const multi_action_name& i : A)
58 {
59 A1.insert(alphabet_operations::hide(I, i));
60 }
61 std::swap(A, A1);
62 assert(check_invariant());
63 }
64
65 bool check_invariant() const
66 {
68 if (I.empty())
69 {
70 return true;
71 }
72 for (const multi_action_name& alpha: A)
73 {
74 for (const core::identifier_string& j: alpha)
75 {
76 if (contains(I, j))
77 {
78 return false;
79 }
80 }
81 }
82 return true;
83 }
84
86 {}
87
88 explicit allow_set(const multi_action_name_set& A_, bool A_includes_subsets_ = false, const std::set<core::identifier_string>& I_ = std::set<core::identifier_string>())
89 : A_includes_subsets(A_includes_subsets_), I(I_)
90 {
91 for (const multi_action_name& i: A_)
92 {
93 A.insert(alphabet_operations::hide(I_, i));
94 }
95 }
96
98 bool contains(const multi_action_name& alpha) const
99 {
101 return beta.empty() || (A_includes_subsets ? alphabet_operations::includes(A, beta) : alphabet_operations::contains(A, beta));
102 }
103
106 {
108 for (const multi_action_name& alpha: alphabet)
109 {
110 if (contains(alpha))
111 {
112 result.insert(alpha);
113 }
114 }
116 if (alphabet.find(tau) != alphabet.end())
117 {
118 result.insert(tau);
119 }
120 return result;
121 }
122
123 bool operator==(const allow_set& other) const
124 {
125 return A == other.A && A_includes_subsets == other.A_includes_subsets && I == other.I;
126 }
127
128 bool operator<(const allow_set& other) const
129 {
131 {
133 }
134 if (A.size() != other.A.size())
135 {
136 return A.size() < other.A.size();
137 }
138 if (I.size() != other.I.size())
139 {
140 return I.size() < other.I.size();
141 }
142 auto m = std::mismatch(A.begin(), A.end(), other.A.begin());
143 if (m.first != A.end())
144 {
145 return *m.first < *m.second;
146 }
147 return I < other.I;
148 }
149};
150
151inline
152std::ostream& operator<<(std::ostream& out, const allow_set& x)
153{
154 if (!x.A.empty())
155 {
156 out << pp(x.A) << (x.A_includes_subsets ? "@" : "");
157 }
158 if (!x.I.empty())
159 {
160 out << "{" << core::pp(x.I) << "}*";
161 }
162 if (x.A.empty() && x.I.empty())
163 {
164 out << "{}";
165 }
166 return out;
167}
168
169// operations on allow_set
170
171namespace alphabet_operations {
172
173// Returns true if there is a beta in A that includes alpha
174inline
175bool subset_includes(const allow_set& A, const multi_action_name& alpha)
176{
178 for (const multi_action_name& beta: A.A)
179 {
180 if (includes(beta, alpha1))
181 {
182 return true;
183 }
184 }
185 return false;
186}
187
188// Returns the intersection of A1 and A
189inline
191{
193 for (const multi_action_name& alpha: A)
194 {
195 if ((A1.A_includes_subsets && subset_includes(A1.A, alpha)) || (!A1.A_includes_subsets && includes(A1.A, alpha)))
196 {
197 result.insert(alpha);
198 }
199 }
200 return result;
201}
202
203// Returns the intersection of concat(A1, A2) and A, and a boolean indicating if the intersection actually removed some elements.
204inline
205std::pair<multi_action_name_set, bool> bounded_concat(const multi_action_name_set& A1, const multi_action_name_set& A2, const allow_set& A)
206{
207 bool removed = false;
209 for (const multi_action_name& i: A1)
210 {
211 for (const multi_action_name& j: A2)
212 {
213 multi_action_name alpha = multiset_union(i, j);
214 if (A.contains(alpha))
215 {
216 result.insert(alpha);
217 }
218 else
219 {
220 removed = true;
221 }
222 }
223 }
224 return { result, removed };
225}
226
227// Returns the intersection of merge(A1, A2) and A
228inline
229std::pair<multi_action_name_set, bool> bounded_merge(const multi_action_name_set& A1, const multi_action_name_set& A2, const allow_set& A)
230{
231 std::pair<multi_action_name_set, bool> A1A2 = bounded_concat(A1, A2, A);
232 return { alphabet_operations::set_union(alphabet_operations::set_union(A1, A2), A1A2.first), A1A2.second };
233}
234
235// Returns the intersection of left_merge(A1, A2) and A
236inline
237std::pair<multi_action_name_set, bool> bounded_left_merge(const multi_action_name_set& A1, const multi_action_name_set& A2, const allow_set& A)
238{
239 return bounded_merge(A1, A2, A);
240}
241
242// Returns the intersection of sync(A1, A2) and A
243inline
244std::pair<multi_action_name_set, bool> bounded_sync(const multi_action_name_set& A1, const multi_action_name_set& A2, const allow_set& A)
245{
246 return bounded_concat(A1, A2, A);
247}
248
249inline
251{
252 if (x.A_includes_subsets)
253 {
255 }
256 else
257 {
259 }
260}
261
262inline
264{
265 allow_set result = x;
266 result.A = alphabet_operations::hide_inverse(I, result.A, result.A_includes_subsets);
267 result.I.insert(I.begin(), I.end());
268 result.establish_invariant();
269 return result;
270}
271
272inline
274{
276 for (const action_name_multiset& v: V)
277 {
278 const core::identifier_string_list& names = v.names();
279 multi_action_name beta(names.begin(), names.end());
281 if (add)
282 {
283 A.insert(beta);
284 }
285 }
286 return allow_set(A);
287}
288
289inline
291{
293 mCRL2log(log::trace) << "rename_inverse(" << R << ", " << x << ") = " << result << std::endl;
294 return result;
295}
296
297inline
299{
301 mCRL2log(log::trace) << "comm_inverse(" << C << ", " << x << ") = " << result << std::endl;
302 return result;
303}
304
305inline
307{
308 allow_set result = x;
309 if (!x.A_includes_subsets)
310 {
311 result.A = left_arrow2(x.A, x.I, A);
312 }
313 result.establish_invariant();
314 mCRL2log(log::trace) << "left_arrow(" << x << ", " << process::pp(A) << ") = " << result << std::endl;
315 return result;
316}
317
318inline
320{
321 allow_set result = x;
322 result.A_includes_subsets = true;
323 if (result.A.size() <= 1000)
324 {
325 result.A = alphabet_operations::remove_subsets(result.A);
326 }
327 else
328 {
329 mCRL2log(log::debug) << "allow_set::subsets: skipped remove_subsets on a set of " << result.A.size() << " elements." << std::endl;
330 }
331 result.establish_invariant();
332 return result;
333}
334
335} // namespace alphabet_operations
336
337} // namespace process
338
339} // namespace mcrl2
340
341#endif // MCRL2_PROCESS_ALLOW_SET_H
add your file description here.
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
const_iterator end() const
const_iterator begin() const
\brief A multiset of action names
\brief The allow operator
\brief The block operator
\brief The value tau
Standard exception class for reporting runtime errors.
Definition exception.h:27
#define mCRL2log(LEVEL)
mCRL2log(LEVEL) provides the stream used to log.
Definition logger.h:391
std::string pp(const identifier_string &x)
Definition core.cpp:26
allow_set left_arrow(const allow_set &x, const multi_action_name_set &A)
Definition allow_set.h:306
std::pair< multi_action_name_set, bool > bounded_concat(const multi_action_name_set &A1, const multi_action_name_set &A2, const allow_set &A)
Definition allow_set.h:205
multi_action_name_set set_union(const multi_action_name_set &A1, const multi_action_name_set &A2)
multi_action_name_set remove_subsets(const multi_action_name_set &A)
allow_set hide_inverse(const core::identifier_string_list &I, const allow_set &x)
Definition allow_set.h:263
multi_action_name_set left_arrow2(const multi_action_name_set &A, const std::set< core::identifier_string > &I, const multi_action_name_set &A2)
multi_action_name_set set_intersection(const allow_set &A1, const multi_action_name_set &A)
Definition allow_set.h:190
multi_action_name multiset_union(const multi_action_name &alpha, const multi_action_name &beta)
bool subset_includes(const allow_set &A, const multi_action_name &alpha)
Definition allow_set.h:175
bool includes(const multi_action_name &x, const multi_action_name &y)
bool contains(const multi_action_name &alpha, const core::identifier_string &a)
std::pair< multi_action_name_set, bool > bounded_left_merge(const multi_action_name_set &A1, const multi_action_name_set &A2, const allow_set &A)
Definition allow_set.h:237
allow_set block(const core::identifier_string_list &B, const allow_set &x)
Definition allow_set.h:250
multi_action_name hide(const multi_action_name &alpha, const std::set< core::identifier_string > &I)
std::pair< multi_action_name_set, bool > bounded_merge(const multi_action_name_set &A1, const multi_action_name_set &A2, const allow_set &A)
Definition allow_set.h:229
std::pair< multi_action_name_set, bool > bounded_sync(const multi_action_name_set &A1, const multi_action_name_set &A2, const allow_set &A)
Definition allow_set.h:244
multi_action_name_set comm_inverse1(const communication_expression_list &C, const multi_action_name_set &A)
allow_set rename_inverse(const rename_expression_list &R, const allow_set &x)
Definition allow_set.h:290
allow_set subsets(const allow_set &x)
Definition allow_set.h:319
allow_set comm_inverse(const communication_expression_list &C, const allow_set &x)
Definition allow_set.h:298
std::string pp(const action_label &x)
Definition process.cpp:36
std::set< multi_action_name > multi_action_name_set
Represents a set of multi action names.
multi_action_name_set alphabet(const process_expression &x, const std::vector< process_equation > &equations)
Definition alphabet.h:272
std::ostream & operator<<(std::ostream &out, const action_label &x)
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 swap(atermpp::unprotected_aterm_core &t1, atermpp::unprotected_aterm_core &t2) noexcept
Swaps two aterms.
Definition aterm.h:462
add your file description here.
Represents the set AI*. If the attribute A_includes_subsets is true, also subsets of the elements are...
Definition allow_set.h:29
multi_action_name_set A
Definition allow_set.h:30
bool operator==(const allow_set &other) const
Definition allow_set.h:123
bool contains(const multi_action_name &alpha) const
Returns true if the allow set contains the multi action name alpha.
Definition allow_set.h:98
multi_action_name_set intersect(const multi_action_name_set &alphabet) const
Returns the intersection of the allow set with alphabet.
Definition allow_set.h:105
allow_set(const multi_action_name_set &A_, bool A_includes_subsets_=false, const std::set< core::identifier_string > &I_=std::set< core::identifier_string >())
Definition allow_set.h:88
bool check_invariant() const
Definition allow_set.h:65
std::set< core::identifier_string > I
Definition allow_set.h:32
multi_action_name pick_element() const
Definition allow_set.h:39
bool operator<(const allow_set &other) const
Definition allow_set.h:128
Represents the name of a multi action.