17#include "cpphoafparser/consumer/hoa_consumer.hh"
18#include "cpphoafparser/util/implicit_edge_helper.hh"
20#include <boost/optional.hpp>
31 cpphoafparser::ImplicitEdgeHelper* helper =
nullptr;
33 std::shared_ptr<storm::expressions::ExpressionManager> expressionManager;
34 std::vector<storm::expressions::Variable> apVariables;
35 std::unique_ptr<storm::solver::SmtSolver> solver;
40 typedef std::shared_ptr<HOAConsumerDA>
ptr;
60 "Parsing deterministic HOA automaton: Missing number-of-states header.");
62 acceptance =
header.getAcceptanceCondition();
65 helper =
new cpphoafparser::ImplicitEdgeHelper(
header.apSet.size());
67 seenEdges.resize(*
header.numberOfStates * helper->getEdgesPerState());
69 for (
const std::string& ap :
header.apSet.getAPs()) {
70 apVariables.push_back(expressionManager->declareBooleanVariable(ap));
81 virtual void addState(
unsigned int id, std::shared_ptr<std::string> info, label_expr::ptr labelExpr, std::shared_ptr<int_list> accSignature) {
83 for (
unsigned int accSet : *accSignature) {
84 acceptance->getAcceptanceSet(accSet).set(
id);
88 STORM_LOG_THROW(labelExpr.get() ==
nullptr, storm::exceptions::NotSupportedException,
89 "Parsing deterministic HOA automaton: State-labeled automata not supported.");
91 helper->startOfState(
id);
106 virtual void addEdgeImplicit(
unsigned int stateId,
const int_list& conjSuccessors, std::shared_ptr<int_list> accSignature) {
107 std::size_t edgeIndex = helper->nextImplicitEdge();
109 STORM_LOG_THROW(conjSuccessors.size() == 1, storm::exceptions::NotSupportedException,
110 "Parsing deterministic HOA automaton: Does not support alternation (conjunction of successor states).");
112 STORM_LOG_THROW(!accSignature, storm::exceptions::NotSupportedException,
113 "Parsing deterministic HOA automaton: Does not support transition-based acceptance.");
115 da->setSuccessor(stateId, edgeIndex, conjSuccessors.at(0));
116 markEdgeAsSeen(stateId, edgeIndex);
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).");
132 STORM_LOG_THROW(!accSignature, storm::exceptions::NotSupportedException,
133 "Parsing deterministic HOA automaton: Does not support transition-based acceptance.");
135 std::size_t successor = conjSuccessors.at(0);
138 solver->add(labelToStormExpression(labelExpr));
143 for (std::size_t i = 0; i < apVariables.size(); i++) {
145 edgeIndex =
header.apSet.elementAddAP(edgeIndex, i);
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 <<
".");
155 da->setSuccessor(stateId, edgeIndex, successor);
156 markEdgeAsSeen(stateId, edgeIndex);
168 helper->endOfState();
176 STORM_LOG_THROW(seenEdges.full(), storm::exceptions::InvalidOperationException,
"HOA automaton has mismatch in number of edges, not complete?");
184 STORM_LOG_THROW(
false, storm::exceptions::WrongFormatException,
"Parsing deterministic automaton: Automaton is incomplete (abort).");
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();
216 STORM_LOG_THROW(
false, storm::exceptions::UnexpectedException,
"Unknown label expression operator.");
219 bool alreadyHaveEdge(std::size_t stateId, std::size_t edgeIndex) {
220 return seenEdges.get(stateId * helper->getEdgesPerState() + edgeIndex);
223 void markEdgeAsSeen(std::size_t stateId, std::size_t edgeIndex) {
224 seenEdges.set(stateId * helper->getEdgesPerState() + edgeIndex);
std::size_t alphabet_element
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.
#define STORM_LOG_THROW(cond, exception, message)
std::unique_ptr< storm::solver::SmtSolver > getSmtSolver(storm::expressions::ExpressionManager &manager)
Creates a new SMT solver instance.
The contract of a DD backend.