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;
45 solver = factory.
create(*expressionManager);
61 "Parsing deterministic HOA automaton: Missing number-of-states header.");
63 acceptance =
header.getAcceptanceCondition();
66 helper =
new cpphoafparser::ImplicitEdgeHelper(
header.apSet.size());
68 seenEdges.resize(*
header.numberOfStates * helper->getEdgesPerState());
70 for (
const std::string& ap :
header.apSet.getAPs()) {
71 apVariables.push_back(expressionManager->declareBooleanVariable(ap));
82 virtual void addState(
unsigned int id, std::shared_ptr<std::string> info, label_expr::ptr labelExpr, std::shared_ptr<int_list> accSignature) {
84 for (
unsigned int accSet : *accSignature) {
85 acceptance->getAcceptanceSet(accSet).set(
id);
89 STORM_LOG_THROW(labelExpr.get() ==
nullptr, storm::exceptions::NotSupportedException,
90 "Parsing deterministic HOA automaton: State-labeled automata not supported.");
92 helper->startOfState(
id);
107 virtual void addEdgeImplicit(
unsigned int stateId,
const int_list& conjSuccessors, std::shared_ptr<int_list> accSignature) {
108 std::size_t edgeIndex = helper->nextImplicitEdge();
110 STORM_LOG_THROW(conjSuccessors.size() == 1, storm::exceptions::NotSupportedException,
111 "Parsing deterministic HOA automaton: Does not support alternation (conjunction of successor states).");
113 STORM_LOG_THROW(!accSignature, storm::exceptions::NotSupportedException,
114 "Parsing deterministic HOA automaton: Does not support transition-based acceptance.");
116 da->setSuccessor(stateId, edgeIndex, conjSuccessors.at(0));
117 markEdgeAsSeen(stateId, edgeIndex);
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).");
133 STORM_LOG_THROW(!accSignature, storm::exceptions::NotSupportedException,
134 "Parsing deterministic HOA automaton: Does not support transition-based acceptance.");
136 std::size_t successor = conjSuccessors.at(0);
139 solver->add(labelToStormExpression(labelExpr));
144 for (std::size_t i = 0; i < apVariables.size(); i++) {
146 edgeIndex =
header.apSet.elementAddAP(edgeIndex, i);
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 <<
".");
156 da->setSuccessor(stateId, edgeIndex, successor);
157 markEdgeAsSeen(stateId, edgeIndex);
169 helper->endOfState();
177 STORM_LOG_THROW(seenEdges.full(), storm::exceptions::InvalidOperationException,
"HOA automaton has mismatch in number of edges, not complete?");
185 STORM_LOG_THROW(
false, storm::exceptions::WrongFormatException,
"Parsing deterministic automaton: Automaton is incomplete (abort).");
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();
217 STORM_LOG_THROW(
false, storm::exceptions::UnexpectedException,
"Unknown label expression operator.");
220 bool alreadyHaveEdge(std::size_t stateId, std::size_t edgeIndex) {
221 return seenEdges.get(stateId * helper->getEdgesPerState() + edgeIndex);
224 void markEdgeAsSeen(std::size_t stateId, std::size_t edgeIndex) {
225 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.
virtual std::unique_ptr< storm::solver::SmtSolver > create(storm::expressions::ExpressionManager &manager) const
Creates a new SMT solver instance.
#define STORM_LOG_THROW(cond, exception, message)