Storm 2.0.0.3
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());
44 solver = storm::utility::solver::getSmtSolver(*expressionManager);
45 }
46
48 delete helper;
49 }
50
52 return da;
53 }
54
58 virtual void notifyBodyStart() {
59 STORM_LOG_THROW(header.numberOfStates, storm::exceptions::WrongFormatException,
60 "Parsing deterministic HOA automaton: Missing number-of-states header.");
61
62 acceptance = header.getAcceptanceCondition();
63 da.reset(new DeterministicAutomaton(header.apSet, *header.numberOfStates, *header.startState, acceptance));
64
65 helper = new cpphoafparser::ImplicitEdgeHelper(header.apSet.size());
66
67 seenEdges.resize(*header.numberOfStates * helper->getEdgesPerState());
68
69 for (const std::string& ap : header.apSet.getAPs()) {
70 apVariables.push_back(expressionManager->declareBooleanVariable(ap));
71 }
72 }
73
81 virtual void addState(unsigned int id, std::shared_ptr<std::string> info, label_expr::ptr labelExpr, std::shared_ptr<int_list> accSignature) {
82 if (accSignature) {
83 for (unsigned int accSet : *accSignature) {
84 acceptance->getAcceptanceSet(accSet).set(id);
85 }
86 }
87
88 STORM_LOG_THROW(labelExpr.get() == nullptr, storm::exceptions::NotSupportedException,
89 "Parsing deterministic HOA automaton: State-labeled automata not supported.");
90
91 helper->startOfState(id);
92 }
93
106 virtual void addEdgeImplicit(unsigned int stateId, const int_list& conjSuccessors, std::shared_ptr<int_list> accSignature) {
107 std::size_t edgeIndex = helper->nextImplicitEdge();
108
109 STORM_LOG_THROW(conjSuccessors.size() == 1, storm::exceptions::NotSupportedException,
110 "Parsing deterministic HOA automaton: Does not support alternation (conjunction of successor states).");
111
112 STORM_LOG_THROW(!accSignature, storm::exceptions::NotSupportedException,
113 "Parsing deterministic HOA automaton: Does not support transition-based acceptance.");
114
115 da->setSuccessor(stateId, edgeIndex, conjSuccessors.at(0));
116 markEdgeAsSeen(stateId, edgeIndex);
117 }
118
128 virtual void addEdgeWithLabel(unsigned int stateId, label_expr::ptr labelExpr, const int_list& conjSuccessors, std::shared_ptr<int_list> accSignature) {
129 STORM_LOG_THROW(conjSuccessors.size() == 1, storm::exceptions::NotSupportedException,
130 "Parsing deterministic HOA automaton: Does not support alternation (conjunction of successor states).");
131
132 STORM_LOG_THROW(!accSignature, storm::exceptions::NotSupportedException,
133 "Parsing deterministic HOA automaton: Does not support transition-based acceptance.");
134
135 std::size_t successor = conjSuccessors.at(0);
136
137 solver->reset();
138 solver->add(labelToStormExpression(labelExpr));
139
140 solver->allSat(apVariables, [this, stateId, successor](storm::expressions::SimpleValuation& valuation) {
141 // construct edge index from valuation
142 APSet::alphabet_element edgeIndex = header.apSet.elementAllFalse();
143 for (std::size_t i = 0; i < apVariables.size(); i++) {
144 if (valuation.getBooleanValue(apVariables[i])) {
145 edgeIndex = header.apSet.elementAddAP(edgeIndex, i);
146 }
147 }
148
149 // require: edge already exists -> same successor
150 STORM_LOG_THROW(!alreadyHaveEdge(stateId, edgeIndex) || da->getSuccessor(stateId, edgeIndex) == successor,
151 storm::exceptions::InvalidOperationException,
152 "HOA automaton: multiple definitions of successor for state " << stateId << " and edge " << edgeIndex << ".");
153
154 // std::cout << stateId << " -(" << edgeIndex << ")-> " << successor << '\n';
155 da->setSuccessor(stateId, edgeIndex, successor);
156 markEdgeAsSeen(stateId, edgeIndex);
157
158 // continue with next valuation
159 return true;
160 });
161 }
162
167 virtual void notifyEndOfState(unsigned int /*stateId*/) {
168 helper->endOfState();
169 }
170
174 virtual void notifyEnd() {
175 // require that we have seen all edges, i.e., that the automaton is complete
176 STORM_LOG_THROW(seenEdges.full(), storm::exceptions::InvalidOperationException, "HOA automaton has mismatch in number of edges, not complete?");
177 }
178
183 virtual void notifyAbort() {
184 STORM_LOG_THROW(false, storm::exceptions::WrongFormatException, "Parsing deterministic automaton: Automaton is incomplete (abort).");
185 }
186
191 virtual void notifyWarning(const std::string& warning) {
192 // IGNORE
193 (void)warning;
194 }
195
196 private:
197 storm::expressions::Expression labelToStormExpression(label_expr::ptr labelExpr) {
198 switch (labelExpr->getType()) {
199 case label_expr::EXP_AND:
200 return labelToStormExpression(labelExpr->getLeft()) && labelToStormExpression(labelExpr->getRight());
201 case label_expr::EXP_OR:
202 return labelToStormExpression(labelExpr->getLeft()) || labelToStormExpression(labelExpr->getRight());
203 case label_expr::EXP_NOT:
204 return !labelToStormExpression(labelExpr->getLeft());
205 case label_expr::EXP_TRUE:
206 return expressionManager->boolean(true);
207 case label_expr::EXP_FALSE:
208 return expressionManager->boolean(false);
209 case label_expr::EXP_ATOM: {
210 unsigned int apIndex = labelExpr->getAtom().getAPIndex();
211 STORM_LOG_THROW(apIndex < apVariables.size(), storm::exceptions::OutOfRangeException,
212 "HOA automaton refers to non-existing atomic proposition.");
213 return apVariables.at(apIndex).getExpression();
214 }
215 }
216 STORM_LOG_THROW(false, storm::exceptions::UnexpectedException, "Unknown label expression operator.");
217 }
218
219 bool alreadyHaveEdge(std::size_t stateId, std::size_t edgeIndex) {
220 return seenEdges.get(stateId * helper->getEdgesPerState() + edgeIndex);
221 }
222
223 void markEdgeAsSeen(std::size_t stateId, std::size_t edgeIndex) {
224 seenEdges.set(stateId * helper->getEdgesPerState() + edgeIndex);
225 }
226};
227
228} // namespace automata
229} // 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
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:39
std::unique_ptr< storm::solver::SmtSolver > getSmtSolver(storm::expressions::ExpressionManager &manager)
Creates a new SMT solver instance.
Definition solver.cpp:215
The contract of a DD backend.