Storm 1.14.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
HOAConsumerDA.h
Go to the documentation of this file.
1#pragma once
2
16
17#include "cpphoafparser/consumer/hoa_consumer.hh"
18#include "cpphoafparser/util/implicit_edge_helper.hh"
19
20#include <boost/optional.hpp>
21#include <exception>
22
23namespace storm {
24namespace automata {
25
27 private:
28 AcceptanceCondition::ptr acceptance;
29
31 cpphoafparser::ImplicitEdgeHelper* helper = nullptr;
32
33 std::shared_ptr<storm::expressions::ExpressionManager> expressionManager;
34 std::vector<storm::expressions::Variable> apVariables;
35 std::unique_ptr<storm::solver::SmtSolver> solver;
36
38
39 public:
40 typedef std::shared_ptr<HOAConsumerDA> ptr;
41
42 HOAConsumerDA() : seenEdges(0) {
43 expressionManager.reset(new storm::expressions::ExpressionManager());
45 solver = factory.create(*expressionManager);
46 }
47
49 delete helper;
50 }
51
53 return da;
54 }
55
59 virtual void notifyBodyStart() {
60 STORM_LOG_THROW(header.numberOfStates, storm::exceptions::WrongFormatException,
61 "Parsing deterministic HOA automaton: Missing number-of-states header.");
62
63 acceptance = header.getAcceptanceCondition();
64 da.reset(new DeterministicAutomaton(header.apSet, *header.numberOfStates, *header.startState, acceptance));
65
66 helper = new cpphoafparser::ImplicitEdgeHelper(header.apSet.size());
67
68 seenEdges.resize(*header.numberOfStates * helper->getEdgesPerState());
69
70 for (const std::string& ap : header.apSet.getAPs()) {
71 apVariables.push_back(expressionManager->declareBooleanVariable(ap));
72 }
73 }
74
82 virtual void addState(unsigned int id, std::shared_ptr<std::string> info, label_expr::ptr labelExpr, std::shared_ptr<int_list> accSignature) {
83 if (accSignature) {
84 for (unsigned int accSet : *accSignature) {
85 acceptance->getAcceptanceSet(accSet).set(id);
86 }
87 }
88
89 STORM_LOG_THROW(labelExpr.get() == nullptr, storm::exceptions::NotSupportedException,
90 "Parsing deterministic HOA automaton: State-labeled automata not supported.");
91
92 helper->startOfState(id);
93 }
94
107 virtual void addEdgeImplicit(unsigned int stateId, const int_list& conjSuccessors, std::shared_ptr<int_list> accSignature) {
108 std::size_t edgeIndex = helper->nextImplicitEdge();
109
110 STORM_LOG_THROW(conjSuccessors.size() == 1, storm::exceptions::NotSupportedException,
111 "Parsing deterministic HOA automaton: Does not support alternation (conjunction of successor states).");
112
113 STORM_LOG_THROW(!accSignature, storm::exceptions::NotSupportedException,
114 "Parsing deterministic HOA automaton: Does not support transition-based acceptance.");
115
116 da->setSuccessor(stateId, edgeIndex, conjSuccessors.at(0));
117 markEdgeAsSeen(stateId, edgeIndex);
118 }
119
129 virtual void addEdgeWithLabel(unsigned int stateId, label_expr::ptr labelExpr, const int_list& conjSuccessors, std::shared_ptr<int_list> accSignature) {
130 STORM_LOG_THROW(conjSuccessors.size() == 1, storm::exceptions::NotSupportedException,
131 "Parsing deterministic HOA automaton: Does not support alternation (conjunction of successor states).");
132
133 STORM_LOG_THROW(!accSignature, storm::exceptions::NotSupportedException,
134 "Parsing deterministic HOA automaton: Does not support transition-based acceptance.");
135
136 std::size_t successor = conjSuccessors.at(0);
137
138 solver->reset();
139 solver->add(labelToStormExpression(labelExpr));
140
141 solver->allSat(apVariables, [this, stateId, successor](storm::expressions::SimpleValuation& valuation) {
142 // construct edge index from valuation
143 APSet::alphabet_element edgeIndex = header.apSet.elementAllFalse();
144 for (std::size_t i = 0; i < apVariables.size(); i++) {
145 if (valuation.getBooleanValue(apVariables[i])) {
146 edgeIndex = header.apSet.elementAddAP(edgeIndex, i);
147 }
148 }
149
150 // require: edge already exists -> same successor
151 STORM_LOG_THROW(!alreadyHaveEdge(stateId, edgeIndex) || da->getSuccessor(stateId, edgeIndex) == successor,
152 storm::exceptions::InvalidOperationException,
153 "HOA automaton: multiple definitions of successor for state " << stateId << " and edge " << edgeIndex << ".");
154
155 // std::cout << stateId << " -(" << edgeIndex << ")-> " << successor << '\n';
156 da->setSuccessor(stateId, edgeIndex, successor);
157 markEdgeAsSeen(stateId, edgeIndex);
158
159 // continue with next valuation
160 return true;
161 });
162 }
163
168 virtual void notifyEndOfState(unsigned int /*stateId*/) {
169 helper->endOfState();
170 }
171
175 virtual void notifyEnd() {
176 // require that we have seen all edges, i.e., that the automaton is complete
177 STORM_LOG_THROW(seenEdges.full(), storm::exceptions::InvalidOperationException, "HOA automaton has mismatch in number of edges, not complete?");
178 }
179
184 virtual void notifyAbort() {
185 STORM_LOG_THROW(false, storm::exceptions::WrongFormatException, "Parsing deterministic automaton: Automaton is incomplete (abort).");
186 }
187
192 virtual void notifyWarning(const std::string& warning) {
193 // IGNORE
194 (void)warning;
195 }
196
197 private:
198 storm::expressions::Expression labelToStormExpression(label_expr::ptr labelExpr) {
199 switch (labelExpr->getType()) {
200 case label_expr::EXP_AND:
201 return labelToStormExpression(labelExpr->getLeft()) && labelToStormExpression(labelExpr->getRight());
202 case label_expr::EXP_OR:
203 return labelToStormExpression(labelExpr->getLeft()) || labelToStormExpression(labelExpr->getRight());
204 case label_expr::EXP_NOT:
205 return !labelToStormExpression(labelExpr->getLeft());
206 case label_expr::EXP_TRUE:
207 return expressionManager->boolean(true);
208 case label_expr::EXP_FALSE:
209 return expressionManager->boolean(false);
210 case label_expr::EXP_ATOM: {
211 unsigned int apIndex = labelExpr->getAtom().getAPIndex();
212 STORM_LOG_THROW(apIndex < apVariables.size(), storm::exceptions::OutOfRangeException,
213 "HOA automaton refers to non-existing atomic proposition.");
214 return apVariables.at(apIndex).getExpression();
215 }
216 }
217 STORM_LOG_THROW(false, storm::exceptions::UnexpectedException, "Unknown label expression operator.");
218 }
219
220 bool alreadyHaveEdge(std::size_t stateId, std::size_t edgeIndex) {
221 return seenEdges.get(stateId * helper->getEdgesPerState() + edgeIndex);
222 }
223
224 void markEdgeAsSeen(std::size_t stateId, std::size_t edgeIndex) {
225 seenEdges.set(stateId * helper->getEdgesPerState() + edgeIndex);
226 }
227};
228
229} // namespace automata
230} // namespace storm
std::size_t alphabet_element
Definition APSet.h:12
std::shared_ptr< AcceptanceCondition > ptr
std::shared_ptr< DeterministicAutomaton > ptr
virtual void notifyBodyStart()
Called by the parser to notify that the BODY of the automaton has started [mandatory,...
virtual void notifyEnd()
Called by the parser to notify the consumer that the automata definition has ended [mandatory,...
virtual void notifyEndOfState(unsigned int)
Called by the parser to notify the consumer that the definition for state stateId has ended [multiple...
virtual void notifyAbort()
Called by the parser to notify the consumer that an "ABORT" message has been encountered (at any time...
virtual void addState(unsigned int id, std::shared_ptr< std::string > info, label_expr::ptr labelExpr, std::shared_ptr< int_list > accSignature)
Called by the parser for each "State: ..." item [multiple].
std::shared_ptr< HOAConsumerDA > ptr
virtual void notifyWarning(const std::string &warning)
Is called whenever a condition is encountered that merits a (non-fatal) warning.
virtual void addEdgeWithLabel(unsigned int stateId, label_expr::ptr labelExpr, const int_list &conjSuccessors, std::shared_ptr< int_list > accSignature)
Called by the parser for each explicit edge definition [optional, multiple], i.e.,...
virtual void addEdgeImplicit(unsigned int stateId, const int_list &conjSuccessors, std::shared_ptr< int_list > accSignature)
Called by the parser for each implicit edge definition [multiple], i.e., where the edge label is dedu...
DeterministicAutomaton::ptr getDA()
This class is responsible for managing a set of typed variables and all expressions using these varia...
A simple implementation of the valuation interface.
virtual bool getBooleanValue(Variable const &booleanVariable) const override
Retrieves the value of the given boolean variable.
A bit vector that is internally represented as a vector of 64-bit values.
Definition BitVector.h:16
virtual std::unique_ptr< storm::solver::SmtSolver > create(storm::expressions::ExpressionManager &manager) const
Creates a new SMT solver instance.
Definition solver.cpp:159
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:28