14#include "cpphoafparser/consumer/hoa_consumer.hh"
15#include "cpphoafparser/util/implicit_edge_helper.hh"
17#include <boost/optional.hpp>
28 cpphoafparser::ImplicitEdgeHelper* helper =
nullptr;
30 std::shared_ptr<storm::expressions::ExpressionManager> expressionManager;
31 std::vector<storm::expressions::Variable> apVariables;
32 std::unique_ptr<storm::solver::SmtSolver> solver;
37 typedef std::shared_ptr<HOAConsumerDA>
ptr;
42 solver = factory.
create(*expressionManager);
58 throw std::runtime_error(
"Parsing deterministic HOA automaton: Missing number-of-states header");
69 apVariables.push_back(expressionManager->declareBooleanVariable(ap));
80 virtual void addState(
unsigned int id, std::shared_ptr<std::string> info, label_expr::ptr labelExpr, std::shared_ptr<int_list> accSignature) {
82 for (
unsigned int accSet : *accSignature) {
83 acceptance->getAcceptanceSet(accSet).set(
id);
88 throw std::runtime_error(
"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 if (conjSuccessors.size() != 1) {
110 throw std::runtime_error(
"Parsing deterministic HOA automaton: Does not support alternation (conjunction of successor states)");
114 throw std::runtime_error(
"Parsing deterministic HOA automaton: Does not support transition-based acceptance");
117 da->setSuccessor(stateId, edgeIndex, conjSuccessors.at(0));
118 markEdgeAsSeen(stateId, edgeIndex);
130 virtual void addEdgeWithLabel(
unsigned int stateId, label_expr::ptr labelExpr,
const int_list& conjSuccessors, std::shared_ptr<int_list> accSignature) {
131 if (conjSuccessors.size() != 1) {
132 throw std::runtime_error(
"Parsing deterministic HOA automaton: Does not support alternation (conjunction of successor states)");
136 throw std::runtime_error(
"Parsing deterministic HOA automaton: Does not support transition-based acceptance");
139 std::size_t successor = conjSuccessors.at(0);
142 solver->add(labelToStormExpression(labelExpr));
147 for (std::size_t i = 0; i < apVariables.size(); i++) {
149 edgeIndex = header.apSet.elementAddAP(edgeIndex, i);
154 STORM_LOG_THROW(!alreadyHaveEdge(stateId, edgeIndex) || da->getSuccessor(stateId, edgeIndex) == successor,
155 storm::exceptions::InvalidOperationException,
156 "HOA automaton: multiple definitions of successor for state " << stateId <<
" and edge " << edgeIndex);
159 da->setSuccessor(stateId, edgeIndex, successor);
160 markEdgeAsSeen(stateId, edgeIndex);
172 helper->endOfState();
180 STORM_LOG_THROW(seenEdges.
full(), storm::exceptions::InvalidOperationException,
"HOA automaton has mismatch in number of edges, not complete?");
188 throw std::runtime_error(
"Parsing deterministic automaton: Automaton is incomplete (abort)");
202 switch (labelExpr->getType()) {
203 case label_expr::EXP_AND:
204 return labelToStormExpression(labelExpr->getLeft()) && labelToStormExpression(labelExpr->getRight());
205 case label_expr::EXP_OR:
206 return labelToStormExpression(labelExpr->getLeft()) || labelToStormExpression(labelExpr->getRight());
207 case label_expr::EXP_NOT:
208 return !labelToStormExpression(labelExpr->getLeft());
209 case label_expr::EXP_TRUE:
210 return expressionManager->boolean(
true);
211 case label_expr::EXP_FALSE:
212 return expressionManager->boolean(
false);
213 case label_expr::EXP_ATOM: {
214 unsigned int apIndex = labelExpr->getAtom().getAPIndex();
215 STORM_LOG_THROW(apIndex < apVariables.size(), storm::exceptions::OutOfRangeException,
216 "HOA automaton refers to non-existing atomic proposition");
217 return apVariables.at(apIndex).getExpression();
220 throw std::runtime_error(
"Unknown label expression operator");
223 bool alreadyHaveEdge(std::size_t stateId, std::size_t edgeIndex) {
224 return seenEdges.
get(stateId * helper->getEdgesPerState() + edgeIndex);
227 void markEdgeAsSeen(std::size_t stateId, std::size_t edgeIndex) {
228 seenEdges.
set(stateId * helper->getEdgesPerState() + edgeIndex);
alphabet_element elementAllFalse() const
unsigned int size() const
std::size_t alphabet_element
const std::vector< std::string > & getAPs() const
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.
bool full() const
Retrieves whether all bits are set in this bit vector.
void resize(uint_fast64_t newLength, bool init=false)
Resizes the bit vector to hold the given new number of bits.
void set(uint_fast64_t index, bool value=true)
Sets the given truth value at the given index.
bool get(uint_fast64_t index) const
Retrieves the truth value of the bit at the given index and performs a bound check.
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)