Storm
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, "Spot could not parse formula: " << prefixLtl << ": " << errorMsg.str());
25 }
26 spot::formula spotFormula = spotPrefixLtl.f;
27
28 // Request a deterministic, complete automaton with state-based acceptance
29 spot::translator trans = spot::translator();
30 trans.set_type(spot::postprocessor::Generic);
31 trans.set_pref(spot::postprocessor::Deterministic | spot::postprocessor::SBAcc | spot::postprocessor::Complete);
32 STORM_LOG_INFO("Construct deterministic automaton for " << spotFormula);
33 auto aut = trans.run(spotFormula);
34
35 if (!(aut->get_acceptance().is_dnf()) && dnf) {
36 STORM_LOG_INFO("Convert acceptance condition " << aut->get_acceptance() << " into DNF...");
37 // Transform the acceptance condition in disjunctive normal form and merge all the Fin-sets of each clause
38 aut = to_generalized_rabin(aut, true);
39 }
40
41 STORM_LOG_INFO("The deterministic automaton has acceptance condition: " << aut->get_acceptance());
42
43 STORM_LOG_INFO(aut->get_acceptance());
44
45 std::stringstream autStream;
46 // Print reachable states in HOA format, implicit edges (i), state-based acceptance (s)
47 spot::print_hoa(autStream, aut, "is");
48
50
51 return da;
52
53#else
54 (void)f;
55 (void)dnf;
56 STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "Storm is compiled without Spot support.");
57#endif
58}
59
60std::shared_ptr<DeterministicAutomaton> LTL2DeterministicAutomaton::ltl2daExternalTool(storm::logic::Formula const& f, std::string ltl2daTool) {
61 std::string prefixLtl = f.toPrefixString();
62
63 STORM_LOG_INFO("Calling external LTL->DA tool: " << ltl2daTool << " '" << prefixLtl << "' da.hoa");
64
65 pid_t pid;
66
67 pid = fork();
68 STORM_LOG_THROW(pid >= 0, storm::exceptions::FileIoException, "Could not construct deterministic automaton, fork failed");
69
70 if (pid == 0) {
71 // we are in the child process
72 if (execlp(ltl2daTool.c_str(), ltl2daTool.c_str(), prefixLtl.c_str(), "da.hoa", NULL) < 0) {
73 std::cerr << "ERROR: exec failed: " << strerror(errno) << '\n';
74 std::exit(1);
75 }
76 // never reached
77 return std::shared_ptr<DeterministicAutomaton>();
78 } else { // in the parent
79 int status;
80
81 // wait for completion
82 while (wait(&status) != pid);
83
84 int rv;
85 if (WIFEXITED(status)) {
86 rv = WEXITSTATUS(status);
87 } else {
88 STORM_LOG_THROW(false, storm::exceptions::FileIoException, "Could not construct deterministic automaton: process aborted");
89 }
90 STORM_LOG_THROW(rv == 0, storm::exceptions::FileIoException,
91 "Could not construct deterministic automaton for " << prefixLtl << ", return code = " << rv);
92
93 STORM_LOG_INFO("Reading automaton for " << prefixLtl << " from da.hoa");
94
96 }
97}
98
99} // namespace automata
100
101} // 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:582
#define STORM_LOG_INFO(message)
Definition logging.h:29
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:30
LabParser.cpp.
Definition cli.cpp:18