mCRL2
Loading...
Searching...
No Matches
suminst.h
Go to the documentation of this file.
1// Author(s): Jeroen Keiren
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_SUMINST_H
13#define MCRL2_LPS_SUMINST_H
14
16
18
20
21namespace mcrl2
22{
23namespace lps
24{
25
27inline
28std::set<data::sort_expression> finite_sorts(const data::data_specification& s)
29{
30 const std::set<data::sort_expression>& sorts = s.sorts();
31 std::set<data::sort_expression> result;
32
33 for(const data::sort_expression& sort : sorts)
34 {
35 if(s.is_certainly_finite(sort))
36 {
37 result.insert(sort);
38 }
39 }
40 return result;
41}
42
43template<typename DataRewriter, typename Specification>
44class suminst_algorithm: public detail::lps_algorithm<Specification>
45{
48 typedef typename Specification::process_type process_type;
49 typedef typename process_type::action_summand_type action_summand_type;
50 typedef std::vector<action_summand_type> action_summand_vector_type;
51 using super::m_spec;
52
53 protected:
55 std::set<data::sort_expression> m_sorts;
56
59
61 DataRewriter m_rewriter;
64
66 std::size_t m_processed;
67 std::size_t m_deleted;
68 std::size_t m_added;
69
70 template <typename SummandType, typename Container>
71 std::size_t instantiate_summand(const SummandType& s, Container& result)
72 {
73 using namespace data;
74 std::size_t nr_summands = 0; // Counter for the number of new summands, used for verbose output
75 std::deque< variable > variables; // The variables we need to consider in instantiating
76
77 // partition such that variables with finite sort precede those that do not
78 for (const variable& v: s.summation_variables())
79 {
80 if(m_sorts.find(v.sort()) != m_sorts.end())
81 {
82 if (m_spec.data().is_certainly_finite(v.sort()))
83 {
84 variables.push_front(v);
85 }
86 else
87 {
88 variables.push_back(v);
89 }
90 }
91 }
92
93 if (variables.empty())
94 {
95 // Nothing to be done, return original summand
96 result.push_back(s);
97 nr_summands = 1;
98 }
99 else
100 {
101 // List of variables with the instantiated variables removed (can be done upfront, which is more efficient,
102 // because we only need to calculate it once.
103 const variable_list vl(variables.begin(),variables.end());
104 variable_list new_summation_variables = term_list_difference(s.summation_variables(), vl);
105
106 try
107 {
108 mCRL2log(log::debug) << "enumerating variables " << vl << " in condition: " << data::pp(s.condition()) << std::endl;
110 m_enumerator.enumerate(enumerator_element(vl, s.condition()),
111 local_sigma,
112 [&](const enumerator_element& p)
113 {
114 mutable_indexed_substitution<> sigma;
115 p.add_assignments(vl, sigma, m_rewriter);
116 mCRL2log(log::debug) << "substitutions: " << sigma << std::endl;
117 SummandType t(s);
118 t.summation_variables() = new_summation_variables;
119 lps::rewrite(t, m_rewriter, sigma);
120 result.push_back(t);
121 ++nr_summands;
122 return false;
123 },
124 sort_bool::is_false_function_symbol
125 );
126 }
127 catch (mcrl2::runtime_error const& e)
128 {
129 // If an error occurs in enumerating, remove all summands that
130 // have been added to result thus far, and re-add the original.
131 // This prevents problems e.g. in case of a sort without constructors.
132 mCRL2log(log::debug) << "An error occurred in enumeration, removing already added summands, and keeping the original" << std::endl;
133 mCRL2log(log::debug) << e.what() << std::endl;
134
135 result.resize(result.size() - nr_summands);
136 result.push_back(s);
137 nr_summands = 1;
138 }
139 }
140 return nr_summands;
141 }
142
144 {
145 return !m_tau_summands_only || summand.is_tau();
146 }
147
149 {
150 return !m_tau_summands_only;
151 }
152
153 template <typename SummandListType, typename Container>
154 void run(const SummandListType& list, Container& result)
155 {
156 for (typename SummandListType::const_iterator i = list.begin(); i != list.end(); ++i)
157 {
158 if (must_instantiate(*i))
159 {
160 std::size_t newsummands = instantiate_summand(*i, result);
161 if (newsummands > 0)
162 {
163 m_added += newsummands - 1;
164 }
165 else
166 {
167 ++m_deleted;
168 }
169 }
170 else
171 {
172 result.push_back(*i);
173 }
174 ++m_processed;
175 mCRL2log(log::status) << "Replaced " << m_processed << " summands by " << (m_processed + m_added - m_deleted)
176 << " summands (" << m_deleted << " were deleted)" << std::endl;
177 }
178 }
179
180 public:
181 suminst_algorithm(Specification& spec,
182 DataRewriter& r,
183 std::set<data::sort_expression> sorts = std::set<data::sort_expression>(),
184 bool tau_summands_only = false)
185 : detail::lps_algorithm<Specification>(spec),
186 m_sorts(sorts),
187 m_tau_summands_only(tau_summands_only),
188 m_rewriter(r),
189 m_enumerator(r, spec.data(), r, m_id_generator, false),
190 m_processed(0),
191 m_deleted(0),
192 m_added(0)
193 {
194 if(sorts.empty())
195 {
196 mCRL2log(log::info) << "an empty set of sorts to be unfolded was provided; defaulting to all finite sorts" << std::endl;
197 m_sorts = finite_sorts(spec.data());
198 }
199 }
200
201 void run()
202 {
203 action_summand_vector_type action_summands;
204 deadlock_summand_vector deadlock_summands;
205 m_added = 0;
206 m_deleted = 0;
207 m_processed = 0;
208 run(m_spec.process().action_summands(), action_summands);
209 run(m_spec.process().deadlock_summands(), deadlock_summands);
210 m_spec.process().action_summands().swap(action_summands);
211 m_spec.process().deadlock_summands().swap(deadlock_summands);
212 mCRL2log(log::status) << std::endl;
213 }
214
215}; // suminst_algorithm
216
217} // namespace lps
218} // namespace mcrl2
219
220#endif // MCRL2_LPS_SUMINST_H
221
const_iterator end() const
Returns a const_iterator pointing past the last argument.
Definition aterm.h:172
const_iterator begin() const
Returns an iterator pointing to the first argument.
Definition aterm.h:165
bool is_certainly_finite(const sort_expression &s) const
Checks whether a sort is certainly finite.
An enumerator algorithm that generates solutions of a condition.
Definition enumerator.h:601
std::size_t enumerate(const EnumeratorListElement &p, MutableSubstitution &sigma, ReportSolution report_solution, Reject reject=Reject(), Accept accept=Accept()) const
Enumerates the element p. Solutions are reported using the callback function report_solution....
Definition enumerator.h:977
An element for the todo list of the enumerator that collects the substitution corresponding to the ex...
Definition enumerator.h:348
\brief A sort expression
const std::set< sort_expression > & sorts() const
Gets the normalised sort declarations including those that are system defined. This is the set with a...
LPS summand containing a deadlock.
Algorithm class for algorithms on linear process specifications. It can be instantiated with lps::spe...
lps_algorithm(Specification &spec)
Constructor.
Specification & m_spec
The specification that is processed by the algorithm.
process_type::action_summand_type action_summand_type
Definition suminst.h:49
DataRewriter m_rewriter
Rewriter.
Definition suminst.h:61
void run(const SummandListType &list, Container &result)
Definition suminst.h:154
std::set< data::sort_expression > m_sorts
Sorts to be instantiated.
Definition suminst.h:55
detail::lps_algorithm< Specification > super
Definition suminst.h:46
data::enumerator_identifier_generator m_id_generator
Definition suminst.h:63
Specification::process_type process_type
Definition suminst.h:48
data::enumerator_algorithm m_enumerator
Definition suminst.h:62
std::vector< action_summand_type > action_summand_vector_type
Definition suminst.h:50
std::size_t instantiate_summand(const SummandType &s, Container &result)
Definition suminst.h:71
std::size_t m_processed
Statistiscs for verbose output.
Definition suminst.h:66
bool must_instantiate(const action_summand_type &summand)
Definition suminst.h:143
bool must_instantiate(const deadlock_summand &)
Definition suminst.h:148
suminst_algorithm(Specification &spec, DataRewriter &r, std::set< data::sort_expression > sorts=std::set< data::sort_expression >(), bool tau_summands_only=false)
Definition suminst.h:181
data::enumerator_list_element_with_substitution enumerator_element
Definition suminst.h:47
bool m_tau_summands_only
Only instantiate tau summands.
Definition suminst.h:58
Standard exception class for reporting runtime errors.
Definition exception.h:27
The class enumerator.
#define mCRL2log(LEVEL)
mCRL2log(LEVEL) provides the stream used to log.
Definition logger.h:391
Add your file description here.
std::string pp(const abstraction &x)
Definition data.cpp:39
std::vector< deadlock_summand > deadlock_summand_vector
\brief vector of deadlock_summands
std::set< data::sort_expression > finite_sorts(const data::data_specification &s)
Return a set with all finite sorts in data specification s.
Definition suminst.h:28
A class that takes a linear process specification and checks all tau-summands of that LPS for conflue...
Definition indexed_set.h:72
Set operations on term lists.