mCRL2
Loading...
Searching...
No Matches
pressolve.h
Go to the documentation of this file.
1// Author(s): Jan Friso Groote. Based on pbessolve.h by Wieger Wesselink; Threads are added by Jan Friso Groote
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 pressolve.h
10/// \brief This tool transforms an .lps file into a labelled transition system.
11/// Optionally, it can be run with multiple treads.
12
13#ifndef MCRL2_PRES_TOOLS_PRESSOLVE_H
14#define MCRL2_PRES_TOOLS_PRESSOLVE_H
15
16#include "mcrl2/utilities/input_output_tool.h"
17#include "mcrl2/data/rewriter_tool.h"
18// #include "mcrl2/lps/detail/lps_io.h"
19#include "mcrl2/pres/pres_input_tool.h"
20#include "mcrl2/pres/detail/pres_io.h"
21#include "mcrl2/pres/pressolve_options.h"
22#include "mcrl2/pres/normalize.h"
23#include "mcrl2/pres/detail/instantiate_global_variables.h"
24#include "mcrl2/pres/pres2res.h"
25#include "mcrl2/pres/ressolve_gauss_elimination.h"
26#include "mcrl2/pres/ressolve_numerical.h"
27#include "mcrl2/pres/ressolve_numerical_directed.h"
28
29using namespace mcrl2;
30using namespace mcrl2::pres_system;
31using namespace mcrl2::utilities::tools;
32using mcrl2::pres_system::tools::pres_input_tool;
33using mcrl2::data::tools::rewriter_tool;
34using mcrl2::utilities::tools::input_tool;
35
36// TODO: put this code in the utilities library?
37inline std::string file_extension(const std::string& filename)
38{
39 std::size_t pos = filename.find_last_of('.');
40 if (pos == std::string::npos)
41 {
42 return "";
43 }
44 return filename.substr(pos + 1);
45}
46
49{
50 protected:
52
54 std::string lpsfile;
55
56 void add_options(utilities::interface_description& desc) override
57 {
58 super::add_options(desc);
59 desc.add_hidden_option("no-remove-unused-rewrite-rules",
60 "do not remove unused rewrite rules. ", 'u');
61 desc.add_hidden_option(
62 "no-replace-constants-by-variables",
63 "Do not move constant expressions to a substitution.");
64 desc.add_option("algorithm", utilities::make_enum_argument<pres_system::solution_algorithm>("NAME")
68 "select the algorithm NAME to solve the res after it is generated.",'a');
69 desc.add_option("precision", utilities::make_mandatory_argument("NUM"),
70 "provide an answer within precision 10^-precision. [AS IT STANDS THIS IS THE NOW THE DIFFERENCE BETWEEN TWO ITERATIONS]", 'p');
71 }
72
73 void parse_options(const utilities::command_line_parser& parser) override
74 {
75 super::parse_options(parser);
76
78 !parser.has_option("no-replace-constants-by-variables");
80 !parser.has_option("no-remove-unused-rewrite-rules");
81 options.rewrite_strategy = rewrite_strategy();
82
83
84 if (parser.has_option("file"))
85 {
86 std::string filename = parser.option_argument("file");
87 if (file_extension(filename) == "lps")
88 {
89 lpsfile = filename;
90 }
91 }
92
93 if (parser.has_option("algorithm"))
94 {
95 options.algorithm = parse_algorithm(parser.option_argument("algorithm"));
96 }
97
98 if (parser.has_option("precision"))
99 {
101 {
102 throw mcrl2::runtime_error("Option --precision (-p) can only be used in combination with --algorithm=numerical or --algorithm=numerical_directed.");
103 }
104 try
105 {
106 options.precision = std::stol(parser.option_argument("precision"));
107 }
108 catch (...)
109 {
110 throw mcrl2::runtime_error("The argument of --precision (-p) is not a valid number.");
111 }
112 if (options.precision>=static_cast<std::size_t>(-std::numeric_limits<double>::min_exponent))
113 {
114 throw mcrl2::runtime_error("Precision " + std::to_string(options.precision) + " is too large. ");
115 }
116 }
117 }
118
120 {
121 return {pres_system::pres_format_internal()};
122 }
123
125 {
126 std::set<data::function_symbol> used_functions = pres_system::find_function_symbols(presspec);
127 used_functions.insert(data::less(data::sort_real::real_()));
128 used_functions.insert(data::sort_real::divides(data::sort_real::real_(),data::sort_real::real_()));
129 used_functions.insert(data::sort_real::times(data::sort_real::real_(),data::sort_real::real_()));
130 used_functions.insert(data::sort_real::plus(data::sort_real::real_(),data::sort_real::real_()));
131 used_functions.insert(data::sort_real::minus(data::sort_real::real_(),data::sort_real::real_()));
132 used_functions.insert(data::sort_real::minimum(data::sort_real::real_(),data::sort_real::real_()));
133 used_functions.insert(data::sort_real::maximum(data::sort_real::real_(),data::sort_real::real_()));
134
135 return data::rewriter(presspec.data(),
136 data::used_data_equation_selector(presspec.data(), used_functions, presspec.global_variables(), !options.remove_unused_rewrite_rules),
137 options.rewrite_strategy);
138 }
139
140
141 public:
142 pressolve_tool(const std::string& toolname)
143 : super(toolname,
144 "Jan Friso Groote",
145 "Generate a BES from a PRES and solve it. ",
146 "Solves (P)BES from INFILE. "
147 "If INFILE is not present, stdin is used. "
148 "The PRES is first instantiated into a parity game, "
149 "which is then solved using Zielonka's algorithm. "
150 "It supports the generation of a witness or counter "
151 "example for the property encoded by the PRES.")
152 {
153 }
154
156 {
157 pres_system::pres presspec = pres_system::detail::load_pres(input_filename());
159
160 // mCRL2log(log::debug) << "INPUT PRES\n" << presspec << "\n";
161 data::mutable_map_substitution<> sigma;
162 sigma = pres_system::detail::instantiate_global_variables(presspec);
163 pres_system::detail::replace_global_variables(presspec, sigma);
164
165 pres_system::normalize(presspec);
166 // mCRL2log(log::debug) << "RESULTING PRES\n" << presspec << "\n";
167
168 mCRL2log(log::verbose) << "Generating RES..." << std::endl;
169 timer().start("instantiation");
170 pres2res_algorithm pres2res(options,presspec,m_R);
171 pres resulting_res = pres2res.run();
172 timer().finish("instantiation");
173
174 // mCRL2log(log::debug) << "RESULTING RES\n" << resulting_res << "\n";
175
176 mCRL2log(log::verbose) << "Solving RES..." << std::endl;
177 timer().start("solving");
178
180 {
182 pres_expression result = solver.run();
183 std::cout << result << std::endl;
184 }
186 {
188 double result = solver.run();
189 std::cout << std::setprecision(options.precision) << result << std::endl;
190 }
192 {
194 double result = solver.run();
195 std::cout << std::setprecision(options.precision) << result << std::endl;
196 }
197 timer().finish("solving");
198 return true;
199 }
200};
201
202#endif // MCRL2_PRES_TOOLS_PRESSOLVE_H
Rewriter that operates on data expressions.
Definition rewriter.h:81
Base class for tools that use a rewriter.
logger(const log_level_t l)
Default constructor.
Definition logger.h:164
A simple algorithm that takes a pres, instantiates it into a res, without parameterized variables,...
Definition pres2res.h:58
pres2res_algorithm(const pressolve_options &options, const pres &input_pres, enumerate_quantifiers_rewriter &R)
Definition pres2res.h:71
parameterized boolean equation system
Definition pres.h:59
An algorithm that takes a res, i.e. a pres with propositional variables without parameters and solves...
ressolve_by_gauss_elimination_algorithm(const pressolve_options &options, const pres &input_pres)
ressolve_by_numerical_iteration_directed(const pressolve_options &options, const pres &input_pres)
ressolve_by_numerical_iteration(const pressolve_options &options, const pres &input_pres)
Base class for filter tools that take a pres as input.
Standard exception class for reporting runtime errors.
Definition exception.h:27
Base class for tools that take a file as input.
Definition input_tool.h:28
void parse_options(const utilities::command_line_parser &parser) override
Definition pressolve.h:73
std::set< utilities::file_format > available_input_formats() const override
Definition pressolve.h:119
bool run() override
Definition pressolve.h:155
std::string lpsfile
Definition pressolve.h:54
pressolve_options options
Definition pressolve.h:53
pressolve_tool(const std::string &toolname)
Definition pressolve.h:142
void add_options(utilities::interface_description &desc) override
Definition pressolve.h:56
data::rewriter construct_rewriter(const pres &presspec)
Definition pressolve.h:124
rewriter_tool< pres_input_tool< input_tool > > super
Definition pressolve.h:51
#define mCRL2log(LEVEL)
mCRL2log(LEVEL) provides the stream used to log.
Definition logger.h:391
Namespace for all data library functionality.
Definition data.cpp:22
@ verbose
Definition logger.h:37
pres load_pres(const std::string &filename)
Loads a PRES from filename, or from stdin if filename equals "".
Definition io.cpp:283
The main namespace for the PRES library.
The namespace for command line tool classes.
A class that takes a linear process specification and checks all tau-summands of that LPS for conflue...
enumerate_quantifiers_rewriter(const data::rewriter &R, const data::data_specification &dataspec, bool enumerate_infinite_sorts=true)
std::size_t operator()(const atermpp::detail::reference_aterm< T > &t) const
std::string file_extension(const std::string &filename)
Definition pbessolve.h:34