mCRL2
Loading...
Searching...
No Matches
tools.cpp
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//
10
11#include "mcrl2/lps/binary.h"
12#include "mcrl2/lps/constelm.h"
15#include "mcrl2/lps/io.h"
16#include "mcrl2/lps/parelm.h"
17#include "mcrl2/lps/parse.h"
18#include "mcrl2/lps/sumelm.h"
19#include "mcrl2/lps/suminst.h"
20#include "mcrl2/lps/tools.h"
21#include "mcrl2/lps/untime.h"
24
25namespace mcrl2
26{
27
28namespace lps
29{
30
31void lpsbinary(const std::string& input_filename,
32 const std::string& output_filename,
33 const std::string& parameter_selection)
34{
36 load_lps(spec, input_filename);
37 data::rewriter r(spec.data());
38
40 save_lps(spec, output_filename);
41}
42
43void lpsconstelm(const std::string& input_filename,
44 const std::string& output_filename,
45 data::rewriter::strategy rewrite_strategy,
46 bool instantiate_free_variables,
47 bool ignore_conditions,
50 )
51{
53 load_lps(spec, input_filename);
54 mcrl2::data::rewriter R(spec.data(), rewrite_strategy);
56
57 // preprocess: remove single element sorts
59 {
60 algorithm.remove_singleton_sorts();
61 }
62
63 // apply constelm
64 algorithm.run(instantiate_free_variables, ignore_conditions);
65
66 // postprocess: remove trivial summands
68 {
69 algorithm.remove_trivial_summands();
70 }
71
72 save_lps(spec, output_filename);
73}
74
75void lpsinfo(const std::string& input_filename,
76 const std::string& input_file_message
77 )
78{
80 load_lps(spec, input_filename);
82 std::cout << input_file_message << "\n\n";
83 std::cout << info.info();
84}
85
86bool lpsinvelm(const std::string& input_filename,
87 const std::string& output_filename,
88 const std::string& invariant_filename,
89 const std::string& dot_file_name,
90 data::rewriter::strategy rewrite_strategy,
92 const bool no_check,
93 const bool no_elimination,
94 const bool simplify_all,
95 const bool all_violations,
96 const bool counter_example,
97 const bool path_eliminator,
98 const bool apply_induction,
99 const int time_limit)
100{
102 data::data_expression invariant;
103
104 load_lps(spec, input_filename);
105
106 if (!invariant_filename.empty())
107 {
108 std::ifstream instream(invariant_filename.c_str());
109
110 if (!instream.is_open())
111 {
112 throw mcrl2::runtime_error("cannot open input file '" + invariant_filename + "'");
113 }
114
115 mCRL2log(log::verbose) << "parsing input file '" << invariant_filename << "'..." << std::endl;
116
118 invariant = data::parse_data_expression(instream, parameters, spec.data());
119
120 instream.close();
121 }
122 else
123 {
124 throw mcrl2::runtime_error("A file containing an invariant must be specified using the option --invariant=INVFILE.");
125 }
126
127 if (no_check)
128 {
129 mCRL2log(log::warning) << "The invariant is not checked; it may not hold for this LPS." << std::endl;
130 }
131 else
132 {
134 rewrite_strategy,
135 time_limit,
136 path_eliminator,
137 solver_type,
138 apply_induction,
139 counter_example,
140 all_violations,
141 dot_file_name);
142
143 if (!v_invariant_checker.check_invariant(invariant))
144 {
145 return false; // The invariant was checked and found invalid.
146 }
147 }
148
150 rewrite_strategy,
151 time_limit,
152 path_eliminator,
153 solver_type,
154 apply_induction,
155 simplify_all);
156 algorithm.run(invariant, !no_elimination);
157 save_lps(spec, output_filename);
158 return true;
159}
160
161void lpsparelm(const std::string& input_filename,
162 const std::string& output_filename
163 )
164{
166 load_lps(spec, input_filename);
167 lps::parelm(spec, true);
168 save_lps(spec, output_filename);
169}
170
171void lpspp(const std::string& input_filename,
172 const std::string& output_filename,
173 bool print_summand_numbers,
175 )
176{
178 load_lps(spec, input_filename);
179
180 mCRL2log(log::verbose) << "printing LPS from "
181 << (input_filename.empty()?"standard input":input_filename)
182 << " to " << (output_filename.empty()?"standard output":output_filename)
183 << " in the " << core::pp_format_to_string(format) << " format" << std::endl;
184
185 std::string text;
186 if (format == core::print_internal)
187 {
188 text = pp(specification_to_aterm(spec));
189 }
190 else
191 {
192 text = print_summand_numbers ? lps::pp_with_summand_numbers(spec) : lps::pp(spec);
193 }
194 if (output_filename.empty())
195 {
196 std::cout << text;
197 }
198 else
199 {
200 std::ofstream output_stream(output_filename.c_str());
201 if (output_stream)
202 {
203 output_stream << text;
204 output_stream.close();
205 }
206 else
207 {
208 throw mcrl2::runtime_error("could not open output file " + output_filename + " for writing");
209 }
210 }
211}
212
213void lpsrewr(const std::string& input_filename,
214 const std::string& output_filename,
215 const data::rewriter::strategy rewrite_strategy,
216 const lps_rewriter_type rewriter_type
217 )
218{
220 load_lps(spec, input_filename);
221 switch (rewriter_type)
222 {
223 case simplify:
224 {
225 mcrl2::data::rewriter R(spec.data(), rewrite_strategy);
226 lps::rewrite(spec, R);
227 break;
228 }
230 {
232 break;
233 }
235 {
236 mcrl2::data::rewriter R(spec.data(), rewrite_strategy);
238 break;
239 }
240 }
243 save_lps(spec, output_filename);
244}
245
246void lpssumelm(const std::string& input_filename,
247 const std::string& output_filename,
248 const bool decluster)
249{
251 load_lps(spec, input_filename);
252
254
255 mCRL2log(log::debug) << "Sum elimination completed, saving to " << output_filename << std::endl;
256 save_lps(spec, output_filename);
257}
258
259void lpssuminst(const std::string& input_filename,
260 const std::string& output_filename,
261 const data::rewriter::strategy rewrite_strategy,
262 const std::string& sorts_string,
263 const bool finite_sorts_only,
264 const bool tau_summands_only)
265{
267 load_lps(spec, input_filename);
268 std::set<data::sort_expression> sorts;
269
270 // Determine set of sorts to be expanded
271 if(!sorts_string.empty())
272 {
273 std::vector<std::string> parts = utilities::split(utilities::remove_whitespace(sorts_string), ",");
274 for (const std::string& part : parts)
275 {
276 sorts.insert(data::parse_sort_expression(part, spec.data()));
277 }
278 }
279 else if (finite_sorts_only)
280 {
281 sorts = lps::finite_sorts(spec.data());
282 }
283 else
284 {
285 const std::set<data::sort_expression>& sort_set=spec.data().sorts();
286 sorts = std::set<data::sort_expression>(sort_set.begin(),sort_set.end());
287 }
288
289 mCRL2log(log::verbose) << "expanding summation variables of sorts: " << data::pp(sorts) << std::endl;
290
291 mcrl2::data::rewriter r(spec.data(), rewrite_strategy);
293 save_lps(spec, output_filename);
294}
295
296void lpsuntime(const std::string& input_filename,
297 const std::string& output_filename,
298 const bool add_invariants,
299 const bool apply_fourier_motzkin,
300 const data::rewriter::strategy rewrite_strategy
301 )
302{
304 load_lps(spec, input_filename);
305 data::rewriter rewr(spec.data(),rewrite_strategy);
306 untime_algorithm<stochastic_specification>(spec, add_invariants, apply_fourier_motzkin, rewr).run();
307 save_lps(spec, output_filename);
308}
309
310void txt2lps(const std::string& input_filename,
311 const std::string& output_filename
312 )
313{
315 std::ifstream ifs(input_filename);
316 if (!ifs.good())
317 {
318 throw mcrl2::runtime_error("Could not open file " + input_filename + ".");
319 }
320 parse_lps(ifs, spec);
321 save_lps(spec, output_filename);
322}
323
324} // namespace lps
325
326} // namespace mcrl2
The binary algorithm.
rewrite_strategy strategy
The rewrite strategies of the rewriter.
Definition rewriter.h:44
Rewriter that operates on data expressions.
Definition rewriter.h:81
const std::set< sort_expression > & sorts() const
Gets the normalised sort declarations including those that are system defined. This is the set with a...
Algorithm class that can be used to apply the binary algorithm.
Definition binary.h:45
void run()
Apply the algorithm to the specification passed in the constructor.
Definition binary.h:405
Algorithm class for elimination of constant parameters.
Definition constelm.h:26
void run(bool instantiate_global_variables=false, bool ignore_conditions=false)
Runs the constelm algorithm.
Definition constelm.h:259
bool check_invariant(const data::data_expression &a_invariant)
precondition: the argument passed as parameter a_invariant is a valid expression in internal mCRL2 fo...
void remove_singleton_sorts()
Removes parameters with a singleton sort.
void remove_trivial_summands()
Removes summands with condition equal to false.
Stores the following properties of a linear process specification:
void run(const data::data_expression &invariant, bool apply_prover)
const data::variable_list & process_parameters() const
Returns the sequence of process parameters.
const LinearProcess & process() const
Returns the linear process of the specification.
const data::data_specification & data() const
Returns the data specification.
Class implementing the sum elimination lemma.
Definition sumelm.h:33
void run()
Apply the sum elimination lemma to all summands in the specification.
Definition sumelm.h:58
void run(const SummandListType &list, Container &result)
Definition suminst.h:154
Standard exception class for reporting runtime errors.
Definition exception.h:27
Interface to class invariant_eliminator.
#define mCRL2log(LEVEL)
mCRL2log(LEVEL) provides the stream used to log.
Definition logger.h:391
Add your file description here.
IO routines for linear process specifications.
The parelm algorithm.
add your file description here.
add your file description here.
print_format_type
print_format_type represents the available pretty print formats
std::string pp_format_to_string(const print_format_type pp_format)
Print string representation of pretty print format.
smt_solver_type
The enumeration type smt_solver_type enumerates all available SMT solvers.
Definition solver_type.h:27
data_expression parse_data_expression(std::istream &in, const VariableContainer &variables, const data_specification &dataspec=detail::default_specification(), bool type_check=true, bool translate_user_notation=true, bool normalize_sorts=true)
Parses and type checks a data expression.
Definition parse.h:276
sort_expression parse_sort_expression(std::istream &in, const data_specification &data_spec=detail::default_specification())
Parses and type checks a sort expression.
Definition parse.h:380
std::string pp(const abstraction &x)
Definition data.cpp:39
@ warning
Definition logger.h:34
@ verbose
Definition logger.h:37
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
std::string pp_with_summand_numbers(const specification &x)
Definition lps.cpp:74
void txt2lps(const std::string &input_filename, const std::string &output_filename)
Definition tools.cpp:310
void parse_lps(std::istream &, Specification &)
Definition parse.h:159
void save_lps(const Specification &spec, std::ostream &stream, const std::string &target="")
Save an LPS in the format specified.
Definition io.h:42
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 action_summand &x)
Definition lps.cpp:26
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
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 one_point_condition_rewrite(T &x, const DataRewriter &R, typename std::enable_if<!std::is_base_of< atermpp::aterm, T >::value >::type *=nullptr)
Applies the one point condition rewriter to all embedded data expressions in an object x.
void lpsparelm(const std::string &input_filename, const std::string &output_filename)
Definition tools.cpp:161
atermpp::aterm specification_to_aterm(const specification_base< LinearProcess, InitialProcessExpression > &spec)
Conversion to aterm.
void lpsbinary(const std::string &input_filename, const std::string &output_filename, const std::string &parameter_selection)
Definition tools.cpp:31
void parelm(Specification &spec, bool variant1=true)
Removes unused parameters from a linear process specification.
Definition parelm.h:273
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 rewrite(T &x, Rewriter R, typename std::enable_if<!std::is_base_of< atermpp::aterm, T >::value >::type *=nullptr)
Definition rewrite.h:27
void remove_singleton_sorts(Specification &spec)
Removes parameters with a singleton sort from a linear process specification.
Definition remove.h:211
data::assignment_list remove_redundant_assignments(const data::assignment_list &assignments, const data::variable_list &do_not_remove)
Removes assignments of the form x := x from v for variables x that are not contained in do_not_remove...
Definition remove.h:229
void lpsrewr(const std::string &input_filename, const std::string &output_filename, const data::rewriter::strategy rewrite_strategy, const lps::lps_rewriter_type rewriter_type)
Definition tools.cpp:213
void load_lps(Specification &spec, std::istream &stream, const std::string &source="")
Load LPS from file.
Definition io.h:54
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
void one_point_rule_rewrite(T &x, typename std::enable_if<!std::is_base_of< atermpp::aterm, T >::value >::type *=nullptr)
Applies the one point rule rewriter to all embedded data expressions in an object x.
void lpsinfo(const std::string &input_filename, const std::string &input_file_message)
Definition tools.cpp:75
void remove_trivial_summands(Specification &spec)
Removes summands with condition equal to false from a linear process specification.
Definition remove.h:199
std::string remove_whitespace(const std::string &text)
Removes whitespace from a string.
std::vector< std::string > split(const std::string &line, const std::string &separators)
Split the text.
A class that takes a linear process specification and checks all tau-summands of that LPS for conflue...
Definition indexed_set.h:72
Rewriter for LPSs that takes equalities of the form p_i == c, where p_i is a process parameter,...
A property map containing properties of an LPS specification.
Provides an implementation of the sum elimination lemma, as well as the removal of unused summation v...
Instantiate summation variables.
Removes time from a linear process.