Browse Source

(MDP-LTL) AcceptanceCondition: extractFromDNF

Convert a generic acceptance condition to DNF.
tempestpy_adaptions
Joachim Klein 4 years ago
committed by Stefan Pranger
parent
commit
b6b31f20af
  1. 45
      src/storm/automata/AcceptanceCondition.cpp
  2. 3
      src/storm/automata/AcceptanceCondition.h

45
src/storm/automata/AcceptanceCondition.cpp

@ -1,5 +1,8 @@
#include "AcceptanceCondition.h"
#include "storm/utility/macros.h"
#include "storm/exceptions/InvalidOperationException.h"
namespace storm {
namespace automata {
@ -79,6 +82,48 @@ bool AcceptanceCondition::isAccepting(const storm::storage::StateBlock& scc, acc
throw std::runtime_error("Missing case statement");
}
std::vector<std::vector<AcceptanceCondition::acceptance_expr::ptr>> AcceptanceCondition::extractFromDNF() const {
std::vector<std::vector<AcceptanceCondition::acceptance_expr::ptr>> dnf;
extractFromDNFRecursion(getAcceptanceExpression(), dnf, true);
return dnf;
}
void AcceptanceCondition::extractFromDNFRecursion(AcceptanceCondition::acceptance_expr::ptr e, std::vector<std::vector<acceptance_expr::ptr>>& dnf, bool topLevel) const {
if (topLevel) {
if (e->isOR()) {
if (e->getLeft()->isOR()) {
extractFromDNFRecursion(e->getLeft(), dnf, true);
} else {
dnf.emplace_back();
extractFromDNFRecursion(e->getLeft(), dnf, false);
}
if (e->getRight()->isOR()) {
extractFromDNFRecursion(e->getRight(), dnf, true);
} else {
dnf.emplace_back();
extractFromDNFRecursion(e->getRight(), dnf, false);
}
} else {
dnf.emplace_back();
extractFromDNFRecursion(e, dnf, false);
}
} else {
if (e->isOR() || e->isNOT()) {
STORM_LOG_THROW(false, storm::exceptions::InvalidOperationException, "Acceptance condition is not in DNF");
} else if (e->isAND()) {
extractFromDNFRecursion(e->getLeft(), dnf, false);
extractFromDNFRecursion(e->getRight(), dnf, false);
} else {
dnf.back().push_back(e);
}
}
}
AcceptanceCondition::ptr AcceptanceCondition::lift(std::size_t productNumberOfStates, std::function<std::size_t (std::size_t)> mapping) const {
AcceptanceCondition::ptr lifted(new AcceptanceCondition(productNumberOfStates, numberOfAcceptanceSets, acceptance));
for (unsigned int i = 0; i < numberOfAcceptanceSets; i++) {

3
src/storm/automata/AcceptanceCondition.h

@ -24,8 +24,11 @@ namespace storm {
acceptance_expr::ptr getAcceptanceExpression() const;
AcceptanceCondition::ptr lift(std::size_t productNumberOfStates, std::function<std::size_t (std::size_t)> mapping) const;
std::vector<std::vector<acceptance_expr::ptr>> extractFromDNF() const;
private:
bool isAccepting(const storm::storage::StateBlock& scc, acceptance_expr::ptr expr) const;
void extractFromDNFRecursion(acceptance_expr::ptr e, std::vector<std::vector<acceptance_expr::ptr>>& dnf, bool topLevel) const;
std::size_t numberOfStates;
unsigned int numberOfAcceptanceSets;

Loading…
Cancel
Save