12#ifndef MCRL2_PBES_PBESINST_FINITE_ALGORITHM_H
13#define MCRL2_PBES_PBESINST_FINITE_ALGORITHM_H
15#include "mcrl2/data/consistency.h"
16#include "mcrl2/data/enumerator.h"
17#include "mcrl2/data/replace.h"
18#include "mcrl2/pbes/algorithms.h"
19#include "mcrl2/pbes/detail/pbes_parameter_map.h"
20#include "mcrl2/pbes/join.h"
21#include "mcrl2/pbes/rewriters/data_rewriter.h"
44 std::ostringstream out;
45 out << std::string(name);
46 for (
const data::data_expression& param: parameters)
48 out <<
"_" << data::pp(param);
62 if (id_generator.has_identifier(dest))
64 dest = id_generator(dest);
68 id_generator.add_identifier(dest);
97template <
typename PropositionalVariable,
typename Parameter>
100 std::vector<Parameter>& finite,
101 std::vector<Parameter>& infinite
104 auto pi = index_map.find(X.name());
105 assert(pi != index_map.end());
106 const std::vector<std::size_t>& v = pi->second;
107 auto i = X.parameters().begin();
108 std::size_t index = 0;
110 for (; i != X.parameters().end(); ++i, ++index)
112 if (j != v.end() && index == *j)
114 finite.push_back(*i);
119 infinite.push_back(*i);
125template <
typename DataRewriter,
typename SubstitutionFunction>
138 SubstitutionFunction& sigma,
152 const std::vector<data::data_expression>& infinite_parameters
155 std::ostringstream out;
157 for (
const data::data_expression& e: finite_parameters)
162 for (
const data::data_expression& e: infinite_parameters)
171 template <
typename VariableContainer,
typename ExpressionContainer>
174 assert(variables.size() == expressions.size());
175 if (variables.empty())
179 auto vi = variables.begin();
180 auto ei = expressions.begin();
184 for (; vi != variables.end(); ++vi, ++ei)
191 template <
typename DataExpressionContainer>
194 return data::data_expression_list(v.begin(), v.end(), [&](
const data::data_expression& x) {
return rewr(x); });
197 template <
typename DataExpressionContainer>
200 return data::data_expression_list(v.begin(), v.end(), [&](
const data::data_expression& x) {
return rewr(x, sigma); });
206 typedef data::enumerator_list_element_with_substitution<> enumerator_element;
209 std::vector<data::data_expression> finite_parameters;
210 std::vector<data::data_expression> infinite_parameters;
211 split_parameters(x, m_index_map, finite_parameters, infinite_parameters);
212 mCRL2log(log::debug) << print_parameters(finite_parameters, infinite_parameters);
219 std::vector<data::variable> di;
220 if (vi != m_variable_map.end())
225 std::set<pbes_expression> result_set;
226 bool accept_solutions_with_variables =
false;
228 data::enumerator_algorithm<> E(super::R, m_data_spec, super::R, id_generator, accept_solutions_with_variables);
230 data::mutable_indexed_substitution<> local_sigma;
231 E.enumerate(enumerator_element(di_list, data::true_()),
233 [&](
const enumerator_element& p) {
234 data::mutable_indexed_substitution<> sigma_i;
235 p.add_assignments(di_list, sigma_i, super::R);
236 data::data_expression_list d_copy = rewrite_container(d, super::R, sigma);
237 data::data_expression_list e_copy = rewrite_container(e, super::R, sigma);
238 data::data_expression_list di_copy = atermpp::container_cast<data::data_expression_list>(di_list);
239 di_copy = data::replace_free_variables(di_copy, sigma_i);
240 data::data_expression c = make_condition(di_copy, d_copy);
241 core::identifier_string Y = m_rename(Xi, di_copy);
242 result_set.insert(and_(c, propositional_variable_instantiation(Y, e_copy)));
246 result = join_or(result_set.begin(), result_set.end());
252 std::vector<data::data_expression> finite_parameters_vector;
253 std::vector<data::data_expression> infinite_parameters_vector;
254 split_parameters(init, m_index_map, finite_parameters_vector, infinite_parameters_vector);
259 return propositional_variable_instantiation(X, infinite_parameters);
284 for (
const pbes_equation& eqn: equations)
286 const core::identifier_string& name = eqn.variable().name();
287 const data::variable_list& parameters = eqn.variable().parameters();
289 std::vector<std::size_t> v;
290 auto j = variable_map.find(name);
291 if (j != variable_map.end())
293 std::size_t index = 0;
294 for (
auto k = parameters.begin(); k != parameters.end(); ++k, ++index)
296 if (contains(j->second, *k))
309 if (size > 0 && size % 1000 == 0)
311 std::ostringstream out;
312 out <<
"Generated " << size <<
" BES equations" <<
std::endl;
337 compute_index_map(pbesspec.equations(), variable_map, index_map);
339 data::
rewriter rewr(pbesspec.data(), m_rewriter_strategy);
342 std::vector<pbes_equation> equations;
343 for (
const pbes_equation& eqn: pbesspec.equations())
345 std::vector<data::variable> finite_parameters;
346 std::vector<data::variable> infinite_parameters;
347 detail::split_parameters(eqn.variable(), index_map, finite_parameters, infinite_parameters);
348 data::variable_list infinite(infinite_parameters.begin(), infinite_parameters.end());
350 typedef data::enumerator_list_element_with_substitution<> enumerator_element;
351 bool accept_solutions_with_variables =
false;
352 data::enumerator_algorithm<> E(rewr, pbesspec.data(), rewr, m_id_generator, accept_solutions_with_variables);
353 data::variable_list finite_parameter_list(finite_parameters.begin(), finite_parameters.end());
354 data::mutable_indexed_substitution<> sigma;
355 E.enumerate(enumerator_element(finite_parameter_list, data::true_()),
357 [&](
const enumerator_element& p) {
358 data::mutable_indexed_substitution<> sigma_j;
359 p.add_assignments(finite_parameter_list, sigma_j, rewr);
360 std::vector<data::data_expression> finite;
361 for (
const data::variable& v: finite_parameters)
363 finite.push_back(sigma_j(v));
365 core::identifier_string name = rename(eqn.variable().name(), data::data_expression_list(finite.begin(), finite.end()));
366 propositional_variable X(name, infinite);
367 detail::pbesinst_finite_builder<data::rewriter, data::mutable_indexed_substitution<>> visitor(rewr, sigma_j, rename, pbesspec.data(), index_map, variable_map);
368 pbes_expression formula;
369 visitor.apply(formula, eqn.formula());
370 equations.emplace_back(eqn.symbol(), X, formula);
371 mCRL2log(log::debug) << print_equation_count(++m_equation_count);
372 mCRL2log(log::debug) <<
"Added equation " << pbes_system::pp(eqn) <<
"\n";
384 pbesspec.equations() = equations;
394 for (
const pbes_equation& eqn: p.equations())
396 for (
const data::variable& v: eqn.variable().parameters())
398 if (p.data().is_certainly_finite(v.sort()))
400 variable_map[eqn.variable().name()].push_back(v);
412 if (finite_parameter_selection.empty())
414 throw empty_parameter_selection(
"no finite parameters were selected!");
419 bool is_empty =
true;
420 for (
auto& i: parameter_map)
422 if (!((i.second).empty()))
430 mCRL2log(log::verbose) <<
"Warning: no parameters were found that match the string \"" + finite_parameter_selection +
"\"" <<
std::endl;
434 algorithm
.run(p
, parameter_map
);
Rewriter that operates on data expressions.
Identifier generator that stores the identifiers of the context in a set. Using the operator()() and ...
logger(const log_level_t l)
Default constructor.
parameterized boolean equation system
propositional_variable_instantiation & initial_state()
Returns the initial state.
Algorithm class for the finite pbesinst algorithm.
data::enumerator_identifier_generator m_id_generator
Identifier generator for the enumerator.
std::size_t m_equation_count
The number of generated equations.
void run(pbes &p)
Runs the algorithm.
void run(pbes &pbesspec, const pbesinst_variable_map &variable_map)
Runs the algorithm.
std::string print_equation_count(std::size_t size) const
Prints a message for every 1000-th equation.
data::rewriter::strategy m_rewriter_strategy
The strategy of the data rewriter.
void compute_index_map(const std::vector< pbes_equation > &equations, const pbesinst_variable_map &variable_map, pbesinst_index_map &index_map)
Returns true if the container contains the given element.
pbesinst_finite_algorithm(data::rewriter::strategy rewriter_strategy=data::jitty)
Constructor.
\brief A propositional variable instantiation
propositional_variable_instantiation(const core::identifier_string &name, const data::data_expression_list ¶meters)
Constructor.
const core::identifier_string & name() const
propositional_variable_instantiation & operator=(const propositional_variable_instantiation &) noexcept=default
Standard exception class for reporting runtime errors.
#define mCRL2log(LEVEL)
mCRL2log(LEVEL) provides the stream used to log.
atermpp::aterm_string identifier_string
String type of the LPS library. Identifier strings are represented internally as ATerms.
Namespace for all data library functionality.
data_expression and_(const data_expression &x, const data_expression &y)
const data_expression & true_()
rewrite_strategy
The strategy of the rewriter.
atermpp::term_list< data_expression > data_expression_list
\brief list of data_expressions
atermpp::term_list< variable > variable_list
\brief list of variables
std::set< data::variable > significant_variables(const pbes_expression &x)
Returns the significant variables of a pbes expression.
void remove_parameters(pbes &x, const std::set< data::variable > &to_be_removed)
Removes parameters from propositional variable instantiations in a pbes expression.
void pbesinst_finite(pbes &p, data::rewrite_strategy rewrite_strategy, const std::string &finite_parameter_selection)
Apply finite instantiation to the given PBES.
void instantiate_global_variables(pbes &p)
Attempts to eliminate the free variables of a PBES, by substituting a constant value for them....
bool is_normalized(const pbes &x)
Checks if a PBEs is normalized.
std::vector< propositional_variable > remove_unreachable_variables(pbes &p)
Removes equations that are not (syntactically) reachable from the initial state of a PBES.
std::string print_removed_equations(const std::vector< propositional_variable > &removed)
Print removed equations.
void normalize(pbes &x)
The function normalize brings (embedded) pbes expressions into positive normal form,...
std::map< core::identifier_string, std::vector< data::variable > > pbes_parameter_map
Data structure for storing the variables that should be expanded by the finite pbesinst algorithm.
void split_parameters(const PropositionalVariable &X, const pbesinst_index_map &index_map, std::vector< Parameter > &finite, std::vector< Parameter > &infinite)
Computes the subset with variables of finite sort and infinite.
pbes_parameter_map parse_pbes_parameter_map(const pbes &p, const std::string &text)
Parses parameter selection for finite pbesinst algorithm.
The main namespace for the PBES library.
std::map< core::identifier_string, std::vector< data::variable > > pbesinst_variable_map
Data structure for storing the variables that should be expanded by the finite pbesinst algorithm.
void pbesinst_finite(pbes &p, data::rewrite_strategy rewrite_strategy, const std::string &finite_parameter_selection)
std::map< core::identifier_string, std::vector< std::size_t > > pbesinst_index_map
Data structure for storing the indices of the variables that should be expanded by the finite pbesins...
A class that takes a linear process specification and checks all tau-summands of that LPS for conflue...
An empty struct that is used to denote the absence of a substitution. Used for rewriters.
Visitor that applies a propositional variable substitution to a pbes expression.
const pbesinst_finite_rename & m_rename
data::data_expression make_condition(const VariableContainer &variables, const ExpressionContainer &expressions) const
Computes the condition 'for all i: variables[i] == expressions[i]'.
void apply(T &result, const propositional_variable_instantiation &x)
const pbesinst_index_map & m_index_map
data::data_expression_list rewrite_container(const DataExpressionContainer &v, const data::rewriter &rewr, const data::mutable_indexed_substitution<> &sigma)
const pbesinst_variable_map & m_variable_map
std::string print_parameters(const std::vector< data::data_expression > &finite_parameters, const std::vector< data::data_expression > &infinite_parameters) const
propositional_variable_instantiation visit_initial_state(const propositional_variable_instantiation &init)
const data::data_specification & m_data_spec
pbes_system::detail::data_rewriter_builder< pbesinst_finite_builder, DataRewriter, SubstitutionFunction > super
data::data_expression_list rewrite_container(const DataExpressionContainer &v, const data::rewriter &rewr)
pbesinst_finite_builder(const DataRewriter &R, SubstitutionFunction &sigma, const pbesinst_finite_rename &rho, const data::data_specification &data_spec, const pbesinst_index_map &index_map, const pbesinst_variable_map &variable_map)
Exception that is used to signal an empty parameter selection.
empty_parameter_selection(const std::string &msg)
Function object for renaming a propositional variable instantiation.
core::identifier_string operator()(const core::identifier_string &name, const data::data_expression_list ¶meters) const
Renames the propositional variable x.
std::unordered_map< propositional_variable_instantiation, core::identifier_string > m
data::set_identifier_generator id_generator
core::identifier_string rename(const core::identifier_string &name, const data::data_expression_list ¶meters) const
std::size_t operator()(const atermpp::detail::reference_aterm< T > &t) const