Storm 1.14.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
LTL2DeterministicAutomaton.cpp
Go to the documentation of this file.
4
10
11#include <sys/wait.h>
12
13namespace storm {
14namespace automata {
15
16std::shared_ptr<DeterministicAutomaton> LTL2DeterministicAutomaton::ltl2daSpot(storm::logic::Formula const& f, bool dnf) {
17#ifdef STORM_HAVE_SPOT
18 std::string prefixLtl = f.toPrefixString();
19
20 spot::parsed_formula spotPrefixLtl = spot::parse_prefix_ltl(prefixLtl);
21 if (!spotPrefixLtl.errors.empty()) {
22 std::ostringstream errorMsg;
23 spotPrefixLtl.format_errors(errorMsg);
24 STORM_LOG_THROW(false, storm::exceptions::ExpressionEvaluationException,
25 "Spot could not parse formula: " << prefixLtl << ": " << errorMsg.str() << ".");
26 }
27 spot::formula spotFormula = spotPrefixLtl.f;
28
29 // Request a deterministic, complete automaton with state-based acceptance
30 spot::translator trans = spot::translator();
31 trans.set_type(spot::postprocessor::Generic);
32 trans.set_pref(spot::postprocessor::Deterministic | spot::postprocessor::SBAcc | spot::postprocessor::Complete);
33 STORM_LOG_INFO("Construct deterministic automaton for " << spotFormula);
34 auto aut = trans.run(spotFormula);
35
36 if (!(aut->get_acceptance().is_dnf()) && dnf) {
37 STORM_LOG_INFO("Convert acceptance condition " << aut->get_acceptance() << " into DNF...");
38 // Transform the acceptance condition in disjunctive normal form and merge all the Fin-sets of each clause
39 aut = to_generalized_rabin(aut, true);
40 }
41
42 STORM_LOG_INFO("The deterministic automaton has acceptance condition: " << aut->get_acceptance());
43
44 STORM_LOG_INFO(aut->get_acceptance());
45
46 std::stringstream autStream;
47 // Print reachable states in HOA format, implicit edges (i), state-based acceptance (s)
48 spot::print_hoa(autStream, aut, "is");
49
51
52 return da;
53
54#else
55 (void)f;
56 (void)dnf;
57 STORM_LOG_THROW(false, storm::exceptions::MissingLibraryException, "Storm is compiled without Spot support.");
58#endif
59}
60
61std::shared_ptr<DeterministicAutomaton> LTL2DeterministicAutomaton::ltl2daExternalTool(storm::logic::Formula const& f, std::string ltl2daTool) {
62 std::string prefixLtl = f.toPrefixString();
63
64 STORM_LOG_INFO("Calling external LTL->DA tool: " << ltl2daTool << " '" << prefixLtl << "' da.hoa");
65
66 pid_t pid;
67
68 pid = fork();
69 STORM_LOG_THROW(pid >= 0, storm::exceptions::FileIoException, "Could not construct deterministic automaton, fork failed.");
70
71 if (pid == 0) {
72 // we are in the child process
73 if (execlp(ltl2daTool.c_str(), ltl2daTool.c_str(), prefixLtl.c_str(), "da.hoa", NULL) < 0) {
74 std::cerr << "ERROR: exec failed: " << strerror(errno) << '\n';
75 std::exit(1);
76 }
77 // never reached
78 return std::shared_ptr<DeterministicAutomaton>();
79 } else { // in the parent
80 int status;
81
82 // wait for completion
83 while (wait(&status) != pid) {
84 // Intentionally left emtpty
85 }
86
87 int rv;
88 if (WIFEXITED(status)) {
89 rv = WEXITSTATUS(status);
90 } else {
91 STORM_LOG_THROW(false, storm::exceptions::FileIoException, "Could not construct deterministic automaton: process aborted.");
92 }
93 STORM_LOG_THROW(rv == 0, storm::exceptions::FileIoException,
94 "Could not construct deterministic automaton for " << prefixLtl << ", return code = " << rv << ".");
95
96 STORM_LOG_INFO("Reading automaton for " << prefixLtl << " from da.hoa");
97
99 }
100}
101
102} // namespace automata
103
104} // namespace storm
static DeterministicAutomaton::ptr parseFromFile(const std::string &filename)
std::shared_ptr< DeterministicAutomaton > ptr
static DeterministicAutomaton::ptr parse(std::istream &in)
static std::shared_ptr< DeterministicAutomaton > ltl2daExternalTool(storm::logic::Formula const &f, std::string ltl2daTool)
Converts an LTL formula into a deterministic omega-automaton using an external LTL2DA tool.
static std::shared_ptr< DeterministicAutomaton > ltl2daSpot(storm::logic::Formula const &f, bool dnf)
Converts an LTL formula into a deterministic omega-automaton using the internal LTL2DA tool "Spot".
std::string toPrefixString() const
Definition Formula.cpp:597
#define STORM_LOG_INFO(message)
Definition logging.h:27
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:28