Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
Bdd.cpp
Go to the documentation of this file.
1#include <algorithm>
2
6
8
12
14
18
19#include "storm-config.h"
21
22namespace storm {
23namespace dd {
24
25template<DdType LibraryType>
27 std::set<storm::expressions::Variable> const& containedMetaVariables)
28 : Dd<LibraryType>(ddManager, containedMetaVariables), internalBdd(internalBdd) {
29 // Intentionally left empty.
30}
31
32template<DdType LibraryType, typename ValueType>
34 static Bdd<LibraryType> fromVector(DdManager<LibraryType> const& ddManager, std::vector<ValueType> const& explicitValues, storm::dd::Odd const& odd,
35 std::set<storm::expressions::Variable> const& metaVariables, storm::logic::ComparisonType comparisonType,
36 ValueType value) {
37 switch (comparisonType) {
40 ddManager,
42 [&value, &explicitValues](uint64_t offset) { return explicitValues[offset] < value; }),
43 metaVariables);
45 return Bdd<LibraryType>(
46 ddManager,
48 [&value, &explicitValues](uint64_t offset) { return explicitValues[offset] <= value; }),
49 metaVariables);
51 return Bdd<LibraryType>(
52 ddManager,
54 [&value, &explicitValues](uint64_t offset) { return explicitValues[offset] > value; }),
55 metaVariables);
58 ddManager,
60 [&value, &explicitValues](uint64_t offset) { return explicitValues[offset] >= value; }),
61 metaVariables);
62 }
63 return Bdd<LibraryType>();
64 }
65};
66
67template<DdType LibraryType>
69 static Bdd<LibraryType> fromVector(DdManager<LibraryType> const&, std::vector<storm::RationalFunction> const&, storm::dd::Odd const&,
70 std::set<storm::expressions::Variable> const&, storm::logic::ComparisonType, storm::RationalFunction) {
71 STORM_LOG_THROW(false, storm::exceptions::InvalidOperationException, "Cannot compare rational functions to bound.");
72 return Bdd<LibraryType>();
73 }
74};
75
76template<DdType LibraryType>
77template<typename ValueType>
78Bdd<LibraryType> Bdd<LibraryType>::fromVector(DdManager<LibraryType> const& ddManager, std::vector<ValueType> const& explicitValues, storm::dd::Odd const& odd,
79 std::set<storm::expressions::Variable> const& metaVariables, storm::logic::ComparisonType comparisonType,
80 ValueType value) {
81 return FromVectorHelper<LibraryType, ValueType>::fromVector(ddManager, explicitValues, odd, metaVariables, comparisonType, value);
83
84template<DdType LibraryType>
86 std::set<storm::expressions::Variable> const& metaVariables) {
87 return Bdd<LibraryType>(ddManager,
89 [&truthValues](uint64_t offset) { return truthValues[offset]; }),
90 metaVariables);
91}
93template<DdType LibraryType>
94Bdd<LibraryType> Bdd<LibraryType>::getEncoding(DdManager<LibraryType> const& ddManager, uint64_t targetOffset, storm::dd::Odd const& odd,
95 std::set<storm::expressions::Variable> const& metaVariables) {
96 return Bdd<LibraryType>(ddManager,
98 [targetOffset](uint64_t offset) { return offset == targetOffset; }),
99 metaVariables);
101
102template<DdType LibraryType>
104 return internalBdd == other.internalBdd;
105}
106
107template<DdType LibraryType>
109 return internalBdd != other.internalBdd;
110}
112template<DdType LibraryType>
114 std::set<storm::expressions::Variable> metaVariables = Dd<LibraryType>::joinMetaVariables(thenBdd, elseBdd);
115 metaVariables.insert(this->getContainedMetaVariables().begin(), this->getContainedMetaVariables().end());
116 return Bdd<LibraryType>(this->getDdManager(), internalBdd.ite(thenBdd.internalBdd, elseBdd.internalBdd), metaVariables);
117}
118
119template<DdType LibraryType>
120template<typename ValueType>
122 std::set<storm::expressions::Variable> metaVariables = Dd<LibraryType>::joinMetaVariables(thenAdd, elseAdd);
123 metaVariables.insert(this->getContainedMetaVariables().begin(), this->getContainedMetaVariables().end());
124 return Add<LibraryType, ValueType>(this->getDdManager(), internalBdd.ite(thenAdd.internalAdd, elseAdd.internalAdd), metaVariables);
125}
126
127template<DdType LibraryType>
129 return Bdd<LibraryType>(this->getDdManager(), internalBdd || other.internalBdd, Dd<LibraryType>::joinMetaVariables(*this, other));
131
132template<DdType LibraryType>
134 this->addMetaVariables(other.getContainedMetaVariables());
135 internalBdd |= other.internalBdd;
136 return *this;
137}
139template<DdType LibraryType>
141 return Bdd<LibraryType>(this->getDdManager(), internalBdd && other.internalBdd, Dd<LibraryType>::joinMetaVariables(*this, other));
142}
143
144template<DdType LibraryType>
146 this->addMetaVariables(other.getContainedMetaVariables());
147 internalBdd &= other.internalBdd;
148 return *this;
149}
150
151template<DdType LibraryType>
153 return Bdd<LibraryType>(this->getDdManager(), internalBdd.iff(other.internalBdd), Dd<LibraryType>::joinMetaVariables(*this, other));
155
156template<DdType LibraryType>
158 return Bdd<LibraryType>(this->getDdManager(), internalBdd.exclusiveOr(other.internalBdd), Dd<LibraryType>::joinMetaVariables(*this, other));
159}
160
161template<DdType LibraryType>
163 return Bdd<LibraryType>(this->getDdManager(), internalBdd.implies(other.internalBdd), Dd<LibraryType>::joinMetaVariables(*this, other));
164}
165
166template<DdType LibraryType>
168 return Bdd<LibraryType>(this->getDdManager(), !internalBdd, this->getContainedMetaVariables());
169}
171template<DdType LibraryType>
173 internalBdd.complement();
174 return *this;
175}
176
177template<DdType LibraryType>
178Bdd<LibraryType> Bdd<LibraryType>::existsAbstract(std::set<storm::expressions::Variable> const& metaVariables) const {
179 Bdd<LibraryType> cube = getCube(this->getDdManager(), metaVariables);
180 return Bdd<LibraryType>(this->getDdManager(), internalBdd.existsAbstract(cube.getInternalBdd()), Dd<LibraryType>::subtractMetaVariables(*this, cube));
181}
182
183template<DdType LibraryType>
184Bdd<LibraryType> Bdd<LibraryType>::existsAbstractRepresentative(std::set<storm::expressions::Variable> const& metaVariables) const {
185 Bdd<LibraryType> cube = getCube(this->getDdManager(), metaVariables);
186 return Bdd<LibraryType>(this->getDdManager(), internalBdd.existsAbstractRepresentative(cube.getInternalBdd()), this->getContainedMetaVariables());
187}
188
189template<DdType LibraryType>
190Bdd<LibraryType> Bdd<LibraryType>::universalAbstract(std::set<storm::expressions::Variable> const& metaVariables) const {
191 Bdd<LibraryType> cube = getCube(this->getDdManager(), metaVariables);
192 return Bdd<LibraryType>(this->getDdManager(), internalBdd.universalAbstract(cube.getInternalBdd()), Dd<LibraryType>::subtractMetaVariables(*this, cube));
193}
194
195template<DdType LibraryType>
196Bdd<LibraryType> Bdd<LibraryType>::andExists(Bdd<LibraryType> const& other, std::set<storm::expressions::Variable> const& existentialVariables) const {
197 Bdd<LibraryType> cube = getCube(this->getDdManager(), existentialVariables);
198
199 std::set<storm::expressions::Variable> unionOfMetaVariables;
200 std::set_union(this->getContainedMetaVariables().begin(), this->getContainedMetaVariables().end(), other.getContainedMetaVariables().begin(),
201 other.getContainedMetaVariables().end(), std::inserter(unionOfMetaVariables, unionOfMetaVariables.begin()));
202 std::set<storm::expressions::Variable> containedMetaVariables;
203 std::set_difference(unionOfMetaVariables.begin(), unionOfMetaVariables.end(), existentialVariables.begin(), existentialVariables.end(),
204 std::inserter(containedMetaVariables, containedMetaVariables.begin()));
205
206 return Bdd<LibraryType>(this->getDdManager(), internalBdd.andExists(other.getInternalBdd(), cube.getInternalBdd()), containedMetaVariables);
207}
209template<DdType LibraryType>
211 return Bdd<LibraryType>(this->getDdManager(), internalBdd.constrain(constraint.getInternalBdd()), Dd<LibraryType>::joinMetaVariables(*this, constraint));
212}
213
214template<DdType LibraryType>
216 return Bdd<LibraryType>(this->getDdManager(), internalBdd.restrict(constraint.getInternalBdd()), Dd<LibraryType>::joinMetaVariables(*this, constraint));
217}
218
219template<DdType LibraryType>
220Bdd<LibraryType> Bdd<LibraryType>::relationalProduct(Bdd<LibraryType> const& relation, std::set<storm::expressions::Variable> const& rowMetaVariables,
221 std::set<storm::expressions::Variable> const& columnMetaVariables) const {
222 std::set<storm::expressions::Variable> newMetaVariables;
223 std::set_difference(relation.getContainedMetaVariables().begin(), relation.getContainedMetaVariables().end(), columnMetaVariables.begin(),
224 columnMetaVariables.end(), std::inserter(newMetaVariables, newMetaVariables.begin()));
226 std::vector<InternalBdd<LibraryType>> rowVariables;
227 for (auto const& metaVariable : rowMetaVariables) {
228 DdMetaVariable<LibraryType> const& variable = this->getDdManager().getMetaVariable(metaVariable);
229 for (auto const& ddVariable : variable.getDdVariables()) {
230 rowVariables.push_back(ddVariable.getInternalBdd());
231 }
232 }
233
234 std::vector<InternalBdd<LibraryType>> columnVariables;
235 for (auto const& metaVariable : columnMetaVariables) {
236 DdMetaVariable<LibraryType> const& variable = this->getDdManager().getMetaVariable(metaVariable);
237 for (auto const& ddVariable : variable.getDdVariables()) {
238 columnVariables.push_back(ddVariable.getInternalBdd());
239 }
240 }
241
242 return Bdd<LibraryType>(this->getDdManager(), internalBdd.relationalProduct(relation.getInternalBdd(), rowVariables, columnVariables), newMetaVariables);
243}
244
245template<DdType LibraryType>
246Bdd<LibraryType> Bdd<LibraryType>::inverseRelationalProduct(Bdd<LibraryType> const& relation, std::set<storm::expressions::Variable> const& rowMetaVariables,
247 std::set<storm::expressions::Variable> const& columnMetaVariables) const {
248 std::set<storm::expressions::Variable> newMetaVariables;
249 std::set_difference(relation.getContainedMetaVariables().begin(), relation.getContainedMetaVariables().end(), columnMetaVariables.begin(),
250 columnMetaVariables.end(), std::inserter(newMetaVariables, newMetaVariables.begin()));
251
252 std::vector<InternalBdd<LibraryType>> rowVariables;
253 for (auto const& metaVariable : rowMetaVariables) {
254 DdMetaVariable<LibraryType> const& variable = this->getDdManager().getMetaVariable(metaVariable);
255 for (auto const& ddVariable : variable.getDdVariables()) {
256 rowVariables.push_back(ddVariable.getInternalBdd());
258 }
259
260 std::vector<InternalBdd<LibraryType>> columnVariables;
261 for (auto const& metaVariable : columnMetaVariables) {
262 DdMetaVariable<LibraryType> const& variable = this->getDdManager().getMetaVariable(metaVariable);
263 for (auto const& ddVariable : variable.getDdVariables()) {
264 columnVariables.push_back(ddVariable.getInternalBdd());
265 }
266 }
267
268 return Bdd<LibraryType>(this->getDdManager(), internalBdd.inverseRelationalProduct(relation.getInternalBdd(), rowVariables, columnVariables),
269 newMetaVariables);
271
272template<DdType LibraryType>
274 std::set<storm::expressions::Variable> const& rowMetaVariables,
275 std::set<storm::expressions::Variable> const& columnMetaVariables) const {
276 std::set<storm::expressions::Variable> newMetaVariables;
277 std::set_difference(relation.getContainedMetaVariables().begin(), relation.getContainedMetaVariables().end(), columnMetaVariables.begin(),
278 columnMetaVariables.end(), std::inserter(newMetaVariables, newMetaVariables.begin()));
279
280 std::vector<InternalBdd<LibraryType>> rowVariables;
281 for (auto const& metaVariable : rowMetaVariables) {
282 DdMetaVariable<LibraryType> const& variable = this->getDdManager().getMetaVariable(metaVariable);
283 for (auto const& ddVariable : variable.getDdVariables()) {
284 rowVariables.push_back(ddVariable.getInternalBdd());
285 }
286 }
287
288 std::vector<InternalBdd<LibraryType>> columnVariables;
289 for (auto const& metaVariable : columnMetaVariables) {
290 DdMetaVariable<LibraryType> const& variable = this->getDdManager().getMetaVariable(metaVariable);
291 for (auto const& ddVariable : variable.getDdVariables()) {
292 columnVariables.push_back(ddVariable.getInternalBdd());
293 }
295
296 return Bdd<LibraryType>(this->getDdManager(),
297 internalBdd.inverseRelationalProductWithExtendedRelation(relation.getInternalBdd(), rowVariables, columnVariables),
298 newMetaVariables);
299}
300
301template<DdType LibraryType>
303 std::vector<std::pair<storm::expressions::Variable, storm::expressions::Variable>> const& metaVariablePairs) const {
304 std::set<storm::expressions::Variable> newContainedMetaVariables;
305 std::set<storm::expressions::Variable> deletedMetaVariables;
306 std::vector<InternalBdd<LibraryType>> from;
307 std::vector<InternalBdd<LibraryType>> to;
308 for (auto const& metaVariablePair : metaVariablePairs) {
309 DdMetaVariable<LibraryType> const& variable1 = this->getDdManager().getMetaVariable(metaVariablePair.first);
310 DdMetaVariable<LibraryType> const& variable2 = this->getDdManager().getMetaVariable(metaVariablePair.second);
311
312 // Keep track of the contained meta variables in the DD.
313 if (this->containsMetaVariable(metaVariablePair.first)) {
314 if (this->containsMetaVariable(metaVariablePair.second)) {
315 // Nothing to do here.
316 } else {
317 newContainedMetaVariables.insert(metaVariablePair.second);
318 deletedMetaVariables.insert(metaVariablePair.first);
319 }
320 } else {
321 if (!this->containsMetaVariable(metaVariablePair.second)) {
322 // Nothing to do here.
323 } else {
324 newContainedMetaVariables.insert(metaVariablePair.first);
325 deletedMetaVariables.insert(metaVariablePair.second);
326 }
327 }
328
329 for (auto const& ddVariable : variable1.getDdVariables()) {
330 from.emplace_back(ddVariable.getInternalBdd());
332 for (auto const& ddVariable : variable2.getDdVariables()) {
333 to.emplace_back(ddVariable.getInternalBdd());
334 }
335 }
336
337 std::set<storm::expressions::Variable> tmp;
338 std::set_difference(this->getContainedMetaVariables().begin(), this->getContainedMetaVariables().end(), deletedMetaVariables.begin(),
339 deletedMetaVariables.end(), std::inserter(tmp, tmp.begin()));
340 std::set<storm::expressions::Variable> containedMetaVariables;
341 std::set_union(tmp.begin(), tmp.end(), newContainedMetaVariables.begin(), newContainedMetaVariables.end(),
342 std::inserter(containedMetaVariables, containedMetaVariables.begin()));
343 return Bdd<LibraryType>(this->getDdManager(), internalBdd.swapVariables(from, to), containedMetaVariables);
344}
346template<DdType LibraryType>
347Bdd<LibraryType> Bdd<LibraryType>::renameVariables(std::set<storm::expressions::Variable> const& from, std::set<storm::expressions::Variable> const& to) const {
348 std::vector<InternalBdd<LibraryType>> fromBdds;
349 std::vector<InternalBdd<LibraryType>> toBdds;
350
351 for (auto const& metaVariable : from) {
352 STORM_LOG_THROW(this->containsMetaVariable(metaVariable), storm::exceptions::InvalidOperationException,
353 "Cannot rename variable '" << metaVariable.getName() << "' that is not present.");
354 DdMetaVariable<LibraryType> const& ddMetaVariable = this->getDdManager().getMetaVariable(metaVariable);
355 for (auto const& ddVariable : ddMetaVariable.getDdVariables()) {
356 fromBdds.push_back(ddVariable.getInternalBdd());
357 }
359 for (auto const& metaVariable : to) {
360 STORM_LOG_THROW(!this->containsMetaVariable(metaVariable), storm::exceptions::InvalidOperationException,
361 "Cannot rename to variable '" << metaVariable.getName() << "' that is already present.");
362 DdMetaVariable<LibraryType> const& ddMetaVariable = this->getDdManager().getMetaVariable(metaVariable);
363 for (auto const& ddVariable : ddMetaVariable.getDdVariables()) {
364 toBdds.push_back(ddVariable.getInternalBdd());
365 }
366 }
368 std::set<storm::expressions::Variable> newContainedMetaVariables = to;
369 std::set_difference(this->getContainedMetaVariables().begin(), this->getContainedMetaVariables().end(), from.begin(), from.end(),
370 std::inserter(newContainedMetaVariables, newContainedMetaVariables.begin()));
371
372 STORM_LOG_THROW(fromBdds.size() == toBdds.size(), storm::exceptions::InvalidArgumentException, "Unable to rename mismatching meta variables.");
373 return Bdd<LibraryType>(this->getDdManager(), internalBdd.swapVariables(fromBdds, toBdds), newContainedMetaVariables);
374}
375
376template<DdType LibraryType>
377Bdd<LibraryType> Bdd<LibraryType>::renameVariablesAbstract(std::set<storm::expressions::Variable> const& from,
378 std::set<storm::expressions::Variable> const& to) const {
379 std::vector<InternalBdd<LibraryType>> fromBdds;
380 std::vector<InternalBdd<LibraryType>> toBdds;
382 for (auto const& metaVariable : from) {
383 STORM_LOG_THROW(this->containsMetaVariable(metaVariable), storm::exceptions::InvalidOperationException,
384 "Cannot rename variable '" << metaVariable.getName() << "' that is not present.");
385 DdMetaVariable<LibraryType> const& ddMetaVariable = this->getDdManager().getMetaVariable(metaVariable);
386 for (auto const& ddVariable : ddMetaVariable.getDdVariables()) {
387 fromBdds.push_back(ddVariable.getInternalBdd());
388 }
390 std::sort(fromBdds.begin(), fromBdds.end(),
391 [](InternalBdd<LibraryType> const& a, InternalBdd<LibraryType> const& b) { return a.getLevel() < b.getLevel(); });
392 for (auto const& metaVariable : to) {
393 STORM_LOG_THROW(!this->containsMetaVariable(metaVariable), storm::exceptions::InvalidOperationException,
394 "Cannot rename to variable '" << metaVariable.getName() << "' that is already present.");
395 DdMetaVariable<LibraryType> const& ddMetaVariable = this->getDdManager().getMetaVariable(metaVariable);
396 for (auto const& ddVariable : ddMetaVariable.getDdVariables()) {
397 toBdds.push_back(ddVariable.getInternalBdd());
398 }
399 }
400 std::sort(toBdds.begin(), toBdds.end(), [](InternalBdd<LibraryType> const& a, InternalBdd<LibraryType> const& b) { return a.getLevel() < b.getLevel(); });
402 std::set<storm::expressions::Variable> newContainedMetaVariables = to;
403 std::set_difference(this->getContainedMetaVariables().begin(), this->getContainedMetaVariables().end(), from.begin(), from.end(),
404 std::inserter(newContainedMetaVariables, newContainedMetaVariables.begin()));
405
406 STORM_LOG_ASSERT(fromBdds.size() >= toBdds.size(), "Unable to perform rename-abstract with mismatching sizes.");
407
408 if (fromBdds.size() == toBdds.size()) {
409 return Bdd<LibraryType>(this->getDdManager(), internalBdd.swapVariables(fromBdds, toBdds), newContainedMetaVariables);
410 } else {
411 InternalBdd<LibraryType> cube = this->getDdManager().getBddOne().getInternalBdd();
412 for (uint64_t index = toBdds.size(); index < fromBdds.size(); ++index) {
413 cube &= fromBdds[index];
414 }
415 fromBdds.resize(toBdds.size());
416
417 return Bdd<LibraryType>(this->getDdManager(), internalBdd.existsAbstract(cube).swapVariables(fromBdds, toBdds), newContainedMetaVariables);
419}
420
421template<DdType LibraryType>
422Bdd<LibraryType> Bdd<LibraryType>::renameVariablesConcretize(std::set<storm::expressions::Variable> const& from,
423 std::set<storm::expressions::Variable> const& to) const {
424 std::vector<InternalBdd<LibraryType>> fromBdds;
425 std::vector<InternalBdd<LibraryType>> toBdds;
426
427 for (auto const& metaVariable : from) {
428 STORM_LOG_THROW(this->containsMetaVariable(metaVariable), storm::exceptions::InvalidOperationException,
429 "Cannot rename variable '" << metaVariable.getName() << "' that is not present.");
430 DdMetaVariable<LibraryType> const& ddMetaVariable = this->getDdManager().getMetaVariable(metaVariable);
431 for (auto const& ddVariable : ddMetaVariable.getDdVariables()) {
432 fromBdds.push_back(ddVariable.getInternalBdd());
433 }
434 }
435 std::sort(fromBdds.begin(), fromBdds.end(),
436 [](InternalBdd<LibraryType> const& a, InternalBdd<LibraryType> const& b) { return a.getLevel() < b.getLevel(); });
437 for (auto const& metaVariable : to) {
438 STORM_LOG_THROW(!this->containsMetaVariable(metaVariable), storm::exceptions::InvalidOperationException,
439 "Cannot rename to variable '" << metaVariable.getName() << "' that is already present.");
440 DdMetaVariable<LibraryType> const& ddMetaVariable = this->getDdManager().getMetaVariable(metaVariable);
441 for (auto const& ddVariable : ddMetaVariable.getDdVariables()) {
442 toBdds.push_back(ddVariable.getInternalBdd());
443 }
444 }
445 std::sort(toBdds.begin(), toBdds.end(), [](InternalBdd<LibraryType> const& a, InternalBdd<LibraryType> const& b) { return a.getLevel() < b.getLevel(); });
446
447 std::set<storm::expressions::Variable> newContainedMetaVariables = to;
448 std::set_difference(this->getContainedMetaVariables().begin(), this->getContainedMetaVariables().end(), from.begin(), from.end(),
449 std::inserter(newContainedMetaVariables, newContainedMetaVariables.begin()));
450
451 STORM_LOG_ASSERT(toBdds.size() >= fromBdds.size(), "Unable to perform rename-concretize with mismatching sizes.");
452
453 if (fromBdds.size() == toBdds.size()) {
454 return Bdd<LibraryType>(this->getDdManager(), internalBdd.swapVariables(fromBdds, toBdds), newContainedMetaVariables);
455 } else {
456 InternalBdd<LibraryType> negatedCube = this->getDdManager().getBddOne().getInternalBdd();
457 for (uint64_t index = fromBdds.size(); index < toBdds.size(); ++index) {
458 negatedCube &= !toBdds[index];
459 }
460 toBdds.resize(fromBdds.size());
461
462 return Bdd<LibraryType>(this->getDdManager(), (internalBdd && negatedCube).swapVariables(fromBdds, toBdds), newContainedMetaVariables);
463 }
464}
465
466template<DdType LibraryType>
467template<typename ValueType>
469 return Add<LibraryType, ValueType>(this->getDdManager(), internalBdd.template toAdd<ValueType>(), this->getContainedMetaVariables());
470}
471
472template<DdType LibraryType>
473std::vector<Bdd<LibraryType>> Bdd<LibraryType>::split(std::set<storm::expressions::Variable> const& variables) const {
474 std::set<storm::expressions::Variable> remainingMetaVariables;
475 std::set_difference(this->getContainedMetaVariables().begin(), this->getContainedMetaVariables().end(), variables.begin(), variables.end(),
476 std::inserter(remainingMetaVariables, remainingMetaVariables.begin()));
477
478 std::vector<uint_fast64_t> ddGroupVariableIndices;
479 for (auto const& variable : variables) {
480 DdMetaVariable<LibraryType> const& metaVariable = this->getDdManager().getMetaVariable(variable);
481 for (auto const& ddVariable : metaVariable.getDdVariables()) {
482 ddGroupVariableIndices.push_back(ddVariable.getIndex());
483 }
484 }
485 std::sort(ddGroupVariableIndices.begin(), ddGroupVariableIndices.end());
486
487 std::vector<InternalBdd<LibraryType>> internalBddGroups = this->internalBdd.splitIntoGroups(ddGroupVariableIndices);
488 std::vector<Bdd<LibraryType>> groups;
489 for (auto const& internalBdd : internalBddGroups) {
490 groups.emplace_back(Bdd<LibraryType>(this->getDdManager(), internalBdd, remainingMetaVariables));
491 }
492
493 return groups;
494}
495
496template<DdType LibraryType>
498 return internalBdd.toVector(rowOdd, this->getSortedVariableIndices());
499}
500
501template<DdType LibraryType>
502std::pair<std::vector<storm::expressions::Expression>, std::unordered_map<uint_fast64_t, storm::expressions::Variable>> Bdd<LibraryType>::toExpression(
504 return internalBdd.toExpression(manager);
505}
506
507template<DdType LibraryType>
509 return Bdd<LibraryType>(this->getDdManager(), internalBdd.getSupport(), this->getContainedMetaVariables());
510}
511
512template<DdType LibraryType>
514 std::size_t numberOfDdVariables = 0;
515 for (auto const& metaVariable : this->getContainedMetaVariables()) {
516 numberOfDdVariables += this->getDdManager().getMetaVariable(metaVariable).getNumberOfDdVariables();
517 }
518 return internalBdd.getNonZeroCount(numberOfDdVariables);
519}
520
521template<DdType LibraryType>
522uint_fast64_t Bdd<LibraryType>::getLeafCount() const {
523 return internalBdd.getLeafCount();
524}
525
526template<DdType LibraryType>
527uint_fast64_t Bdd<LibraryType>::getNodeCount() const {
528 return internalBdd.getNodeCount();
529}
530
531template<DdType LibraryType>
532uint_fast64_t Bdd<LibraryType>::getIndex() const {
533 return internalBdd.getIndex();
534}
535
536template<DdType LibraryType>
537uint_fast64_t Bdd<LibraryType>::getLevel() const {
538 return internalBdd.getLevel();
539}
540
541template<DdType LibraryType>
543 return internalBdd.isOne();
544}
545
546template<DdType LibraryType>
548 return internalBdd.isZero();
549}
550
551template<DdType LibraryType>
552void Bdd<LibraryType>::exportToDot(std::string const& filename, bool showVariablesIfPossible) const {
553 internalBdd.exportToDot(filename, this->getDdManager().getDdVariableNames(), showVariablesIfPossible);
554}
555
556template<DdType LibraryType>
557void Bdd<LibraryType>::exportToText(std::string const& filename) const {
558 internalBdd.exportToText(filename);
559}
560
561template<DdType LibraryType>
562Bdd<LibraryType> Bdd<LibraryType>::getCube(DdManager<LibraryType> const& manager, std::set<storm::expressions::Variable> const& metaVariables) {
563 Bdd<LibraryType> cube = manager.getBddOne();
564 for (auto const& metaVariable : metaVariables) {
565 cube &= manager.getMetaVariable(metaVariable).getCube();
566 }
567 return cube;
568}
569
570template<DdType LibraryType>
572 return internalBdd.createOdd(this->getSortedVariableIndices());
573}
574
575template<DdType LibraryType>
577 return internalBdd;
578}
579
580template<DdType LibraryType>
581template<typename ValueType>
582std::vector<ValueType> Bdd<LibraryType>::filterExplicitVector(Odd const& odd, std::vector<ValueType> const& values) const {
583 std::vector<ValueType> result(this->getNonZeroCount());
584 internalBdd.filterExplicitVector(odd, this->getSortedVariableIndices(), values, result);
585 return result;
586}
587
588template<DdType LibraryType>
590 storm::storage::BitVector result(this->getNonZeroCount());
591 internalBdd.filterExplicitVector(odd, this->getSortedVariableIndices(), values, result);
592 return result;
593}
594
595template class Bdd<DdType::CUDD>;
596
597template Bdd<DdType::CUDD> Bdd<DdType::CUDD>::fromVector(DdManager<DdType::CUDD> const& ddManager, std::vector<double> const& explicitValues,
598 storm::dd::Odd const& odd, std::set<storm::expressions::Variable> const& metaVariables,
599 storm::logic::ComparisonType comparisonType, double value);
600
604
605template std::vector<double> Bdd<DdType::CUDD>::filterExplicitVector(Odd const& odd, std::vector<double> const& values) const;
606template std::vector<uint_fast64_t> Bdd<DdType::CUDD>::filterExplicitVector(Odd const& odd, std::vector<uint_fast64_t> const& values) const;
607
610 Add<DdType::CUDD, uint_fast64_t> const& elseAdd) const;
611#ifdef STORM_HAVE_CARL
613 Add<DdType::CUDD, storm::RationalNumber> const& elseAdd) const;
614#endif
615
616template class Bdd<DdType::Sylvan>;
617
618template Bdd<DdType::Sylvan> Bdd<DdType::Sylvan>::fromVector(DdManager<DdType::Sylvan> const& ddManager, std::vector<double> const& explicitValues,
619 storm::dd::Odd const& odd, std::set<storm::expressions::Variable> const& metaVariables,
620 storm::logic::ComparisonType comparisonType, double value);
621
622#ifdef STORM_HAVE_CARL
624 std::vector<storm::RationalNumber> const& explicitValues, storm::dd::Odd const& odd,
625 std::set<storm::expressions::Variable> const& metaVariables,
626 storm::logic::ComparisonType comparisonType, storm::RationalNumber value);
628 std::vector<storm::RationalFunction> const& explicitValues, storm::dd::Odd const& odd,
629 std::set<storm::expressions::Variable> const& metaVariables,
631#endif
632
635
636#ifdef STORM_HAVE_CARL
639#endif
640
641template std::vector<double> Bdd<DdType::Sylvan>::filterExplicitVector(Odd const& odd, std::vector<double> const& values) const;
642template std::vector<uint_fast64_t> Bdd<DdType::Sylvan>::filterExplicitVector(Odd const& odd, std::vector<uint_fast64_t> const& values) const;
643
644#ifdef STORM_HAVE_CARL
645template std::vector<storm::RationalNumber> Bdd<DdType::Sylvan>::filterExplicitVector(Odd const& odd, std::vector<storm::RationalNumber> const& values) const;
646template std::vector<storm::RationalFunction> Bdd<DdType::Sylvan>::filterExplicitVector(Odd const& odd,
647 std::vector<storm::RationalFunction> const& values) const;
648#endif
649
652 Add<DdType::Sylvan, uint_fast64_t> const& elseAdd) const;
653
654#ifdef STORM_HAVE_CARL
656 Add<DdType::Sylvan, storm::RationalNumber> const& elseAdd) const;
659#endif
660} // namespace dd
661} // namespace storm
Bdd< LibraryType > renameVariablesAbstract(std::set< storm::expressions::Variable > const &from, std::set< storm::expressions::Variable > const &to) const
Renames the given meta variables in the BDD.
Definition Bdd.cpp:377
virtual uint_fast64_t getLevel() const override
Retrieves the level of the topmost variable in the DD.
Definition Bdd.cpp:537
static Bdd< LibraryType > fromVector(DdManager< LibraryType > const &ddManager, storm::storage::BitVector const &truthValues, storm::dd::Odd const &odd, std::set< storm::expressions::Variable > const &metaVariables)
Constructs a BDD representation of all encodings whose value is true in the given list of truth value...
Definition Bdd.cpp:85
Bdd< LibraryType > existsAbstract(std::set< storm::expressions::Variable > const &metaVariables) const
Existentially abstracts from the given meta variables.
Definition Bdd.cpp:178
Bdd< LibraryType > inverseRelationalProduct(Bdd< LibraryType > const &relation, std::set< storm::expressions::Variable > const &rowMetaVariables, std::set< storm::expressions::Variable > const &columnMetaVariables) const
Computes the inverse relational product of the current BDD and the given BDD representing a relation.
Definition Bdd.cpp:246
bool isZero() const
Retrieves whether this DD represents the constant zero function.
Definition Bdd.cpp:547
virtual uint_fast64_t getNonZeroCount() const override
Retrieves the number of encodings that are mapped to a non-zero value.
Definition Bdd.cpp:513
bool operator!=(Bdd< LibraryType > const &other) const
Retrieves whether the two BDDs represent different functions.
Definition Bdd.cpp:108
virtual uint_fast64_t getIndex() const override
Retrieves the index of the topmost variable in the DD.
Definition Bdd.cpp:532
Bdd< LibraryType > & operator&=(Bdd< LibraryType > const &other)
Performs a logical and of the current and the given BDD and assigns it to the current BDD.
Definition Bdd.cpp:145
std::pair< std::vector< storm::expressions::Expression >, std::unordered_map< uint_fast64_t, storm::expressions::Variable > > toExpression(storm::expressions::ExpressionManager &manager) const
Translates the function the BDD is representing to a set of expressions that characterize the functio...
Definition Bdd.cpp:502
Bdd< LibraryType > andExists(Bdd< LibraryType > const &other, std::set< storm::expressions::Variable > const &existentialVariables) const
Computes the logical and of the current and the given BDD and existentially abstracts from the given ...
Definition Bdd.cpp:196
static Bdd< LibraryType > getEncoding(DdManager< LibraryType > const &ddManager, uint64_t targetOffset, storm::dd::Odd const &odd, std::set< storm::expressions::Variable > const &metaVariables)
Constructs the BDD representation of the encoding with the given offset.
Definition Bdd.cpp:94
virtual uint_fast64_t getNodeCount() const override
Retrieves the number of nodes necessary to represent the DD.
Definition Bdd.cpp:527
Bdd< LibraryType > swapVariables(std::vector< std::pair< storm::expressions::Variable, storm::expressions::Variable > > const &metaVariablePairs) const
Swaps the given pairs of meta variables in the BDD.
Definition Bdd.cpp:302
Bdd< LibraryType > & complement()
Logically complements the current BDD.
Definition Bdd.cpp:172
Odd createOdd() const
Creates an ODD based on the current BDD.
Definition Bdd.cpp:571
Bdd< LibraryType > operator&&(Bdd< LibraryType > const &other) const
Performs a logical and of the current and the given BDD.
Definition Bdd.cpp:140
storm::storage::BitVector toVector(storm::dd::Odd const &rowOdd) const
Converts the BDD to a bit vector.
Definition Bdd.cpp:497
Bdd< LibraryType > existsAbstractRepresentative(std::set< storm::expressions::Variable > const &metaVariables) const
Similar to existsAbstract, but does not abstract from the variables but rather picks a valuation of e...
Definition Bdd.cpp:184
static Bdd< LibraryType > getCube(DdManager< LibraryType > const &manager, std::set< storm::expressions::Variable > const &metaVariables)
Retrieves the cube of all given meta variables.
Definition Bdd.cpp:562
Bdd< LibraryType > universalAbstract(std::set< storm::expressions::Variable > const &metaVariables) const
Universally abstracts from the given meta variables.
Definition Bdd.cpp:190
virtual Bdd< LibraryType > getSupport() const override
Retrieves the support of the current DD.
Definition Bdd.cpp:508
Add< LibraryType, ValueType > toAdd() const
Converts a BDD to an equivalent ADD.
Definition Bdd.cpp:468
Bdd< LibraryType > constrain(Bdd< LibraryType > const &constraint) const
Computes the constraint of the current BDD with the given constraint.
Definition Bdd.cpp:210
Bdd< LibraryType > & operator|=(Bdd< LibraryType > const &other)
Performs a logical or of the current and the given BDD and assigns it to the current BDD.
Definition Bdd.cpp:133
std::vector< Bdd< LibraryType > > split(std::set< storm::expressions::Variable > const &variables) const
Splits the BDD along the given variables (must be at the top).
Definition Bdd.cpp:473
Bdd< LibraryType > ite(Bdd< LibraryType > const &thenBdd, Bdd< LibraryType > const &elseBdd) const
Performs an if-then-else with the given operands, i.e.
Definition Bdd.cpp:113
Bdd< LibraryType > operator!() const
Logically inverts the current BDD.
Definition Bdd.cpp:167
Bdd< LibraryType > iff(Bdd< LibraryType > const &other) const
Performs a logical iff of the current and the given BDD.
Definition Bdd.cpp:152
virtual void exportToDot(std::string const &filename, bool showVariablesIfPossible=true) const override
Exports the DD to the given file in the dot format.
Definition Bdd.cpp:552
Bdd< LibraryType > renameVariables(std::set< storm::expressions::Variable > const &from, std::set< storm::expressions::Variable > const &to) const
Renames the given meta variables in the BDD.
Definition Bdd.cpp:347
Bdd< LibraryType > inverseRelationalProductWithExtendedRelation(Bdd< LibraryType > const &relation, std::set< storm::expressions::Variable > const &rowMetaVariables, std::set< storm::expressions::Variable > const &columnMetaVariables) const
Computes the inverse relational product of the current BDD and the given BDD representing a relation ...
Definition Bdd.cpp:273
bool isOne() const
Retrieves whether this DD represents the constant one function.
Definition Bdd.cpp:542
Bdd()=default
Bdd< LibraryType > exclusiveOr(Bdd< LibraryType > const &other) const
Performs a logical exclusive-or of the current and the given BDD.
Definition Bdd.cpp:157
Bdd< LibraryType > relationalProduct(Bdd< LibraryType > const &relation, std::set< storm::expressions::Variable > const &rowMetaVariables, std::set< storm::expressions::Variable > const &columnMetaVariables) const
Computes the relational product of the current BDD and the given BDD representing a relation.
Definition Bdd.cpp:220
virtual void exportToText(std::string const &filename) const override
Exports the DD to the given file in the dot format.
Definition Bdd.cpp:557
Bdd< LibraryType > restrict(Bdd< LibraryType > const &constraint) const
Computes the restriction of the current BDD with the given constraint.
Definition Bdd.cpp:215
Bdd< LibraryType > implies(Bdd< LibraryType > const &other) const
Performs a logical implication of the current and the given BDD.
Definition Bdd.cpp:162
Bdd< LibraryType > renameVariablesConcretize(std::set< storm::expressions::Variable > const &from, std::set< storm::expressions::Variable > const &to) const
Renames the given meta variables in the BDD.
Definition Bdd.cpp:422
InternalBdd< LibraryType > const & getInternalBdd() const
Retrieves the internal BDD.
Definition Bdd.cpp:576
std::vector< ValueType > filterExplicitVector(Odd const &odd, std::vector< ValueType > const &values) const
Filters the given explicit vector using the symbolic representation of which values to select.
Definition Bdd.cpp:582
bool operator==(Bdd< LibraryType > const &other) const
Retrieves whether the two BDDs represent the same function.
Definition Bdd.cpp:103
Bdd< LibraryType > operator||(Bdd< LibraryType > const &other) const
Performs a logical or of the current and the given BDD.
Definition Bdd.cpp:128
virtual uint_fast64_t getLeafCount() const override
Retrieves the number of leaves of the DD.
Definition Bdd.cpp:522
static std::set< storm::expressions::Variable > joinMetaVariables(storm::dd::Dd< LibraryType > const &first, storm::dd::Dd< LibraryType > const &second)
Retrieves the set of meta variables contained in both DDs.
Definition Dd.cpp:75
std::set< storm::expressions::Variable > const & getContainedMetaVariables() const
Retrieves the set of all meta variables contained in the DD.
Definition Dd.cpp:29
std::vector< uint_fast64_t > getSortedVariableIndices() const
Retrieves the (sorted) list of the variable indices of the DD variables given by the meta variable se...
InternalDdManager< LibraryType > & getInternalDdManager()
Retrieves the internal DD manager.
This class is responsible for managing a set of typed variables and all expressions using these varia...
A bit vector that is internally represented as a vector of 64-bit values.
Definition BitVector.h:18
#define STORM_LOG_ASSERT(cond, message)
Definition macros.h:11
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:30
LabParser.cpp.
Definition cli.cpp:18
static Bdd< LibraryType > fromVector(DdManager< LibraryType > const &, std::vector< storm::RationalFunction > const &, storm::dd::Odd const &, std::set< storm::expressions::Variable > const &, storm::logic::ComparisonType, storm::RationalFunction)
Definition Bdd.cpp:69
static Bdd< LibraryType > fromVector(DdManager< LibraryType > const &ddManager, std::vector< ValueType > const &explicitValues, storm::dd::Odd const &odd, std::set< storm::expressions::Variable > const &metaVariables, storm::logic::ComparisonType comparisonType, ValueType value)
Definition Bdd.cpp:34