mCRL2
Loading...
Searching...
No Matches
pbes_parameter_map.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//
9/// \file mcrl2/pbes/detail/pbes_parameter_map.h
10/// \brief add your file description here.
11
12#ifndef MCRL2_PBES_DETAIL_PBES_PARAMETER_MAP_H
13#define MCRL2_PBES_DETAIL_PBES_PARAMETER_MAP_H
14
15#include "mcrl2/core/detail/print_utility.h"
16#include "mcrl2/pbes/pbes.h"
17#include <regex>
18
19namespace mcrl2::pbes_system::detail
20{
21
22/// \brief Data structure for storing the variables that should be expanded by the finite pbesinst algorithm.
24
25/// \brief Returns true if the declaration text matches with the variable d.
26inline
27bool match_declaration(const std::string& text, const data::variable& d, const data::data_specification& data_spec)
28{
29 std::vector<std::string> words = utilities::split(text, ":");
30 if (words.size() != 2)
31 {
32 throw mcrl2::runtime_error("invalid parameter declaration: '" + text + "'");
33 }
34 std::string name = utilities::trim_copy(words[0]);
35 std::string type = utilities::trim_copy(words[1]);
36 if (name != "*" && core::identifier_string(name) != d.name())
37 {
38 return false;
39 }
40 return type == "*" || data::parse_sort_expression(type, data_spec) == d.sort();
41}
42
43/// \brief Find parameter declarations that match a given string.
44inline
46{
47 std::set<data::variable> result;
48 for (const pbes_equation& eqn: p.equations())
49 {
50 const propositional_variable& X = eqn.variable();
51 if (name == "*" || name == std::string(X.name()))
52 {
53 for (const data::variable& v: X.parameters())
54 {
55 // find a declaration *k that accepts the variable *j
56 for (const std::string& declaration: declarations)
57 {
58 if (match_declaration(declaration, v, p.data()))
59 {
60 result.insert(v);
61 break;
62 }
63 }
64 }
65 }
66 }
67 return std::vector<data::variable>(result.begin(), result.end());
68}
69
70/// \brief Parses parameter selection for finite pbesinst algorithm
71inline
73{
74 pbes_parameter_map result;
75
76 // maps propositional variable name to the corresponding variable declarations, for example:
77 // X(b:Bool,c:C) X(d:*) Y(*:Bool) results in the mapping
78 //
79 // X -> { "b:Bool", "c:C", "d:*" }
80 // Y -> { "*:Bool" }
81 std::map<std::string, std::set<std::string>> parameter_declarations;
82
83 for (const std::string& s: utilities::split(text, ";"))
84 {
85 std::string line = utilities::trim_copy(s);
86 if (line.empty())
87 {
88 continue;
89 }
90 std::regex sre(R"((\*|\w*)\‍(([:,#*\s\w>'()-]*)\‍)\s*)", std::regex::icase);
91 std::match_results<std::string::const_iterator> what;
92 if (!regex_match(line, what, sre))
93 {
94 mCRL2log(log::log_level_t::warning) << "ignoring selection '" << line << "'" << std::endl;
95 continue;
96 }
97 std::string X = what[1];
98 utilities::trim(X);
99 std::string word = what[2];
100 utilities::trim(word);
101 for (const std::string& parameter: utilities::regex_split(word, "\\s*,\\s*"))
102 {
103 parameter_declarations[X].insert(parameter);
104 }
105 }
106
107 // expand the name "*"
108 auto q = parameter_declarations.find("*");
109 if (q != parameter_declarations.end())
110 {
111 std::set<std::string> v = q->second;
112 parameter_declarations.erase(q);
113 for (const pbes_equation& eqn: p.equations())
114 {
115 std::string name = eqn.variable().name();
116 parameter_declarations[name].insert(v.begin(), v.end());
117 }
118 }
119
120 // create a mapping from PBES variable names to the corresponding parameters
121 std::map<core::identifier_string, data::variable_list> pbes_index;
122 for (const pbes_equation& eqn: p.equations())
123 {
124 const propositional_variable& X = eqn.variable();
125 pbes_index[X.name()] = X.parameters();
126 }
127
128 for (const auto& decl: parameter_declarations)
129 {
130 core::identifier_string name(decl.first);
131 std::vector<data::variable> variables = find_matching_parameters(p, decl.first, decl.second);
132
133 // sort variables according to their position in the PBES variable
134 std::map<data::variable, std::size_t> m;
135 std::size_t index = 0;
136 for (const data::variable& v: pbes_index[name])
137 {
138 m[v] = index++;
139 }
140 std::sort(variables.begin(), variables.end(), [&](const data::variable& x, const data::variable& y) { return m[x] < m[y]; });
141
142 result[name] = variables;
143 }
144
145 return result;
146}
147
148/// \brief Print a parameter map.
149inline
151{
152 for (const auto& p: m)
153 {
154 out << p.first << " -> " << core::detail::print_list(p.second) << std::endl;
155 }
156 return out;
157}
158
159} // namespace mcrl2::pbes_system::detail
160
161#endif // MCRL2_PBES_DETAIL_PBES_PARAMETER_MAP_H
Rewriter that operates on data expressions.
Definition rewriter.h:84
Identifier generator that stores the identifiers of the context in a set. Using the operator()() and ...
\brief A data variable
Definition variable.h:25
\brief The and operator for pbes expressions
\brief The existential quantification operator for pbes expressions
const data::variable_list & variables() const
\brief The universal quantification operator for pbes expressions
const data::variable_list & variables() const
\brief The implication operator for pbes expressions
\brief The not operator for pbes expressions
\brief The or operator for pbes expressions
parameterized boolean equation system
Definition pbes.h:54
propositional_variable_instantiation & initial_state()
Returns the initial state.
Definition pbes.h:194
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 &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.
pbesinst_finite_algorithm(data::rewriter::strategy rewriter_strategy=data::rewrite_strategy::jitty)
Constructor.
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.
\brief A propositional variable instantiation
propositional_variable_instantiation(const core::identifier_string &name, const data::data_expression_list &parameters)
Constructor.
propositional_variable_instantiation & operator=(const propositional_variable_instantiation &) noexcept=default
#define mCRL2log(LEVEL)
mCRL2log(LEVEL) provides the stream used to log.
Definition logger.h:435
data_expression and_(const data_expression &x, const data_expression &y)
const data_expression & true_()
Definition consistency.h:91
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 remove_parameters(pbes &x, const std::map< core::identifier_string, std::vector< std::size_t > > &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....
Definition pbes.cpp:64
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::ostream & print_pbes_parameter_map(std::ostream &out, const pbes_parameter_map &m)
Print a parameter map.
bool match_declaration(const std::string &text, const data::variable &d, const data::data_specification &data_spec)
Returns true if the declaration text matches with the variable d.
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.
std::vector< data::variable > find_matching_parameters(const pbes &p, const std::string &name, const std::set< std::string > &declarations)
Find parameter declarations that match a given string.
The main namespace for the PBES library.
void pbesinst_finite(pbes &p, data::rewrite_strategy rewrite_strategy, const std::string &finite_parameter_selection)
pbes_expression optimized_exists(const data::variable_list &l, const pbes_expression &p, bool remove_variables=false)
Make an existential quantification If l is empty, p is returned.
bool is_normalized(const T &x)
Checks if a pbes expression is normalized.
Definition normalize.h:155
pbes_expression optimized_forall(const data::variable_list &l, const pbes_expression &p, bool remove_variables=false)
Make a universal quantification If l is empty, p is returned.
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.
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)
data::data_expression_list rewrite_container(const DataExpressionContainer &v, const data::rewriter &rewr, const data::mutable_indexed_substitution<> &sigma)
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)
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.
Function object for renaming a propositional variable instantiation.
core::identifier_string operator()(const core::identifier_string &name, const data::data_expression_list &parameters) const
Renames the propositional variable x.
std::unordered_map< propositional_variable_instantiation, core::identifier_string > m
core::identifier_string rename(const core::identifier_string &name, const data::data_expression_list &parameters) const