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