12#ifndef MCRL2_LPS_DETAIL_PARAMETER_SELECTION_H
13#define MCRL2_LPS_DETAIL_PARAMETER_SELECTION_H
15#include "mcrl2/core/detail/print_utility.h"
16#include "mcrl2/data/parse.h"
34template <
typename OutputIterator>
43 std::set<data::variable> result;
44 for (
const data::variable& v: params)
46 for (
const auto& [name, type]: selections)
48 if (match_selection(v, name, type, dataspec))
54 return std::vector<data::variable>(result.begin(), result.end());
59std::vector<data::variable> parse_lps_parameter_selection(
const data::variable_list& params,
const data::data_specification& dataspec,
const std::string& text)
61 std::vector<data::variable> result;
66 throw mcrl2::runtime_error(
"The parameter selection argument is empty.");
68 std::regex sre(R"(\s*(\w[\w']*|\*)\s*:\s*(\w[\w']*|\*)\s*)", std::regex::icase);
69 std::vector<std::pair<std::string, std::string>> selections;
70 for (
const std::string& var_sort: utilities::split(text,
","))
72 std::match_results<std::string::const_iterator> what;
73 if (!std::regex_match(var_sort, what, sre))
75 mCRL2log(log::warning) <<
"Ignoring " << var_sort <<
" since it does not follow the necessary format (NAME:SORT)." << std::endl;
79 selections.push_back(std::make_pair(what[1], what[2]));
82 find_matching_parameters(params, dataspec, selections, std::inserter(result, result.end()));
85 std::map<data::variable, std::size_t> m;
86 std::size_t index = 0;
87 for (
const data::variable& v: params)
91 std::sort(result.begin(), result.end(), [&](
const data::variable& x,
const data::variable& y) {
return m[x] < m[y]; });
aterm_string(const std::string &s)
Constructor that allows construction from a string.
bool operator==(const unprotected_aterm_core &t) const
Comparison operator.
bool operator!=(const unprotected_aterm_core &t) const
Inequality operator on two unprotected aterms.
Rewriter that operates on data expressions.
Identifier generator that stores the identifiers of the context in a set. Using the operator()() and ...
const core::identifier_string & name() const
const sort_expression & sort() const
logger(const log_level_t l)
Default constructor.
LPS summand containing a multi-action.
Algorithm class that can be used to apply the binary algorithm.
data::assignment_list replace_enumerated_parameters_in_assignments(data::assignment_list v)
Replace assignments in v that are of a finite sort with a vector of assignments to Boolean variables.
data::data_expression make_if_tree(data::variable_vector new_parameters, const data::data_expression_vector &enumerated_elements)
Build an if-then-else tree of enumerated elements in terms of new parameters.
binary_algorithm(Specification &spec, DataRewriter &r, const std::string parameter_selection="")
Constructor for binary algorithm.
void update_deadlock_summand(deadlock_summand &s)
Update a deadlock summand with the new Boolean parameters.
detail::lps_algorithm< Specification > super
std::map< data::variable, std::vector< data::data_expression > > m_enumerated_elements
Mapping of variables to all values they can be assigned.
stochastic_process_initializer update_initial_process(const data::variable_list ¶meters, const stochastic_process_initializer &init)
Specification::process_type process_type
data::set_identifier_generator m_if_trees_generator
Contains the names of variables appearing in rhs of m_if_trees.
const std::string m_parameter_selection
void replace_enumerated_parameters(const std::set< data::variable > &selected_params)
Take a specification and calculate a vector of boolean variables for each process parameter in select...
data::data_expression_list replace_enumerated_parameters_in_initial_expressions(const data::variable_list &vl, const data::data_expression_list &el)
Replace expressions in v that are of a finite sort with a vector of assignments to Boolean variables.
void update_action_summand(action_summand &s)
Update an action summand with the new Boolean parameters.
std::set< data::variable > select_parameters(const std::string parameter_selection) const
Determine which variables should be replaced, based on parameter_selection.
void run()
Apply the algorithm to the specification passed in the constructor.
process_type::action_summand_type action_summand_type
data::mutable_map_substitution m_if_trees
Mapping of variables to corresponding if-tree.
process_initializer update_initial_process(const data::variable_list ¶meters, const process_initializer &init)
DataRewriter m_rewriter
Rewriter.
std::map< data::variable, std::vector< data::variable > > m_new_parameters
Mapping of finite variables to boolean vectors.
void update_action_summand(stochastic_action_summand &s)
Update an action summand with the new Boolean parameters.
data::enumerator_list_element_with_substitution enumerator_element
data::enumerator_identifier_generator m_id_generator
Identifier generator for the enumerator.
Algorithm class for elimination of constant parameters.
LPS summand containing a deadlock.
Algorithm class for algorithms on linear process specifications. It can be instantiated with lps::spe...
Stores the following properties of a linear process specification:
LPS summand containing a multi-action.
\brief A stochastic distribution
A stochastic process initializer.
Linear process specification.
Standard exception class for reporting runtime errors.
#define mCRL2log(LEVEL)
mCRL2log(LEVEL) provides the stream used to log.
std::string pp(const atermpp::aterm &t)
Transform an aterm to an ascii string.
std::string pp_format_to_string(const print_format_type pp_format)
Print string representation of pretty print format.
atermpp::aterm_string identifier_string
String type of the LPS library. Identifier strings are represented internally as ATerms.
smt_solver_type
The enumeration type smt_solver_type enumerates all available SMT solvers.
Namespace for all data library functionality.
std::vector< assignment > assignment_vector
\brief vector of assignments
std::vector< variable > variable_vector
\brief vector of variables
std::vector< data_expression > data_expression_vector
\brief vector of data_expressions
atermpp::term_list< data_expression > data_expression_list
\brief list of data_expressions
atermpp::term_list< variable > variable_list
\brief list of variables
sort_expression parse_sort_expression(const std::string &text, const data_specification &data_spec=detail::default_specification())
Parses and type checks a sort expression.
atermpp::term_list< assignment > assignment_list
\brief list of assignments
std::string pp(const data::sort_expression_vector &x)
std::vector< data::variable > find_matching_parameters(const data::variable_list ¶ms, const data::data_specification &dataspec, const std::vector< std::pair< std::string, std::string > > &selections, OutputIterator o)
Find parameter declarations that match a given string.
The main namespace for the LPS library.
void lpspp(const std::string &input_filename, const std::string &output_filename, bool print_summand_numbers, core::print_format_type format)
void lpssumelm(const std::string &input_filename, const std::string &output_filename, const bool decluster)
void txt2lps(const std::string &input_filename, const std::string &output_filename)
void lpsuntime(const std::string &input_filename, const std::string &output_filename, const bool add_invariants, const bool apply_fourier_motzkin, const data::rewriter::strategy rewrite_strategy)
std::string pp(const lps::stochastic_specification &x)
void lpssuminst(const std::string &input_filename, const std::string &output_filename, const data::rewriter::strategy rewrite_strategy, const std::string &sorts_string, const bool finite_sorts_only, const bool tau_summands_only)
std::size_t nr_of_booleans_for_elements(std::size_t n)
bool lpsinvelm(const std::string &input_filename, const std::string &output_filename, const std::string &invariant_filename, const std::string &dot_file_name, data::rewriter::strategy rewrite_strategy, data::detail::smt_solver_type solver_type, const bool no_check, const bool no_elimination, const bool simplify_all, const bool all_violations, const bool counter_example, const bool path_eliminator, const bool apply_induction, const int time_limit)
void lpsparelm(const std::string &input_filename, const std::string &output_filename)
void lpsbinary(const std::string &input_filename, const std::string &output_filename, const std::string ¶meter_selection)
lps_rewriter_type
An enumerated type for the available lps rewriters.
void lpsconstelm(const std::string &input_filename, const std::string &output_filename, data::rewriter::strategy rewrite_strategy, bool instantiate_free_variables, bool ignore_conditions, bool remove_trivial_summands, bool remove_singleton_sorts)
void lpsinfo(const std::string &input_filename, const std::string &input_file_message)
void parse_lps< stochastic_specification >(std::istream &from, stochastic_specification &result)
Parses a stochastic linear process specification from an input stream.
void lpsrewr(const std::string &input_filename, const std::string &output_filename, const data::rewriter::strategy rewrite_strategy, const lps_rewriter_type rewriter_type)
std::string pp_with_summand_numbers(const stochastic_specification &x)
std::size_t ceil_log2(std::size_t n)
std::string trim_copy(const std::string &text)
Remove all trailing and leading spaces from the input.
A class that takes a linear process specification and checks all tau-summands of that LPS for conflue...
std::size_t operator()(const atermpp::detail::reference_aterm< T > &t) const