mCRL2
Loading...
Searching...
No Matches
parameter_selection.h
Go to the documentation of this file.
1// Author(s): Wieger Wesselink, Thomas Neele
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/lps/detail/parameter_selection.h
10/// \brief
11
12#ifndef MCRL2_LPS_DETAIL_PARAMETER_SELECTION_H
13#define MCRL2_LPS_DETAIL_PARAMETER_SELECTION_H
14
15#include "mcrl2/core/detail/print_utility.h"
16#include "mcrl2/data/parse.h"
17#include <regex>
18
19namespace mcrl2::lps::detail
20{
21
22/// \brief Returns true if the selection name:type matches with the variable v.
23inline
24bool match_selection(const data::variable& v, const std::string& name, const std::string& type, const data::data_specification& data_spec)
25{
26 if (name != "*" && core::identifier_string(name) != v.name())
27 {
28 return false;
29 }
30 return type == "*" || data::parse_sort_expression(type, data_spec) == v.sort();
31}
32
33/// \brief Find parameter declarations that match a given string.
34template <typename OutputIterator>
35inline
41 )
42{
43 std::set<data::variable> result;
44 for (const data::variable& v: params)
45 {
46 for (const auto& [name, type]: selections)
47 {
48 if (match_selection(v, name, type, dataspec))
49 {
50 *o = v;
51 }
52 }
53 }
54 return std::vector<data::variable>(result.begin(), result.end());
55}
56
57/// \brief Parses parameter selection for finite pbesinst algorithm
58inline
59std::vector<data::variable> parse_lps_parameter_selection(const data::variable_list& params, const data::data_specification& dataspec, const std::string& text)
60{
61 std::vector<data::variable> result;
62
63 std::string line = utilities::trim_copy(text);
64 if (line.empty())
65 {
66 throw mcrl2::runtime_error("The parameter selection argument is empty.");
67 }
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, ","))
71 {
72 std::match_results<std::string::const_iterator> what;
73 if (!std::regex_match(var_sort, what, sre))
74 {
75 mCRL2log(log::warning) << "Ignoring " << var_sort << " since it does not follow the necessary format (NAME:SORT)." << std::endl;
76 continue;
77 }
78
79 selections.push_back(std::make_pair(what[1], what[2]));
80 }
81
82 find_matching_parameters(params, dataspec, selections, std::inserter(result, result.end()));
83
84 // sort the parameters in result according to their position in params
85 std::map<data::variable, std::size_t> m;
86 std::size_t index = 0;
87 for (const data::variable& v: params)
88 {
89 m[v] = index++;
90 }
91 std::sort(result.begin(), result.end(), [&](const data::variable& x, const data::variable& y) { return m[x] < m[y]; });
92
93 return result;
94}
95
96} // namespace mcrl2::lps::detail
97
98#endif // MCRL2_LPS_DETAIL_PARAMETER_SELECTION_H
aterm_string(const std::string &s)
Constructor that allows construction from a string.
bool operator==(const unprotected_aterm_core &t) const
Comparison operator.
Definition aterm_core.h:83
bool operator!=(const unprotected_aterm_core &t) const
Inequality operator on two unprotected aterms.
Definition aterm_core.h:92
Rewriter that operates on data expressions.
Definition rewriter.h:81
Identifier generator that stores the identifiers of the context in a set. Using the operator()() and ...
\brief A data variable
Definition variable.h:28
const core::identifier_string & name() const
Definition variable.h:38
const sort_expression & sort() const
Definition variable.h:43
logger(const log_level_t l)
Default constructor.
Definition logger.h:164
LPS summand containing a multi-action.
Algorithm class that can be used to apply the binary algorithm.
Definition binary.h:45
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.
Definition binary.h:298
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.
Definition binary.h:77
binary_algorithm(Specification &spec, DataRewriter &r, const std::string parameter_selection="")
Constructor for binary algorithm.
Definition binary.h:395
void update_deadlock_summand(deadlock_summand &s)
Update a deadlock summand with the new Boolean parameters.
Definition binary.h:370
detail::lps_algorithm< Specification > super
Definition binary.h:47
std::map< data::variable, std::vector< data::data_expression > > m_enumerated_elements
Mapping of variables to all values they can be assigned.
Definition binary.h:62
stochastic_process_initializer update_initial_process(const data::variable_list &parameters, const stochastic_process_initializer &init)
Definition binary.h:381
Specification::process_type process_type
Definition binary.h:48
data::set_identifier_generator m_if_trees_generator
Contains the names of variables appearing in rhs of m_if_trees.
Definition binary.h:68
const std::string m_parameter_selection
Definition binary.h:56
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...
Definition binary.h:160
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.
Definition binary.h:236
void update_action_summand(action_summand &s)
Update an action summand with the new Boolean parameters.
Definition binary.h:355
std::set< data::variable > select_parameters(const std::string parameter_selection) const
Determine which variables should be replaced, based on parameter_selection.
Definition binary.h:119
void run()
Apply the algorithm to the specification passed in the constructor.
Definition binary.h:405
process_type::action_summand_type action_summand_type
Definition binary.h:49
data::mutable_map_substitution m_if_trees
Mapping of variables to corresponding if-tree.
Definition binary.h:65
process_initializer update_initial_process(const data::variable_list &parameters, const process_initializer &init)
Definition binary.h:376
DataRewriter m_rewriter
Rewriter.
Definition binary.h:54
std::map< data::variable, std::vector< data::variable > > m_new_parameters
Mapping of finite variables to boolean vectors.
Definition binary.h:59
void update_action_summand(stochastic_action_summand &s)
Update an action summand with the new Boolean parameters.
Definition binary.h:363
data::enumerator_list_element_with_substitution enumerator_element
Definition binary.h:46
data::enumerator_identifier_generator m_id_generator
Identifier generator for the enumerator.
Definition binary.h:71
Algorithm class for elimination of constant parameters.
Definition constelm.h:26
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
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 atermpp::aterm &t)
Transform an aterm to an ascii string.
Definition aterm.h:440
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.
Definition solver_type.h:27
Namespace for all data library functionality.
Definition data.cpp:22
std::vector< assignment > assignment_vector
\brief vector of assignments
Definition assignment.h:149
std::vector< variable > variable_vector
\brief vector of variables
Definition variable.h:89
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.
Definition parse.h:399
atermpp::term_list< assignment > assignment_list
\brief list of assignments
Definition assignment.h:146
std::string pp(const data::sort_expression_vector &x)
Definition data.cpp:26
@ warning
Definition logger.h:34
@ verbose
Definition logger.h:37
std::vector< data::variable > find_matching_parameters(const data::variable_list &params, 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.
Definition constelm.h:21
void lpspp(const std::string &input_filename, const std::string &output_filename, bool print_summand_numbers, core::print_format_type format)
Definition tools.cpp:171
void lpssumelm(const std::string &input_filename, const std::string &output_filename, const bool decluster)
Definition tools.cpp:246
void txt2lps(const std::string &input_filename, const std::string &output_filename)
Definition tools.cpp:310
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)
Definition tools.cpp:296
std::string pp(const lps::stochastic_specification &x)
Definition lps.cpp:37
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)
Definition tools.cpp:259
std::size_t nr_of_booleans_for_elements(std::size_t n)
Definition binary.h:27
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)
Definition tools.cpp:86
void lpsparelm(const std::string &input_filename, const std::string &output_filename)
Definition tools.cpp:161
void lpsbinary(const std::string &input_filename, const std::string &output_filename, const std::string &parameter_selection)
Definition tools.cpp:31
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)
Definition tools.cpp:43
void lpsinfo(const std::string &input_filename, const std::string &input_file_message)
Definition tools.cpp:75
void parse_lps< stochastic_specification >(std::istream &from, stochastic_specification &result)
Parses a stochastic linear process specification from an input stream.
Definition parse.h:183
void lpsrewr(const std::string &input_filename, const std::string &output_filename, const data::rewriter::strategy rewrite_strategy, const lps_rewriter_type rewriter_type)
Definition tools.cpp:213
std::string pp_with_summand_numbers(const stochastic_specification &x)
Definition lps.cpp:83
std::size_t ceil_log2(std::size_t n)
Definition math.h:28
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