Storm 1.14.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
AcceptanceCondition.cpp
Go to the documentation of this file.
2
6
7namespace storm {
8namespace automata {
9
10AcceptanceCondition::AcceptanceCondition(std::size_t numberOfStates, unsigned int numberOfAcceptanceSets, acceptance_expr::ptr acceptance)
11 : numberOfAcceptanceSets(numberOfAcceptanceSets), acceptance(acceptance) {
12 // initialize acceptance sets
13 for (unsigned int i = 0; i < numberOfAcceptanceSets; i++) {
14 acceptanceSets.push_back(storm::storage::BitVector(numberOfStates));
15 }
16}
17
19 return numberOfAcceptanceSets;
20}
21
23 return acceptanceSets.at(index);
24}
25
27 return acceptanceSets.at(index);
28}
29
30AcceptanceCondition::acceptance_expr::ptr AcceptanceCondition::getAcceptanceExpression() const {
31 return acceptance;
32}
33
35 return isAccepting(scc, acceptance);
36}
37
38bool AcceptanceCondition::isAccepting(const storm::storage::StateBlock& scc, acceptance_expr::ptr expr) const {
39 switch (expr->getType()) {
40 case acceptance_expr::EXP_AND:
41 return isAccepting(scc, expr->getLeft()) && isAccepting(scc, expr->getRight());
42 case acceptance_expr::EXP_OR:
43 return isAccepting(scc, expr->getLeft()) || isAccepting(scc, expr->getRight());
44 case acceptance_expr::EXP_NOT:
45 return !isAccepting(scc, expr->getLeft());
46 case acceptance_expr::EXP_TRUE:
47 return true;
48 case acceptance_expr::EXP_FALSE:
49 return false;
50 case acceptance_expr::EXP_ATOM: {
51 const cpphoafparser::AtomAcceptance& atom = expr->getAtom();
52 const storm::storage::BitVector& acceptanceSet = acceptanceSets.at(atom.getAcceptanceSet());
53 bool negated = atom.isNegated();
54 bool rv;
55 switch (atom.getType()) {
56 case cpphoafparser::AtomAcceptance::TEMPORAL_INF:
57 rv = false;
58 for (auto& state : scc) {
59 if (acceptanceSet.get(state)) {
60 rv = true;
61 break;
62 }
63 }
64 break;
65 case cpphoafparser::AtomAcceptance::TEMPORAL_FIN:
66 rv = true;
67 for (auto& state : scc) {
68 if (acceptanceSet.get(state)) {
69 rv = false;
70 break;
71 }
72 }
73 break;
74 }
75
76 return (negated ? !rv : rv);
77 }
78 }
79
80 STORM_LOG_THROW(false, storm::exceptions::UnexpectedException, "Missing case statement.");
81}
82
83std::vector<std::vector<AcceptanceCondition::acceptance_expr::ptr>> AcceptanceCondition::extractFromDNF() const {
84 std::vector<std::vector<AcceptanceCondition::acceptance_expr::ptr>> dnf;
85
86 extractFromDNFRecursion(getAcceptanceExpression(), dnf, true);
87
88 return dnf;
89}
90
91void AcceptanceCondition::extractFromDNFRecursion(AcceptanceCondition::acceptance_expr::ptr e, std::vector<std::vector<acceptance_expr::ptr>>& dnf,
92 bool topLevel) const {
93 if (topLevel) {
94 if (e->isOR()) {
95 if (e->getLeft()->isOR()) {
96 extractFromDNFRecursion(e->getLeft(), dnf, true);
97 } else {
98 dnf.emplace_back();
99 extractFromDNFRecursion(e->getLeft(), dnf, false);
100 }
101
102 if (e->getRight()->isOR()) {
103 extractFromDNFRecursion(e->getRight(), dnf, true);
104 } else {
105 dnf.emplace_back();
106 extractFromDNFRecursion(e->getRight(), dnf, false);
107 }
108 } else {
109 dnf.emplace_back();
110 extractFromDNFRecursion(e, dnf, false);
111 }
112 } else {
113 if (e->isOR() || e->isNOT()) {
114 STORM_LOG_THROW(false, storm::exceptions::InvalidOperationException, "Acceptance condition is not in DNF.");
115 } else if (e->isAND()) {
116 extractFromDNFRecursion(e->getLeft(), dnf, false);
117 extractFromDNFRecursion(e->getRight(), dnf, false);
118 } else {
119 dnf.back().push_back(e);
120 }
121 }
122}
123
124AcceptanceCondition::ptr AcceptanceCondition::lift(std::size_t productNumberOfStates, std::function<std::size_t(std::size_t)> mapping) const {
125 AcceptanceCondition::ptr lifted(new AcceptanceCondition(productNumberOfStates, numberOfAcceptanceSets, acceptance));
126 for (unsigned int i = 0; i < numberOfAcceptanceSets; i++) {
128 storm::storage::BitVector& liftedSet = lifted->getAcceptanceSet(i);
129
130 for (std::size_t prodState = 0; prodState < productNumberOfStates; prodState++) {
131 if (set.get(mapping(prodState))) {
132 liftedSet.set(prodState);
133 }
134 }
135 }
136
137 return lifted;
138}
139
140} // namespace automata
141} // namespace storm
AcceptanceCondition(std::size_t numberOfStates, unsigned int numberOfAcceptanceSets, acceptance_expr::ptr acceptance)
storm::storage::BitVector & getAcceptanceSet(unsigned int index)
std::shared_ptr< AcceptanceCondition > ptr
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
acceptance_expr::ptr getAcceptanceExpression() const
bool isAccepting(const storm::storage::StateBlock &scc) const
A bit vector that is internally represented as a vector of 64-bit values.
Definition BitVector.h:16
void set(uint64_t index, bool value=true)
Sets the given truth value at the given index.
bool get(uint64_t index) const
Retrieves the truth value of the bit at the given index and performs a bound check.
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:28