Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
DeterministicAutomaton.cpp
Go to the documentation of this file.
2
3#include "cpphoafparser/consumer/hoa_intermediate_check_validity.hh"
4#include "cpphoafparser/parser/hoa_parser.hh"
5#include "cpphoafparser/parser/hoa_parser_helper.hh"
6
10#include "storm/io/file.h"
12
13namespace storm {
14namespace automata {
15DeterministicAutomaton::DeterministicAutomaton(APSet apSet, std::size_t numberOfStates, std::size_t initialState, AcceptanceCondition::ptr acceptance)
16 : apSet(apSet), numberOfStates(numberOfStates), initialState(initialState), acceptance(acceptance) {
17 // TODO: this could overflow, add check?
18 edgesPerState = apSet.alphabetSize();
19 numberOfEdges = numberOfStates * edgesPerState;
20 successors.resize(numberOfEdges);
21}
22
24 return initialState;
25}
26
28 return apSet;
29}
30
31std::size_t DeterministicAutomaton::getSuccessor(std::size_t from, APSet::alphabet_element label) const {
32 std::size_t index = from * edgesPerState + label;
33 return successors.at(index);
34}
35
36void DeterministicAutomaton::setSuccessor(std::size_t from, APSet::alphabet_element label, std::size_t successor) {
37 std::size_t index = from * edgesPerState + label;
38 successors.at(index) = successor;
39}
40
42 return numberOfStates;
43}
44
46 return edgesPerState;
47}
48
52
53void DeterministicAutomaton::printHOA(std::ostream& out) const {
54 out << "HOA: v1\n";
55
56 out << "States: " << numberOfStates << "\n";
57
58 out << "Start: " << initialState << "\n";
59
60 out << "AP: " << apSet.size();
61 for (unsigned int i = 0; i < apSet.size(); i++) {
62 out << " " << cpphoafparser::HOAParserHelper::quote(apSet.getAP(i));
63 }
64 out << "\n";
65
66 out << "Acceptance: " << acceptance->getNumberOfAcceptanceSets() << " " << *acceptance->getAcceptanceExpression() << "\n";
67
68 out << "--BODY--" << "\n";
69
70 for (std::size_t s = 0; s < getNumberOfStates(); s++) {
71 out << "State: " << s;
72 out << " {";
73 bool first = true;
74 for (unsigned int i = 0; i < acceptance->getNumberOfAcceptanceSets(); i++) {
75 if (acceptance->getAcceptanceSet(i).get(s)) {
76 if (!first)
77 out << " ";
78 first = false;
79 out << i;
80 }
81 }
82 out << "}\n";
83 for (std::size_t label = 0; label < getNumberOfEdgesPerState(); label++) {
84 out << getSuccessor(s, label) << "\n";
85 }
86 }
87}
88
90 HOAConsumerDA::ptr consumer(new HOAConsumerDA());
91 cpphoafparser::HOAIntermediateCheckValidity::ptr validator(new cpphoafparser::HOAIntermediateCheckValidity(consumer));
92 cpphoafparser::HOAParser::parse(in, validator);
93
94 return consumer->getDA();
95}
96
98 std::ifstream in;
99 storm::io::openFile(filename, in);
100 auto da = parse(in);
102
103 STORM_LOG_INFO("Deterministic automaton from HOA file '" << filename << "' has " << da->getNumberOfStates() << " states, " << da->getAPSet().size()
104 << " atomic propositions and " << *da->getAcceptance()->getAcceptanceExpression()
105 << " as acceptance condition.");
106 return da;
107}
108
109} // namespace automata
110} // namespace storm
std::size_t alphabetSize() const
Definition APSet.cpp:20
const std::string & getAP(unsigned int index) const
Definition APSet.cpp:39
unsigned int size() const
Definition APSet.cpp:16
std::size_t alphabet_element
Definition APSet.h:12
std::shared_ptr< AcceptanceCondition > ptr
static DeterministicAutomaton::ptr parseFromFile(const std::string &filename)
void setSuccessor(std::size_t from, APSet::alphabet_element label, std::size_t successor)
DeterministicAutomaton(APSet apSet, std::size_t numberOfStates, std::size_t initialState, std::shared_ptr< AcceptanceCondition > acceptance)
std::size_t getSuccessor(std::size_t from, APSet::alphabet_element label) const
std::shared_ptr< DeterministicAutomaton > ptr
std::shared_ptr< AcceptanceCondition > getAcceptance() const
static DeterministicAutomaton::ptr parse(std::istream &in)
std::shared_ptr< HOAConsumerDA > ptr
#define STORM_LOG_INFO(message)
Definition logging.h:29
void closeFile(std::ofstream &stream)
Close the given file after writing.
Definition file.h:47
void openFile(std::string const &filepath, std::ofstream &filestream, bool append=false, bool silent=false)
Open the given file for writing.
Definition file.h:18
LabParser.cpp.
Definition cli.cpp:18