Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
CostLimitClosure.cpp
Go to the documentation of this file.
6
7namespace storm {
8namespace modelchecker {
9namespace helper {
10namespace rewardbounded {
11CostLimit::CostLimit(uint64_t const& costLimit) : value(costLimit) {
12 // Intentionally left empty
13}
14
16 return value == std::numeric_limits<uint64_t>::max();
17}
18
19uint64_t const& CostLimit::get() const {
20 STORM_LOG_ASSERT(!isInfinity(), "Tried to get an infinite cost limit as int.");
21 return value;
22}
23
24uint64_t& CostLimit::get() {
25 STORM_LOG_ASSERT(!isInfinity(), "Tried to get an infinite cost limit as int.");
26 return value;
27}
28
29bool CostLimit::operator<(CostLimit const& other) const {
30 // Since infinity is represented by the max integer, we can compare this way.
31 return value < other.value;
32}
33
34bool CostLimit::operator==(CostLimit const& other) const {
35 return value == other.value;
36}
37
39 return CostLimit(std::numeric_limits<uint64_t>::max());
40}
41
44 for (uint64_t i = 0; i < lhs.size(); ++i) {
45 if (lhs[i] < rhs[i]) {
46 return true;
47 } else if (rhs[i] < lhs[i]) {
48 return false;
49 }
50 }
51 return false;
52}
53
54CostLimitClosure::CostLimitClosure(storm::storage::BitVector const& downwardDimensions) : downwardDimensions(downwardDimensions) {
55 // Intentionally left empty
56}
57
58bool CostLimitClosure::insert(CostLimits const& costLimits) {
59 // Iterate over all points in the generator and check whether they dominate the given point or vice versa
60 // TODO: make this more efficient by exploiting the order of the generator set.
61 std::vector<CostLimits> pointsToErase;
62 for (auto const& b : generator) {
63 if (dominates(b, costLimits)) {
64 // The given point is already contained in this closure.
65 // Since domination is transitive, this should not happen:
66 STORM_LOG_ASSERT(pointsToErase.empty(), "Inconsistent generator of CostLimitClosure.");
67 return false;
68 }
69 if (dominates(costLimits, b)) {
70 // b will be dominated by the new point so we erase it later.
71 // Note that b != newPoint holds if we reach this point
72 pointsToErase.push_back(b);
73 }
74 }
75 for (auto const& b : pointsToErase) {
76 generator.erase(b);
77 }
78 generator.insert(std::move(costLimits));
79 return true;
80}
81
82bool CostLimitClosure::contains(CostLimits const& costLimits) const {
83 // Iterate over all points in the generator and check whether they dominate the given point.
84 // TODO: make this more efficient by exploiting the order of the generator set.
85 for (auto const& b : generator) {
86 if (dominates(b, costLimits)) {
87 return true;
88 }
89 }
90 return false;
91}
92
94 CostLimits infinityProjection(costLimits);
95 for (auto dim : downwardDimensions) {
96 infinityProjection[dim] = CostLimit::infinity();
97 }
98 return contains(infinityProjection);
99}
100
102 return generator.empty();
103}
104
107 for (auto dim : downwardDimensions) {
108 p[dim] = CostLimit::infinity();
109 }
110 return contains(p);
111}
112
113bool CostLimitClosure::dominates(CostLimits const& lhs, CostLimits const& rhs) const {
114 for (uint64_t i = 0; i < lhs.size(); ++i) {
115 if (downwardDimensions.get(i)) {
116 if (lhs[i] < rhs[i]) {
117 return false;
118 }
119 } else {
120 if (rhs[i] < lhs[i]) {
121 return false;
122 }
123 }
124 }
125 return true;
126}
127
128std::vector<CostLimits> CostLimitClosure::getDominatingCostLimits(CostLimits const& costLimits) const {
129 std::vector<CostLimits> result;
130 for (auto const& b : generator) {
131 if (dominates(b, costLimits)) {
132 result.push_back(b);
133 }
134 }
135 return result;
136}
137
139 return generator;
140}
141
143 return downwardDimensions.size();
144}
145
147 assert(first.dimension() == second.dimension());
148 uint64_t dimension = first.dimension();
149 auto manager = std::make_shared<storm::expressions::ExpressionManager>();
150 auto solver = storm::utility::solver::getSmtSolver(*manager);
151
152 std::vector<storm::expressions::Expression> point;
153 storm::expressions::Expression zero = manager->integer(0);
154 for (uint64_t i = 0; i < dimension; ++i) {
155 point.push_back(manager->declareIntegerVariable("x" + std::to_string(i)).getExpression());
156 solver->add(point.back() >= zero);
157 }
158 for (auto const& cl : {first, second}) {
159 for (auto const& q : cl.getGenerator()) {
160 storm::expressions::Expression pointNotDominated;
161 for (uint64_t i = 0; i < point.size(); ++i) {
162 if (!cl.downwardDimensions.get(i) || !q[i].isInfinity()) {
163 assert(!q[i].isInfinity());
164 storm::expressions::Expression qi = manager->integer(q[i].get());
165 storm::expressions::Expression piNotDominated = cl.downwardDimensions.get(i) ? point[i] > qi : point[i] < qi;
166 if (piNotDominated.isInitialized()) {
167 pointNotDominated = pointNotDominated || piNotDominated;
168 } else {
169 pointNotDominated = piNotDominated;
170 }
171 }
172 }
173 if (pointNotDominated.isInitialized()) {
174 solver->add(pointNotDominated);
175 } else {
176 solver->add(manager->boolean(false));
177 }
178 }
179 }
180 return solver->check() == storm::solver::SmtSolver::CheckResult::Unsat;
181 ;
182}
183} // namespace rewardbounded
184} // namespace helper
185} // namespace modelchecker
186} // namespace storm
bool isInitialized() const
Checks whether the object encapsulates a base-expression.
static bool unionFull(CostLimitClosure const &first, CostLimitClosure const &second)
Returns true if the union of the two closures is full, i.e., contains every point.
std::vector< CostLimits > getDominatingCostLimits(CostLimits const &costLimits) const
CostLimitClosure(storm::storage::BitVector const &downwardDimensions)
bool dominates(CostLimits const &lhs, CostLimits const &rhs) const
std::set< CostLimits, CostLimitsCompare > GeneratorType
bool containsUpwardClosure(CostLimits const &costLimits) const
A bit vector that is internally represented as a vector of 64-bit values.
Definition BitVector.h:18
size_t size() const
Retrieves the number of bits this bit vector can store.
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_ASSERT(cond, message)
Definition macros.h:11
std::unique_ptr< storm::solver::SmtSolver > getSmtSolver(storm::expressions::ExpressionManager &manager)
Definition solver.cpp:154
LabParser.cpp.
Definition cli.cpp:18
bool operator()(CostLimits const &lhs, CostLimits const &rhs) const