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