Storm 2.0.0.3
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
Add.cpp
Go to the documentation of this file.
1#include "storm/dd/Add.h"
2
3#include <boost/algorithm/string/join.hpp>
4
8#include "storm/dd/Odd.h"
15
16namespace storm {
17namespace dd {
18template<DdType LibraryType, typename ValueType>
20 std::set<storm::expressions::Variable> const& containedMetaVariables)
21 : Dd<LibraryType>(ddManager, containedMetaVariables), internalAdd(internalAdd) {
22 // Intentionally left empty.
23}
24
25template<DdType LibraryType, typename ValueType>
27 return internalAdd == other.internalAdd;
28}
29
30template<DdType LibraryType, typename ValueType>
32 return internalAdd != other.internalAdd;
33}
34
35template<DdType LibraryType, typename ValueType>
39
40template<DdType LibraryType, typename ValueType>
43 internalAdd += other.internalAdd;
44 return *this;
45}
46
47template<DdType LibraryType, typename ValueType>
51
52template<DdType LibraryType, typename ValueType>
55 internalAdd *= other.internalAdd;
56 return *this;
57}
58
59template<DdType LibraryType, typename ValueType>
63
64template<DdType LibraryType, typename ValueType>
66 return this->getDdManager().template getAddZero<ValueType>() - *this;
67}
68
69template<DdType LibraryType, typename ValueType>
72 internalAdd -= other.internalAdd;
73 return *this;
74}
75
76template<DdType LibraryType, typename ValueType>
80
81template<DdType LibraryType, typename ValueType>
84 internalAdd /= other.internalAdd;
85 return *this;
86}
87
88template<DdType LibraryType, typename ValueType>
92
93template<DdType LibraryType, typename ValueType>
98template<DdType LibraryType, typename ValueType>
100 return Bdd<LibraryType>(this->getDdManager(), internalAdd.less(other), Dd<LibraryType>::joinMetaVariables(*this, other));
101}
102
103template<DdType LibraryType, typename ValueType>
105 return Bdd<LibraryType>(this->getDdManager(), internalAdd.lessOrEqual(other), Dd<LibraryType>::joinMetaVariables(*this, other));
106}
107
108template<DdType LibraryType, typename ValueType>
110 return Bdd<LibraryType>(this->getDdManager(), internalAdd.greater(other), Dd<LibraryType>::joinMetaVariables(*this, other));
111}
112
113template<DdType LibraryType, typename ValueType>
115 return Bdd<LibraryType>(this->getDdManager(), internalAdd.greaterOrEqual(other), Dd<LibraryType>::joinMetaVariables(*this, other));
116}
117
118template<DdType LibraryType, typename ValueType>
122
123template<DdType LibraryType, typename ValueType>
127
128template<DdType LibraryType, typename ValueType>
132
133template<DdType LibraryType, typename ValueType>
135 return Add<LibraryType, ValueType>(this->getDdManager(), internalAdd.floor(), this->getContainedMetaVariables());
137
138template<DdType LibraryType, typename ValueType>
140 return Add<LibraryType, ValueType>(this->getDdManager(), internalAdd.ceil(), this->getContainedMetaVariables());
141}
142
143template<DdType LibraryType, typename ValueType>
146{
147 return Add<LibraryType, storm::RationalNumber>(this->getDdManager(), internalAdd.sharpenKwekMehlhorn(static_cast<std::size_t>(precision)),
148 this->getContainedMetaVariables());
149}
150
151template<DdType LibraryType, typename ValueType>
155
156template<DdType LibraryType, typename ValueType>
161template<DdType LibraryType, typename ValueType>
162Add<LibraryType, ValueType> Add<LibraryType, ValueType>::sumAbstract(std::set<storm::expressions::Variable> const& metaVariables) const {
163 Bdd<LibraryType> cube = Bdd<LibraryType>::getCube(this->getDdManager(), metaVariables);
164 return Add<LibraryType, ValueType>(this->getDdManager(), internalAdd.sumAbstract(cube.getInternalBdd()),
166}
167
168template<DdType LibraryType, typename ValueType>
169Add<LibraryType, ValueType> Add<LibraryType, ValueType>::minAbstract(std::set<storm::expressions::Variable> const& metaVariables) const {
170 Bdd<LibraryType> cube = Bdd<LibraryType>::getCube(this->getDdManager(), metaVariables);
171 return Add<LibraryType, ValueType>(this->getDdManager(), internalAdd.minAbstract(cube.getInternalBdd()),
173}
174
175template<DdType LibraryType, typename ValueType>
176Bdd<LibraryType> Add<LibraryType, ValueType>::minAbstractRepresentative(std::set<storm::expressions::Variable> const& metaVariables) const {
178 return Bdd<LibraryType>(this->getDdManager(), internalAdd.minAbstractRepresentative(cube.getInternalBdd()), this->getContainedMetaVariables());
179}
180
181template<DdType LibraryType, typename ValueType>
182Add<LibraryType, ValueType> Add<LibraryType, ValueType>::maxAbstract(std::set<storm::expressions::Variable> const& metaVariables) const {
183 Bdd<LibraryType> cube = Bdd<LibraryType>::getCube(this->getDdManager(), metaVariables);
184 return Add<LibraryType, ValueType>(this->getDdManager(), internalAdd.maxAbstract(cube.getInternalBdd()),
187
188template<DdType LibraryType, typename ValueType>
189Bdd<LibraryType> Add<LibraryType, ValueType>::maxAbstractRepresentative(std::set<storm::expressions::Variable> const& metaVariables) const {
190 Bdd<LibraryType> cube = Bdd<LibraryType>::getCube(this->getDdManager(), metaVariables);
191 return Bdd<LibraryType>(this->getDdManager(), internalAdd.maxAbstractRepresentative(cube.getInternalBdd()), this->getContainedMetaVariables());
192}
193
194template<DdType LibraryType, typename ValueType>
195bool Add<LibraryType, ValueType>::equalModuloPrecision(Add<LibraryType, ValueType> const& other, ValueType const& precision, bool relative) const {
196 return internalAdd.equalModuloPrecision(other, precision, relative);
197}
198
199template<DdType LibraryType, typename ValueType>
200Add<LibraryType, ValueType> Add<LibraryType, ValueType>::renameVariables(std::set<storm::expressions::Variable> const& from,
201 std::set<storm::expressions::Variable> const& to) const {
202 std::vector<InternalBdd<LibraryType>> fromBdds;
203 std::vector<InternalBdd<LibraryType>> toBdds;
205 for (auto const& metaVariable : from) {
206 STORM_LOG_THROW(this->containsMetaVariable(metaVariable), storm::exceptions::InvalidOperationException,
207 "Cannot rename variable '" << metaVariable.getName() << "' that is not present.");
208 DdMetaVariable<LibraryType> const& ddMetaVariable = this->getDdManager().getMetaVariable(metaVariable);
209 for (auto const& ddVariable : ddMetaVariable.getDdVariables()) {
210 fromBdds.push_back(ddVariable.getInternalBdd());
211 }
213 for (auto const& metaVariable : to) {
214 STORM_LOG_THROW(!this->containsMetaVariable(metaVariable), storm::exceptions::InvalidOperationException,
215 "Cannot rename to variable '" << metaVariable.getName() << "' that is already present.");
216 DdMetaVariable<LibraryType> const& ddMetaVariable = this->getDdManager().getMetaVariable(metaVariable);
217 for (auto const& ddVariable : ddMetaVariable.getDdVariables()) {
218 toBdds.push_back(ddVariable.getInternalBdd());
219 }
221
222 std::set<storm::expressions::Variable> newContainedMetaVariables = to;
223 std::set_difference(this->getContainedMetaVariables().begin(), this->getContainedMetaVariables().end(), from.begin(), from.end(),
224 std::inserter(newContainedMetaVariables, newContainedMetaVariables.begin()));
225
226 STORM_LOG_THROW(fromBdds.size() == toBdds.size(), storm::exceptions::InvalidArgumentException, "Unable to rename mismatching meta variables.");
227 return Add<LibraryType, ValueType>(this->getDdManager(), internalAdd.swapVariables(fromBdds, toBdds), newContainedMetaVariables);
228}
230template<DdType LibraryType, typename ValueType>
232 std::set<storm::expressions::Variable> const& to) const {
233 std::vector<InternalBdd<LibraryType>> fromBdds;
234 std::vector<InternalBdd<LibraryType>> toBdds;
235
236 for (auto const& metaVariable : from) {
237 STORM_LOG_THROW(this->containsMetaVariable(metaVariable), storm::exceptions::InvalidOperationException,
238 "Cannot rename variable '" << metaVariable.getName() << "' that is not present.");
239 DdMetaVariable<LibraryType> const& ddMetaVariable = this->getDdManager().getMetaVariable(metaVariable);
240 for (auto const& ddVariable : ddMetaVariable.getDdVariables()) {
241 fromBdds.push_back(ddVariable.getInternalBdd());
242 }
244 std::sort(fromBdds.begin(), fromBdds.end(),
245 [](InternalBdd<LibraryType> const& a, InternalBdd<LibraryType> const& b) { return a.getLevel() < b.getLevel(); });
246 for (auto const& metaVariable : to) {
247 STORM_LOG_THROW(!this->containsMetaVariable(metaVariable), storm::exceptions::InvalidOperationException,
248 "Cannot rename to variable '" << metaVariable.getName() << "' that is already present.");
249 DdMetaVariable<LibraryType> const& ddMetaVariable = this->getDdManager().getMetaVariable(metaVariable);
250 for (auto const& ddVariable : ddMetaVariable.getDdVariables()) {
251 toBdds.push_back(ddVariable.getInternalBdd());
252 }
253 }
254 std::sort(toBdds.begin(), toBdds.end(), [](InternalBdd<LibraryType> const& a, InternalBdd<LibraryType> const& b) { return a.getLevel() < b.getLevel(); });
255
256 std::set<storm::expressions::Variable> newContainedMetaVariables = to;
257 std::set_difference(this->getContainedMetaVariables().begin(), this->getContainedMetaVariables().end(), from.begin(), from.end(),
258 std::inserter(newContainedMetaVariables, newContainedMetaVariables.begin()));
259
260 STORM_LOG_ASSERT(fromBdds.size() >= toBdds.size(), "Unable to perform rename-abstract with mismatching sizes.");
261
262 if (fromBdds.size() == toBdds.size()) {
263 return Add<LibraryType, ValueType>(this->getDdManager(), internalAdd.permuteVariables(fromBdds, toBdds), newContainedMetaVariables);
264 } else {
265 InternalBdd<LibraryType> cube = this->getDdManager().getBddOne().getInternalBdd();
266 for (uint64_t index = toBdds.size(); index < fromBdds.size(); ++index) {
267 cube &= fromBdds[index];
269 fromBdds.resize(toBdds.size());
270
271 return Add<LibraryType, ValueType>(this->getDdManager(), internalAdd.sumAbstract(cube).permuteVariables(fromBdds, toBdds), newContainedMetaVariables);
272 }
273}
274
275template<DdType LibraryType, typename ValueType>
277 std::vector<std::pair<storm::expressions::Variable, storm::expressions::Variable>> const& metaVariablePairs) const {
278 std::set<storm::expressions::Variable> newContainedMetaVariables;
279 std::set<storm::expressions::Variable> deletedMetaVariables;
280 std::vector<InternalBdd<LibraryType>> from;
281 std::vector<InternalBdd<LibraryType>> to;
282 for (auto const& metaVariablePair : metaVariablePairs) {
283 DdMetaVariable<LibraryType> const& variable1 = this->getDdManager().getMetaVariable(metaVariablePair.first);
284 DdMetaVariable<LibraryType> const& variable2 = this->getDdManager().getMetaVariable(metaVariablePair.second);
286 // Keep track of the contained meta variables in the DD.
287 if (this->containsMetaVariable(metaVariablePair.first)) {
288 if (this->containsMetaVariable(metaVariablePair.second)) {
289 // Nothing to do here.
290 } else {
291 newContainedMetaVariables.insert(metaVariablePair.second);
292 deletedMetaVariables.insert(metaVariablePair.first);
293 }
294 } else {
295 if (!this->containsMetaVariable(metaVariablePair.second)) {
296 // Nothing to do here.
297 } else {
298 newContainedMetaVariables.insert(metaVariablePair.first);
299 deletedMetaVariables.insert(metaVariablePair.second);
300 }
302 for (auto const& ddVariable : variable1.getDdVariables()) {
303 from.push_back(ddVariable.getInternalBdd());
304 }
305 for (auto const& ddVariable : variable2.getDdVariables()) {
306 to.push_back(ddVariable.getInternalBdd());
307 }
309
310 std::set<storm::expressions::Variable> tmp;
311 std::set_difference(this->getContainedMetaVariables().begin(), this->getContainedMetaVariables().end(), deletedMetaVariables.begin(),
312 deletedMetaVariables.end(), std::inserter(tmp, tmp.begin()));
313 std::set<storm::expressions::Variable> containedMetaVariables;
314 std::set_union(tmp.begin(), tmp.end(), newContainedMetaVariables.begin(), newContainedMetaVariables.end(),
315 std::inserter(containedMetaVariables, containedMetaVariables.begin()));
316 STORM_LOG_THROW(from.size() == to.size(), storm::exceptions::InvalidArgumentException, "Unable to swap mismatching meta variables.");
317 return Add<LibraryType, ValueType>(this->getDdManager(), internalAdd.swapVariables(from, to), containedMetaVariables);
318}
319
320template<DdType LibraryType, typename ValueType>
322 std::vector<std::pair<storm::expressions::Variable, storm::expressions::Variable>> const& metaVariablePairs) const {
323 std::set<storm::expressions::Variable> newContainedMetaVariables;
324 std::set<storm::expressions::Variable> deletedMetaVariables;
325 std::vector<InternalBdd<LibraryType>> from;
326 std::vector<InternalBdd<LibraryType>> to;
327 for (auto const& metaVariablePair : metaVariablePairs) {
328 DdMetaVariable<LibraryType> const& variable1 = this->getDdManager().getMetaVariable(metaVariablePair.first);
329 DdMetaVariable<LibraryType> const& variable2 = this->getDdManager().getMetaVariable(metaVariablePair.second);
330
331 // Keep track of the contained meta variables in the DD.
332 if (this->containsMetaVariable(metaVariablePair.first)) {
333 deletedMetaVariables.insert(metaVariablePair.first);
334 newContainedMetaVariables.insert(metaVariablePair.second);
335 }
336
337 for (auto const& ddVariable : variable1.getDdVariables()) {
338 from.push_back(ddVariable.getInternalBdd());
340 for (auto const& ddVariable : variable2.getDdVariables()) {
341 to.push_back(ddVariable.getInternalBdd());
342 }
343 }
344
345 std::set<storm::expressions::Variable> tmp;
346 std::set_difference(this->getContainedMetaVariables().begin(), this->getContainedMetaVariables().end(), deletedMetaVariables.begin(),
347 deletedMetaVariables.end(), std::inserter(tmp, tmp.begin()));
348 std::set<storm::expressions::Variable> containedMetaVariables;
349 std::set_union(tmp.begin(), tmp.end(), newContainedMetaVariables.begin(), newContainedMetaVariables.end(),
350 std::inserter(containedMetaVariables, containedMetaVariables.begin()));
351 STORM_LOG_THROW(from.size() == to.size(), storm::exceptions::InvalidArgumentException, "Unable to swap mismatching meta variables.");
352 return Add<LibraryType, ValueType>(this->getDdManager(), internalAdd.permuteVariables(from, to), containedMetaVariables);
353}
354
355template<DdType LibraryType, typename ValueType>
357 std::set<storm::expressions::Variable> const& summationMetaVariables) const {
358 // Create the summation variables.
359 std::vector<InternalBdd<LibraryType>> summationDdVariables;
360 for (auto const& metaVariable : summationMetaVariables) {
361 for (auto const& ddVariable : this->getDdManager().getMetaVariable(metaVariable).getDdVariables()) {
362 summationDdVariables.push_back(ddVariable.getInternalBdd());
363 }
364 }
365
366 std::set<storm::expressions::Variable> unionOfMetaVariables = Dd<LibraryType>::joinMetaVariables(*this, otherMatrix);
367 std::set<storm::expressions::Variable> containedMetaVariables;
368 std::set_difference(unionOfMetaVariables.begin(), unionOfMetaVariables.end(), summationMetaVariables.begin(), summationMetaVariables.end(),
369 std::inserter(containedMetaVariables, containedMetaVariables.begin()));
370
371 return Add<LibraryType, ValueType>(this->getDdManager(), internalAdd.multiplyMatrix(otherMatrix, summationDdVariables), containedMetaVariables);
373
374template<DdType LibraryType, typename ValueType>
376 std::set<storm::expressions::Variable> const& summationMetaVariables) const {
377 // Create the summation variables.
378 std::vector<InternalBdd<LibraryType>> summationDdVariables;
379 for (auto const& metaVariable : summationMetaVariables) {
380 for (auto const& ddVariable : this->getDdManager().getMetaVariable(metaVariable).getDdVariables()) {
381 summationDdVariables.push_back(ddVariable.getInternalBdd());
382 }
384
385 std::set<storm::expressions::Variable> unionOfMetaVariables = Dd<LibraryType>::joinMetaVariables(*this, otherMatrix);
386 std::set<storm::expressions::Variable> containedMetaVariables;
387 std::set_difference(unionOfMetaVariables.begin(), unionOfMetaVariables.end(), summationMetaVariables.begin(), summationMetaVariables.end(),
388 std::inserter(containedMetaVariables, containedMetaVariables.begin()));
389
390 return Add<LibraryType, ValueType>(this->getDdManager(), internalAdd.multiplyMatrix(otherMatrix.getInternalBdd(), summationDdVariables),
391 containedMetaVariables);
392}
393
394template<DdType LibraryType, typename ValueType>
396 return Bdd<LibraryType>(this->getDdManager(), internalAdd.greater(value), this->getContainedMetaVariables());
397}
398
399template<DdType LibraryType, typename ValueType>
401 return Bdd<LibraryType>(this->getDdManager(), internalAdd.greaterOrEqual(value), this->getContainedMetaVariables());
402}
403
404template<DdType LibraryType, typename ValueType>
406 return Bdd<LibraryType>(this->getDdManager(), internalAdd.less(value), this->getContainedMetaVariables());
407}
408
409template<DdType LibraryType, typename ValueType>
411 return Bdd<LibraryType>(this->getDdManager(), internalAdd.lessOrEqual(value), this->getContainedMetaVariables());
412}
413
414template<DdType LibraryType, typename ValueType>
416 return Bdd<LibraryType>(this->getDdManager(), internalAdd.notZero(), this->getContainedMetaVariables());
417}
418
419template<DdType LibraryType, typename ValueType>
421 return Add<LibraryType, ValueType>(this->getDdManager(), internalAdd.constrain(constraint), Dd<LibraryType>::joinMetaVariables(*this, constraint));
422}
423
424template<DdType LibraryType, typename ValueType>
426 return Add<LibraryType, ValueType>(this->getDdManager(), internalAdd.restrict(constraint), Dd<LibraryType>::joinMetaVariables(*this, constraint));
427}
428
429template<DdType LibraryType, typename ValueType>
431 return Bdd<LibraryType>(this->getDdManager(), internalAdd.getSupport(), this->getContainedMetaVariables());
432}
433
434template<DdType LibraryType, typename ValueType>
436 std::size_t numberOfDdVariables = 0;
437 for (auto const& metaVariable : this->getContainedMetaVariables()) {
438 numberOfDdVariables += this->getDdManager().getMetaVariable(metaVariable).getNumberOfDdVariables();
439 }
440 return internalAdd.getNonZeroCount(numberOfDdVariables);
441}
442
443template<DdType LibraryType, typename ValueType>
445 return internalAdd.getLeafCount();
446}
447
448template<DdType LibraryType, typename ValueType>
450 return internalAdd.getNodeCount();
451}
452
453template<DdType LibraryType, typename ValueType>
455 return internalAdd.getMin();
456}
457
458template<DdType LibraryType, typename ValueType>
460 return internalAdd.getMax();
461}
462
463template<DdType LibraryType, typename ValueType>
464void Add<LibraryType, ValueType>::setValue(storm::expressions::Variable const& metaVariable, int_fast64_t variableValue, ValueType const& targetValue) {
465 std::map<storm::expressions::Variable, int_fast64_t> metaVariableToValueMap;
466 metaVariableToValueMap.emplace(metaVariable, variableValue);
467 this->setValue(metaVariableToValueMap, targetValue);
468}
469
470template<DdType LibraryType, typename ValueType>
471void Add<LibraryType, ValueType>::setValue(storm::expressions::Variable const& metaVariable1, int_fast64_t variableValue1,
472 storm::expressions::Variable const& metaVariable2, int_fast64_t variableValue2, ValueType const& targetValue) {
473 std::map<storm::expressions::Variable, int_fast64_t> metaVariableToValueMap;
474 metaVariableToValueMap.emplace(metaVariable1, variableValue1);
475 metaVariableToValueMap.emplace(metaVariable2, variableValue2);
476 this->setValue(metaVariableToValueMap, targetValue);
477}
478
479template<DdType LibraryType, typename ValueType>
480void Add<LibraryType, ValueType>::setValue(std::map<storm::expressions::Variable, int_fast64_t> const& metaVariableToValueMap, ValueType const& targetValue) {
481 Bdd<LibraryType> valueEncoding = this->getDdManager().getBddOne();
482 for (auto const& nameValuePair : metaVariableToValueMap) {
483 valueEncoding &= this->getDdManager().getEncoding(nameValuePair.first, nameValuePair.second);
484 // Also record that the DD now contains the meta variable.
485 this->addMetaVariable(nameValuePair.first);
487
488 internalAdd = valueEncoding.ite(this->getDdManager().getConstant(targetValue), *this);
489}
490
491template<DdType LibraryType, typename ValueType>
492ValueType Add<LibraryType, ValueType>::getValue(std::map<storm::expressions::Variable, int_fast64_t> const& metaVariableToValueMap) const {
493 std::set<storm::expressions::Variable> remainingMetaVariables(this->getContainedMetaVariables());
494 Bdd<LibraryType> valueEncoding = this->getDdManager().getBddOne();
495 for (auto const& nameValuePair : metaVariableToValueMap) {
496 valueEncoding &= this->getDdManager().getEncoding(nameValuePair.first, nameValuePair.second);
497 if (this->containsMetaVariable(nameValuePair.first)) {
498 remainingMetaVariables.erase(nameValuePair.first);
499 }
501
502 STORM_LOG_THROW(remainingMetaVariables.empty(), storm::exceptions::InvalidArgumentException,
503 "Cannot evaluate function for which not all inputs were given.");
504
505 Add<LibraryType, ValueType> value = *this * valueEncoding.template toAdd<ValueType>();
506 value = value.sumAbstract(this->getContainedMetaVariables());
507 return value.internalAdd.getValue();
508}
509
510template<DdType LibraryType, typename ValueType>
512 return internalAdd.isOne();
513}
514
515template<DdType LibraryType, typename ValueType>
517 return internalAdd.isZero();
518}
519
520template<DdType LibraryType, typename ValueType>
522 return internalAdd.isConstant();
523}
524
525template<DdType LibraryType, typename ValueType>
527 return internalAdd.getIndex();
528}
529
530template<DdType LibraryType, typename ValueType>
532 return internalAdd.getLevel();
533}
534
535template<DdType LibraryType, typename ValueType>
536std::vector<ValueType> Add<LibraryType, ValueType>::toVector() const {
537 return this->toVector(this->createOdd());
538}
539
540template<DdType LibraryType, typename ValueType>
541std::vector<ValueType> Add<LibraryType, ValueType>::toVector(Odd const& rowOdd) const {
542 std::vector<ValueType> result(rowOdd.getTotalOffset());
543 std::vector<uint_fast64_t> ddVariableIndices = this->getSortedVariableIndices();
544 internalAdd.composeWithExplicitVector(rowOdd, ddVariableIndices, result, std::plus<ValueType>());
545 return result;
546}
547
548template<DdType LibraryType, typename ValueType>
550 std::vector<uint_fast64_t> const& rowGroupIndices,
551 std::set<storm::expressions::Variable> const& rowMetaVariables,
552 std::set<storm::expressions::Variable> const& columnMetaVariables,
553 std::set<storm::expressions::Variable> const& groupMetaVariables,
554 storm::dd::Odd const& rowOdd) const {
555 std::vector<uint_fast64_t> ddRowVariableIndices;
556 std::vector<uint_fast64_t> ddColumnVariableIndices;
557 std::vector<uint_fast64_t> ddGroupVariableIndices;
558 std::set<storm::expressions::Variable> rowAndColumnMetaVariables;
559
560 for (auto const& variable : rowMetaVariables) {
561 DdMetaVariable<LibraryType> const& metaVariable = this->getDdManager().getMetaVariable(variable);
562 for (auto const& ddVariable : metaVariable.getDdVariables()) {
563 ddRowVariableIndices.push_back(ddVariable.getIndex());
564 }
565 rowAndColumnMetaVariables.insert(variable);
566 }
567 std::sort(ddRowVariableIndices.begin(), ddRowVariableIndices.end());
568 for (auto const& variable : columnMetaVariables) {
569 DdMetaVariable<LibraryType> const& metaVariable = this->getDdManager().getMetaVariable(variable);
570 for (auto const& ddVariable : metaVariable.getDdVariables()) {
571 ddColumnVariableIndices.push_back(ddVariable.getIndex());
573 rowAndColumnMetaVariables.insert(variable);
575 std::sort(ddColumnVariableIndices.begin(), ddColumnVariableIndices.end());
576 for (auto const& variable : groupMetaVariables) {
577 DdMetaVariable<LibraryType> const& metaVariable = this->getDdManager().getMetaVariable(variable);
578 for (auto const& ddVariable : metaVariable.getDdVariables()) {
579 ddGroupVariableIndices.push_back(ddVariable.getIndex());
580 }
582 std::sort(ddGroupVariableIndices.begin(), ddGroupVariableIndices.end());
583
584 Bdd<LibraryType> columnVariableCube = Bdd<LibraryType>::getCube(this->getDdManager(), columnMetaVariables);
585
586 // Copy the row group indices so we can modify them.
587 std::vector<uint_fast64_t> mutableRowGroupIndices = rowGroupIndices;
588
589 // Create the explicit vector we need to fill later.
590 std::vector<ValueType> explicitVector(mutableRowGroupIndices.back());
591
592 // Next, we split the matrix into one for each group. Note that this only works if the group variables are at the very top.
593 std::vector<std::pair<InternalAdd<LibraryType, ValueType>, InternalAdd<LibraryType, ValueType>>> internalAddGroups =
594 matrix.internalAdd.splitIntoGroups(*this, ddGroupVariableIndices);
595 std::vector<std::pair<Add<LibraryType, ValueType>, Add<LibraryType, ValueType>>> groups;
596 for (auto const& internalAdd : internalAddGroups) {
597 groups.push_back(std::make_pair(Add<LibraryType, ValueType>(this->getDdManager(), internalAdd.first, rowAndColumnMetaVariables),
598 Add<LibraryType, ValueType>(this->getDdManager(), internalAdd.second, rowMetaVariables)));
599 }
600
601 std::vector<InternalAdd<LibraryType, uint_fast64_t>> statesWithGroupEnabled(groups.size());
602 for (uint_fast64_t i = 0; i < groups.size(); ++i) {
603 std::pair<Add<LibraryType, ValueType>, Add<LibraryType, ValueType>> const& ddPair = groups[i];
604 Bdd<LibraryType> matrixDdNotZero = ddPair.first.notZero();
605 Bdd<LibraryType> vectorDdNotZero = ddPair.second.notZero();
606
607 ddPair.second.internalAdd.composeWithExplicitVector(rowOdd, ddRowVariableIndices, mutableRowGroupIndices, explicitVector, std::plus<ValueType>());
608
609 InternalAdd<LibraryType, uint_fast64_t> statesWithGroupEnabled =
610 (matrixDdNotZero.existsAbstract(columnMetaVariables) || vectorDdNotZero).template toAdd<uint_fast64_t>();
611 statesWithGroupEnabled.composeWithExplicitVector(rowOdd, ddRowVariableIndices, mutableRowGroupIndices, std::plus<uint_fast64_t>());
612 }
613
614 return explicitVector;
615}
616
617template<DdType LibraryType, typename ValueType>
619 std::set<storm::expressions::Variable> rowVariables;
620 std::set<storm::expressions::Variable> columnVariables;
622 for (auto const& variable : this->getContainedMetaVariables()) {
623 if (variable.getName().size() > 0 && variable.getName().back() == '\'') {
624 columnVariables.insert(variable);
625 } else {
626 rowVariables.insert(variable);
627 }
628 }
629
630 return toMatrix(rowVariables, columnVariables, this->sumAbstract(rowVariables).createOdd(), this->sumAbstract(columnVariables).createOdd());
631}
632
633template<DdType LibraryType, typename ValueType>
635 std::set<storm::expressions::Variable> rowMetaVariables;
636 std::set<storm::expressions::Variable> columnMetaVariables;
637
638 for (auto const& variable : this->getContainedMetaVariables()) {
639 if (variable.getName().size() > 0 && variable.getName().back() == '\'') {
640 columnMetaVariables.insert(variable);
641 } else {
642 rowMetaVariables.insert(variable);
643 }
644 }
645
646 return toMatrix(rowMetaVariables, columnMetaVariables, rowOdd, columnOdd);
647}
648
649template<DdType LibraryType, typename ValueType>
650storm::storage::SparseMatrix<ValueType> Add<LibraryType, ValueType>::toMatrix(std::set<storm::expressions::Variable> const& rowMetaVariables,
651 std::set<storm::expressions::Variable> const& columnMetaVariables,
652 storm::dd::Odd const& rowOdd, storm::dd::Odd const& columnOdd) const {
653 std::vector<uint_fast64_t> ddRowVariableIndices;
654 std::vector<uint_fast64_t> ddColumnVariableIndices;
655
656 for (auto const& variable : rowMetaVariables) {
657 DdMetaVariable<LibraryType> const& metaVariable = this->getDdManager().getMetaVariable(variable);
658 for (auto const& ddVariable : metaVariable.getDdVariables()) {
659 ddRowVariableIndices.push_back(ddVariable.getIndex());
660 }
661 }
662 std::sort(ddRowVariableIndices.begin(), ddRowVariableIndices.end());
663
664 for (auto const& variable : columnMetaVariables) {
665 DdMetaVariable<LibraryType> const& metaVariable = this->getDdManager().getMetaVariable(variable);
666 for (auto const& ddVariable : metaVariable.getDdVariables()) {
667 ddColumnVariableIndices.push_back(ddVariable.getIndex());
668 }
669 }
670 std::sort(ddColumnVariableIndices.begin(), ddColumnVariableIndices.end());
671
672 // Prepare the vectors that represent the matrix.
673 std::vector<uint_fast64_t> rowIndications(rowOdd.getTotalOffset() + 1);
674 std::vector<storm::storage::MatrixEntry<uint_fast64_t, ValueType>> columnsAndValues(this->getNonZeroCount());
675
676 // Create a trivial row grouping.
677 std::vector<uint_fast64_t> trivialRowGroupIndices(rowIndications.size());
678 uint_fast64_t i = 0;
679 for (auto& entry : trivialRowGroupIndices) {
680 entry = i;
681 ++i;
682 }
683
684 // Count the number of elements in the rows.
685 rowIndications = this->notZero().template toAdd<uint_fast64_t>().sumAbstract(columnMetaVariables).toVector(rowOdd);
686 rowIndications.emplace_back();
687
688 // Now that we computed the number of entries in each row, compute the corresponding offsets in the entry vector.
689 uint_fast64_t tmp = 0;
690 uint_fast64_t tmp2 = 0;
691 for (uint_fast64_t i = 1; i < rowIndications.size(); ++i) {
692 tmp2 = rowIndications[i];
693 rowIndications[i] = rowIndications[i - 1] + tmp;
694 std::swap(tmp, tmp2);
695 }
696 rowIndications[0] = 0;
697
698 // Now actually fill the entry vector.
699 internalAdd.toMatrixComponents(trivialRowGroupIndices, rowIndications, columnsAndValues, rowOdd, columnOdd, ddRowVariableIndices, ddColumnVariableIndices,
700 true);
701
702 // Since the last call to toMatrixRec modified the rowIndications, we need to restore the correct values.
703 for (uint_fast64_t i = rowIndications.size() - 1; i > 0; --i) {
704 rowIndications[i] = rowIndications[i - 1];
705 }
706 rowIndications[0] = 0;
707
708 // Construct matrix and return result.
709 return storm::storage::SparseMatrix<ValueType>(columnOdd.getTotalOffset(), std::move(rowIndications), std::move(columnsAndValues), boost::none);
710}
712template<DdType LibraryType, typename ValueType>
713storm::storage::SparseMatrix<ValueType> Add<LibraryType, ValueType>::toMatrix(std::set<storm::expressions::Variable> const& groupMetaVariables,
714 storm::dd::Odd const& rowOdd, storm::dd::Odd const& columnOdd) const {
715 std::set<storm::expressions::Variable> rowMetaVariables;
716 std::set<storm::expressions::Variable> columnMetaVariables;
717
718 for (auto const& variable : this->getContainedMetaVariables()) {
719 // If the meta variable is a group meta variable, we do not insert it into the set of row/column meta variables.
720 if (groupMetaVariables.contains(variable)) {
721 continue;
722 }
723
724 if (variable.getName().size() > 0 && variable.getName().back() == '\'') {
725 columnMetaVariables.insert(variable);
726 } else {
727 rowMetaVariables.insert(variable);
728 }
729 }
730
731 // Create the canonical row group sizes and build the matrix.
732 return toLabeledMatrix(rowMetaVariables, columnMetaVariables, groupMetaVariables, rowOdd, columnOdd).matrix;
734
735template<DdType LibraryType, typename ValueType>
737 std::set<storm::expressions::Variable> const& rowMetaVariables, std::set<storm::expressions::Variable> const& columnMetaVariables,
738 std::set<storm::expressions::Variable> const& groupMetaVariables, storm::dd::Odd const& rowOdd, storm::dd::Odd const& columnOdd,
739 std::vector<std::set<storm::expressions::Variable>> const& labelMetaVariables) const {
740 std::vector<uint_fast64_t> ddRowVariableIndices;
741 std::vector<uint_fast64_t> ddColumnVariableIndices;
742 std::vector<uint_fast64_t> ddGroupVariableIndices;
743 std::vector<storm::storage::BitVector> ddLabelVariableIndicesVector;
744 std::set<storm::expressions::Variable> rowAndColumnMetaVariables;
745 bool buildLabeling = !labelMetaVariables.empty();
746 MatrixAndLabeling result;
747
748 for (auto const& variable : rowMetaVariables) {
749 DdMetaVariable<LibraryType> const& metaVariable = this->getDdManager().getMetaVariable(variable);
750 for (auto const& ddVariable : metaVariable.getDdVariables()) {
751 ddRowVariableIndices.push_back(ddVariable.getIndex());
752 }
753 rowAndColumnMetaVariables.insert(variable);
754 }
755 std::sort(ddRowVariableIndices.begin(), ddRowVariableIndices.end());
756 for (auto const& variable : columnMetaVariables) {
757 DdMetaVariable<LibraryType> const& metaVariable = this->getDdManager().getMetaVariable(variable);
758 for (auto const& ddVariable : metaVariable.getDdVariables()) {
759 ddColumnVariableIndices.push_back(ddVariable.getIndex());
760 }
761 rowAndColumnMetaVariables.insert(variable);
762 }
763 std::sort(ddColumnVariableIndices.begin(), ddColumnVariableIndices.end());
764 for (auto const& variable : groupMetaVariables) {
765 DdMetaVariable<LibraryType> const& metaVariable = this->getDdManager().getMetaVariable(variable);
766 for (auto const& ddVariable : metaVariable.getDdVariables()) {
767 ddGroupVariableIndices.push_back(ddVariable.getIndex());
768 }
769 }
770 std::sort(ddGroupVariableIndices.begin(), ddGroupVariableIndices.end());
771 if (buildLabeling) {
772 for (auto const& labelMetaVariableSet : labelMetaVariables) {
773 std::set<uint64_t> ddLabelVariableIndicesSet;
774 for (auto const& variable : labelMetaVariableSet) {
775 DdMetaVariable<LibraryType> const& metaVariable = this->getDdManager().getMetaVariable(variable);
776 for (auto const& ddVariable : metaVariable.getDdVariables()) {
777 ddLabelVariableIndicesSet.insert(ddVariable.getIndex());
778 }
779 }
780
781 ddLabelVariableIndicesVector.emplace_back(ddGroupVariableIndices.size());
782 uint64_t position = 0;
783 for (auto const& index : ddGroupVariableIndices) {
784 if (ddLabelVariableIndicesSet.contains(index)) {
785 ddLabelVariableIndicesVector.back().set(position);
786 }
787 ++position;
788 }
789 }
790 }
791
792 Bdd<LibraryType> columnVariableCube = Bdd<LibraryType>::getCube(this->getDdManager(), columnMetaVariables);
793
794 // Start by computing the offsets (in terms of rows) for each row group.
795 Add<LibraryType, uint_fast64_t> stateToNumberOfChoices =
796 this->notZero().existsAbstract(columnMetaVariables).template toAdd<uint_fast64_t>().sumAbstract(groupMetaVariables);
797 std::vector<uint_fast64_t> rowGroupIndices = stateToNumberOfChoices.toVector(rowOdd);
798 rowGroupIndices.resize(rowGroupIndices.size() + 1);
799 uint_fast64_t tmp = 0;
800 uint_fast64_t tmp2 = 0;
801 for (uint_fast64_t i = 1; i < rowGroupIndices.size(); ++i) {
802 tmp2 = rowGroupIndices[i];
803 rowGroupIndices[i] = rowGroupIndices[i - 1] + tmp;
804 std::swap(tmp, tmp2);
805 }
806 rowGroupIndices[0] = 0;
807
808 // Next, we split the matrix into one for each group. Note that this only works if the group variables are
809 // at the very top.
810 std::vector<InternalAdd<LibraryType, ValueType>> internalAddGroups = internalAdd.splitIntoGroups(ddGroupVariableIndices);
811 std::vector<Add<LibraryType, ValueType>> groups;
812 for (auto const& internalAdd : internalAddGroups) {
813 groups.push_back(Add<LibraryType, ValueType>(this->getDdManager(), internalAdd, rowAndColumnMetaVariables));
814 }
815
816 // Create the group labelings if requested.
817 std::vector<std::vector<uint64_t>> groupLabelings;
818 if (buildLabeling) {
819 for (auto const& ddLabelVariableIndices : ddLabelVariableIndicesVector) {
820 groupLabelings.emplace_back(internalAdd.decodeGroupLabels(ddGroupVariableIndices, ddLabelVariableIndices));
821 STORM_LOG_ASSERT(groupLabelings.back().size() == groups.size(), "Mismatching label sizes.");
822 }
823 }
824
825 // Create the actual storage for the non-zero entries.
826 std::vector<storm::storage::MatrixEntry<uint_fast64_t, ValueType>> columnsAndValues(this->getNonZeroCount());
827
828 // Now compute the indices at which the individual rows start.
829 std::vector<uint_fast64_t> rowIndications(rowGroupIndices.back() + 1);
830
831 if (buildLabeling) {
832 for (uint64_t i = 0; i < labelMetaVariables.size(); ++i) {
833 result.labelings.emplace_back(rowGroupIndices.back());
834 }
835 }
836
837 std::vector<InternalAdd<LibraryType, uint_fast64_t>> statesWithGroupEnabled(groups.size());
838 InternalAdd<LibraryType, uint_fast64_t> stateToRowGroupCount = this->getDdManager().template getAddZero<uint_fast64_t>();
839 for (uint_fast64_t i = 0; i < groups.size(); ++i) {
840 auto const& group = groups[i];
841 auto groupNotZero = group.notZero();
842
843 std::vector<uint64_t> tmpRowIndications = groupNotZero.template toAdd<uint_fast64_t>().sumAbstract(columnMetaVariables).toVector(rowOdd);
844 for (uint64_t offset = 0; offset < tmpRowIndications.size(); ++offset) {
845 rowIndications[rowGroupIndices[offset]] += tmpRowIndications[offset];
846 }
847
848 statesWithGroupEnabled[i] = groupNotZero.existsAbstract(columnMetaVariables).template toAdd<uint_fast64_t>();
849 if (buildLabeling) {
850 for (uint64_t j = 0; j < labelMetaVariables.size(); ++j) {
851 uint64_t currentLabel = groupLabelings[j][i];
852 statesWithGroupEnabled[i].forEach(rowOdd, ddRowVariableIndices,
853 [currentLabel, &rowGroupIndices, &result, j](uint64_t const& offset, uint_fast64_t const& value) {
854 result.labelings[j][rowGroupIndices[offset]] = currentLabel;
855 });
856 }
857 }
858 statesWithGroupEnabled[i].composeWithExplicitVector(rowOdd, ddRowVariableIndices, rowGroupIndices, std::plus<uint_fast64_t>());
859 }
860
861 // Since we modified the rowGroupIndices, we need to restore the correct values.
862 stateToNumberOfChoices.internalAdd.composeWithExplicitVector(rowOdd, ddRowVariableIndices, rowGroupIndices, std::minus<uint_fast64_t>());
863
864 // Now that we computed the number of entries in each row, compute the corresponding offsets in the entry vector.
865 tmp = 0;
866 tmp2 = 0;
867 for (uint_fast64_t i = 1; i < rowIndications.size(); ++i) {
868 tmp2 = rowIndications[i];
869 rowIndications[i] = rowIndications[i - 1] + tmp;
870 std::swap(tmp, tmp2);
871 }
872 rowIndications[0] = 0;
873
874 // Now actually fill the entry vector.
875 for (uint_fast64_t i = 0; i < groups.size(); ++i) {
876 auto const& group = groups[i];
877
878 group.internalAdd.toMatrixComponents(rowGroupIndices, rowIndications, columnsAndValues, rowOdd, columnOdd, ddRowVariableIndices,
879 ddColumnVariableIndices, true);
880
881 statesWithGroupEnabled[i].composeWithExplicitVector(rowOdd, ddRowVariableIndices, rowGroupIndices, std::plus<uint_fast64_t>());
882 }
883
884 // Since we modified the rowGroupIndices, we need to restore the correct values.
885 stateToNumberOfChoices.internalAdd.composeWithExplicitVector(rowOdd, ddRowVariableIndices, rowGroupIndices, std::minus<uint_fast64_t>());
886
887 // Since the last call to toMatrixRec modified the rowIndications, we need to restore the correct values.
888 for (uint_fast64_t i = rowIndications.size() - 1; i > 0; --i) {
889 rowIndications[i] = rowIndications[i - 1];
890 }
891 rowIndications[0] = 0;
892
893 // Move-construct matrix and return.
894 result.matrix =
895 storm::storage::SparseMatrix<ValueType>(columnOdd.getTotalOffset(), std::move(rowIndications), std::move(columnsAndValues), std::move(rowGroupIndices));
896 return result;
897}
898
899template<DdType LibraryType, typename ValueType>
900std::pair<storm::storage::SparseMatrix<ValueType>, std::vector<ValueType>> Add<LibraryType, ValueType>::toMatrixVector(
901 storm::dd::Add<LibraryType, ValueType> const& vector, std::set<storm::expressions::Variable> const& groupMetaVariables, storm::dd::Odd const& rowOdd,
902 storm::dd::Odd const& columnOdd) const {
903 std::set<storm::expressions::Variable> rowMetaVariables;
904 std::set<storm::expressions::Variable> columnMetaVariables;
905
906 for (auto const& variable : this->getContainedMetaVariables()) {
907 // If the meta variable is a group meta variable, we do not insert it into the set of row/column meta variables.
908 if (groupMetaVariables.contains(variable)) {
909 continue;
910 }
911
912 if (variable.getName().size() > 0 && variable.getName().back() == '\'') {
913 columnMetaVariables.insert(variable);
914 } else {
915 rowMetaVariables.insert(variable);
916 }
917 }
918
919 // Create the canonical row group sizes and build the matrix.
920 return toMatrixVector(vector, rowMetaVariables, columnMetaVariables, groupMetaVariables, rowOdd, columnOdd);
921}
922
923template<DdType LibraryType, typename ValueType>
924std::pair<storm::storage::SparseMatrix<ValueType>, std::vector<ValueType>> Add<LibraryType, ValueType>::toMatrixVector(
925 storm::dd::Add<LibraryType, ValueType> const& vector, std::set<storm::expressions::Variable> const& rowMetaVariables,
926 std::set<storm::expressions::Variable> const& columnMetaVariables, std::set<storm::expressions::Variable> const& groupMetaVariables,
927 storm::dd::Odd const& rowOdd, storm::dd::Odd const& columnOdd) const {
928 // Count how many choices each row group has.
929 std::vector<uint_fast64_t> rowGroupIndices = (this->notZero().existsAbstract(columnMetaVariables) || vector.notZero())
930 .template toAdd<uint_fast64_t>()
931 .sumAbstract(groupMetaVariables)
932 .toVector(rowOdd);
933 return toMatrixVector(std::move(rowGroupIndices), vector, rowMetaVariables, columnMetaVariables, groupMetaVariables, rowOdd, columnOdd);
934}
935
936template<DdType LibraryType, typename ValueType>
937std::pair<storm::storage::SparseMatrix<ValueType>, std::vector<ValueType>> Add<LibraryType, ValueType>::toMatrixVector(
938 std::vector<uint_fast64_t>&& rowGroupIndices, storm::dd::Add<LibraryType, ValueType> const& vector,
939 std::set<storm::expressions::Variable> const& rowMetaVariables, std::set<storm::expressions::Variable> const& columnMetaVariables,
940 std::set<storm::expressions::Variable> const& groupMetaVariables, storm::dd::Odd const& rowOdd, storm::dd::Odd const& columnOdd) const {
941 auto resultAsVector = toMatrixVectors(std::move(rowGroupIndices), {vector}, rowMetaVariables, columnMetaVariables, groupMetaVariables, rowOdd, columnOdd);
942 return std::make_pair(resultAsVector.first, resultAsVector.second.front());
943}
944
945template<DdType LibraryType, typename ValueType>
946std::pair<storm::storage::SparseMatrix<ValueType>, std::vector<std::vector<ValueType>>> Add<LibraryType, ValueType>::toMatrixVectors(
947 std::vector<storm::dd::Add<LibraryType, ValueType>> const& vectors, std::set<storm::expressions::Variable> const& groupMetaVariables,
948 storm::dd::Odd const& rowOdd, storm::dd::Odd const& columnOdd) const {
949 std::set<storm::expressions::Variable> rowMetaVariables;
950 std::set<storm::expressions::Variable> columnMetaVariables;
951
952 for (auto const& variable : this->getContainedMetaVariables()) {
953 // If the meta variable is a group meta variable, we do not insert it into the set of row/column meta variables.
954 if (groupMetaVariables.contains(variable)) {
955 continue;
956 }
957
958 if (variable.getName().size() > 0 && variable.getName().back() == '\'') {
959 columnMetaVariables.insert(variable);
960 } else {
961 rowMetaVariables.insert(variable);
962 }
963 }
964 // Count how many choices each row group has.
965 Bdd<LibraryType> vectorsNotZero = this->getDdManager().getBddZero();
966 for (auto const& v : vectors) {
967 vectorsNotZero |= v.notZero();
968 }
969 std::vector<uint_fast64_t> rowGroupIndices = (this->notZero().existsAbstract(columnMetaVariables) || vectorsNotZero)
970 .template toAdd<uint_fast64_t>()
971 .sumAbstract(groupMetaVariables)
972 .toVector(rowOdd);
973 return toMatrixVectors(std::move(rowGroupIndices), vectors, rowMetaVariables, columnMetaVariables, groupMetaVariables, rowOdd, columnOdd);
974}
975
976template<DdType LibraryType, typename ValueType>
977std::pair<storm::storage::SparseMatrix<ValueType>, std::vector<std::vector<ValueType>>> Add<LibraryType, ValueType>::toMatrixVectors(
978 std::vector<uint_fast64_t>&& rowGroupIndices, std::vector<storm::dd::Add<LibraryType, ValueType>> const& vectors,
979 std::set<storm::expressions::Variable> const& rowMetaVariables, std::set<storm::expressions::Variable> const& columnMetaVariables,
980 std::set<storm::expressions::Variable> const& groupMetaVariables, storm::dd::Odd const& rowOdd, storm::dd::Odd const& columnOdd) const {
981 std::vector<uint_fast64_t> ddRowVariableIndices;
982 std::vector<uint_fast64_t> ddColumnVariableIndices;
983 std::vector<uint_fast64_t> ddGroupVariableIndices;
984 std::set<storm::expressions::Variable> rowAndColumnMetaVariables;
985
986 for (auto const& variable : rowMetaVariables) {
987 DdMetaVariable<LibraryType> const& metaVariable = this->getDdManager().getMetaVariable(variable);
988 for (auto const& ddVariable : metaVariable.getDdVariables()) {
989 ddRowVariableIndices.push_back(ddVariable.getIndex());
990 }
991 rowAndColumnMetaVariables.insert(variable);
992 }
993 std::sort(ddRowVariableIndices.begin(), ddRowVariableIndices.end());
994 for (auto const& variable : columnMetaVariables) {
995 DdMetaVariable<LibraryType> const& metaVariable = this->getDdManager().getMetaVariable(variable);
996 for (auto const& ddVariable : metaVariable.getDdVariables()) {
997 ddColumnVariableIndices.push_back(ddVariable.getIndex());
998 }
999 rowAndColumnMetaVariables.insert(variable);
1000 }
1001 std::sort(ddColumnVariableIndices.begin(), ddColumnVariableIndices.end());
1002 for (auto const& variable : groupMetaVariables) {
1003 DdMetaVariable<LibraryType> const& metaVariable = this->getDdManager().getMetaVariable(variable);
1004 for (auto const& ddVariable : metaVariable.getDdVariables()) {
1005 ddGroupVariableIndices.push_back(ddVariable.getIndex());
1006 }
1007 }
1008 std::sort(ddGroupVariableIndices.begin(), ddGroupVariableIndices.end());
1009
1010 Bdd<LibraryType> columnVariableCube = Bdd<LibraryType>::getCube(this->getDdManager(), columnMetaVariables);
1011
1012 // Transform the row group sizes to the actual row group indices.
1013 rowGroupIndices.resize(rowGroupIndices.size() + 1);
1014 uint_fast64_t tmp = 0;
1015 uint_fast64_t tmp2 = 0;
1016 for (uint_fast64_t i = 1; i < rowGroupIndices.size(); ++i) {
1017 tmp2 = rowGroupIndices[i];
1018 rowGroupIndices[i] = rowGroupIndices[i - 1] + tmp;
1019 std::swap(tmp, tmp2);
1020 }
1021 rowGroupIndices[0] = 0;
1022
1023 // Create the explicit vectors we need to fill later.
1024 std::vector<std::vector<ValueType>> explicitVectors(vectors.size());
1025 for (auto& v : explicitVectors) {
1026 v.resize(rowGroupIndices.back());
1027 }
1028
1029 // Next, we split the matrix into one for each group. Note that this only works if the group variables are at the very top.
1030 std::vector<std::vector<Add<LibraryType, ValueType>>> groups;
1031 if (vectors.size() == 1) {
1032 // This version potentially has slightly reduced overhead
1033 std::vector<std::pair<InternalAdd<LibraryType, ValueType>, InternalAdd<LibraryType, ValueType>>> internalAddGroups =
1034 internalAdd.splitIntoGroups(vectors.front(), ddGroupVariableIndices);
1035 for (auto const& internalAdd : internalAddGroups) {
1036 groups.push_back({Add<LibraryType, ValueType>(this->getDdManager(), internalAdd.second, rowMetaVariables),
1037 Add<LibraryType, ValueType>(this->getDdManager(), internalAdd.first, rowAndColumnMetaVariables)});
1038 }
1039 } else {
1040 std::vector<InternalAdd<LibraryType, ValueType>> internalVectors;
1041 for (Add<LibraryType, ValueType> const& v : vectors) {
1042 internalVectors.push_back(v.getInternalAdd());
1043 }
1044 std::vector<std::vector<InternalAdd<LibraryType, ValueType>>> internalAddGroups = internalAdd.splitIntoGroups(internalVectors, ddGroupVariableIndices);
1045 for (auto const& internalAddGroup : internalAddGroups) {
1046 STORM_LOG_ASSERT(internalAddGroup.size() == vectors.size() + 1, "Unexpected group size.");
1047 std::vector<Add<LibraryType, ValueType>> group;
1048 for (uint64_t vectorIndex = 0; vectorIndex < vectors.size(); ++vectorIndex) {
1049 group.push_back(Add<LibraryType, ValueType>(this->getDdManager(), internalAddGroup[vectorIndex], rowMetaVariables));
1050 }
1051 // The last group member corresponds to the matrix.
1052 group.push_back(Add<LibraryType, ValueType>(this->getDdManager(), internalAddGroup.back(), rowAndColumnMetaVariables));
1053 groups.push_back(std::move(group));
1054 }
1055 }
1056
1057 // Create the actual storage for the non-zero entries.
1058 std::vector<storm::storage::MatrixEntry<uint_fast64_t, ValueType>> columnsAndValues(this->getNonZeroCount());
1059
1060 // Now compute the indices at which the individual rows start.
1061 std::vector<uint_fast64_t> rowIndications(rowGroupIndices.back() + 1);
1062
1063 std::vector<InternalAdd<LibraryType, uint_fast64_t>> statesWithGroupEnabled(groups.size());
1064 InternalAdd<LibraryType, uint_fast64_t> stateToRowGroupCount = this->getDdManager().template getAddZero<uint_fast64_t>();
1065 for (uint_fast64_t i = 0; i < groups.size(); ++i) {
1066 std::vector<Add<LibraryType, ValueType>> const& group = groups[i];
1067 Bdd<LibraryType> matrixDdNotZero = group.back().notZero();
1068
1069 std::vector<uint64_t> tmpRowIndications = matrixDdNotZero.template toAdd<uint_fast64_t>().sumAbstract(columnMetaVariables).toVector(rowOdd);
1070 for (uint64_t offset = 0; offset < tmpRowIndications.size(); ++offset) {
1071 rowIndications[rowGroupIndices[offset]] += tmpRowIndications[offset];
1072 }
1073
1074 Bdd<LibraryType> vectorDdNotZero = this->getDdManager().getBddZero();
1075 for (uint64_t vectorIndex = 0; vectorIndex < vectors.size(); ++vectorIndex) {
1076 vectorDdNotZero |= group[vectorIndex].notZero();
1077 group[vectorIndex].internalAdd.composeWithExplicitVector(rowOdd, ddRowVariableIndices, rowGroupIndices, explicitVectors[vectorIndex],
1078 std::plus<ValueType>());
1079 }
1080
1081 statesWithGroupEnabled[i] = (matrixDdNotZero.existsAbstract(columnMetaVariables) || vectorDdNotZero).template toAdd<uint_fast64_t>();
1082 stateToRowGroupCount += statesWithGroupEnabled[i];
1083 statesWithGroupEnabled[i].composeWithExplicitVector(rowOdd, ddRowVariableIndices, rowGroupIndices, std::plus<uint_fast64_t>());
1084 }
1085
1086 // Since we modified the rowGroupIndices, we need to restore the correct values.
1087 stateToRowGroupCount.composeWithExplicitVector(rowOdd, ddRowVariableIndices, rowGroupIndices, std::minus<uint_fast64_t>());
1088
1089 // Now that we computed the number of entries in each row, compute the corresponding offsets in the entry vector.
1090 tmp = 0;
1091 tmp2 = 0;
1092 for (uint_fast64_t i = 1; i < rowIndications.size(); ++i) {
1093 tmp2 = rowIndications[i];
1094 rowIndications[i] = rowIndications[i - 1] + tmp;
1095 std::swap(tmp, tmp2);
1096 }
1097 rowIndications[0] = 0;
1098
1099 // Now actually fill the entry vector.
1100 for (uint_fast64_t i = 0; i < groups.size(); ++i) {
1101 auto const& dd = groups[i].back();
1102
1103 dd.internalAdd.toMatrixComponents(rowGroupIndices, rowIndications, columnsAndValues, rowOdd, columnOdd, ddRowVariableIndices, ddColumnVariableIndices,
1104 true);
1105 statesWithGroupEnabled[i].composeWithExplicitVector(rowOdd, ddRowVariableIndices, rowGroupIndices, std::plus<uint_fast64_t>());
1106 }
1107
1108 // Since we modified the rowGroupIndices, we need to restore the correct values.
1109 stateToRowGroupCount.composeWithExplicitVector(rowOdd, ddRowVariableIndices, rowGroupIndices, std::minus<uint_fast64_t>());
1110
1111 // Since the last call to toMatrixRec modified the rowIndications, we need to restore the correct values.
1112 for (uint_fast64_t i = rowIndications.size() - 1; i > 0; --i) {
1113 rowIndications[i] = rowIndications[i - 1];
1114 }
1115 rowIndications[0] = 0;
1116
1117 return std::make_pair(
1118 storm::storage::SparseMatrix<ValueType>(columnOdd.getTotalOffset(), std::move(rowIndications), std::move(columnsAndValues), std::move(rowGroupIndices)),
1119 std::move(explicitVectors));
1120}
1121
1122template<DdType LibraryType, typename ValueType>
1123void Add<LibraryType, ValueType>::exportToDot(std::string const& filename, bool showVariablesIfPossible) const {
1124 internalAdd.exportToDot(filename, this->getDdManager().getDdVariableNames(), showVariablesIfPossible);
1125}
1126
1127template<DdType LibraryType, typename ValueType>
1128void Add<LibraryType, ValueType>::exportToText(std::string const& filename) const {
1129 internalAdd.exportToText(filename);
1130}
1131
1132template<DdType LibraryType, typename ValueType>
1134 uint_fast64_t numberOfDdVariables = 0;
1135 for (auto const& metaVariable : this->getContainedMetaVariables()) {
1136 auto const& ddMetaVariable = this->getDdManager().getMetaVariable(metaVariable);
1137 numberOfDdVariables += ddMetaVariable.getNumberOfDdVariables();
1138 }
1139
1140 return internalAdd.begin(this->getDdManager(), Bdd<LibraryType>::getCube(this->getDdManager(), this->getContainedMetaVariables()).getInternalBdd(),
1141 numberOfDdVariables, this->getContainedMetaVariables(), enumerateDontCareMetaVariables);
1142}
1143
1144template<DdType LibraryType, typename ValueType>
1146 return internalAdd.end(this->getDdManager());
1147}
1148
1149template<DdType LibraryType, typename ValueType>
1150std::ostream& operator<<(std::ostream& out, Add<LibraryType, ValueType> const& add) {
1151 out << "ADD [" << add.getInternalAdd().getStringId() << "] with " << add.getNonZeroCount() << " nnz, " << add.getNodeCount() << " nodes, "
1152 << add.getLeafCount() << " leaves\n";
1153 std::vector<std::string> variableNames;
1154 for (auto const& variable : add.getContainedMetaVariables()) {
1155 variableNames.push_back(variable.getName());
1156 }
1157 out << "contained variables: " << boost::algorithm::join(variableNames, ", ") << '\n';
1158 return out;
1159}
1160
1161template<DdType LibraryType, typename ValueType>
1163 Odd const& odd, std::set<storm::expressions::Variable> const& metaVariables) {
1164 return Add<LibraryType, ValueType>(ddManager,
1165 InternalAdd<LibraryType, ValueType>::fromVector(ddManager.getInternalDdManagerPointer(), values, odd,
1166 ddManager.getSortedVariableIndices(metaVariables)),
1167 metaVariables);
1168}
1169
1170template<DdType LibraryType, typename ValueType>
1174
1175template<DdType LibraryType, typename ValueType>
1177 return internalAdd.createOdd(this->getSortedVariableIndices());
1178}
1179
1180template<DdType LibraryType, typename ValueType>
1184
1185template<DdType LibraryType, typename ValueType>
1187 return internalAdd.getInternalDdManager();
1188}
1189
1190template<DdType LibraryType, typename ValueType>
1192 return internalAdd;
1193}
1194
1195template<DdType LibraryType, typename ValueType>
1196template<typename TargetValueType>
1197std::enable_if_t<std::is_same_v<TargetValueType, ValueType>, Add<LibraryType, TargetValueType>> Add<LibraryType, ValueType>::toValueType() const {
1198 return *this;
1199}
1200
1201template<DdType LibraryType, typename ValueType>
1202template<typename TargetValueType>
1203std::enable_if_t<!std::is_same_v<TargetValueType, ValueType>, Add<LibraryType, TargetValueType>> Add<LibraryType, ValueType>::toValueType() const {
1204 return Add<LibraryType, TargetValueType>(this->getDdManager(), internalAdd.template toValueType<TargetValueType>(), this->getContainedMetaVariables());
1205}
1206
1208template std::ostream& operator<<(std::ostream& out, Add<storm::dd::DdType::CUDD, double> const& add);
1210
1212template std::ostream& operator<<(std::ostream& out, Add<storm::dd::DdType::Sylvan, double> const& add);
1214
1216template std::ostream& operator<<(std::ostream& out, Add<storm::dd::DdType::Sylvan, storm::RationalNumber> const& add);
1218template std::ostream& operator<<(std::ostream& out, Add<storm::dd::DdType::Sylvan, storm::RationalFunction> const& add);
1219
1221 const;
1225} // namespace dd
1226} // namespace storm
Definition DdTest.cpp:39
Add< LibraryType, ValueType > restrict(Add< LibraryType, ValueType > const &constraint) const
Computes the restriction of the current ADD with the given constraint.
Definition Add.cpp:425
Add< LibraryType, ValueType > swapVariables(std::vector< std::pair< storm::expressions::Variable, storm::expressions::Variable > > const &metaVariablePairs) const
Swaps the given pairs of meta variables in the ADD.
Definition Add.cpp:276
MatrixAndLabeling toLabeledMatrix(std::set< storm::expressions::Variable > const &rowMetaVariables, std::set< storm::expressions::Variable > const &columnMetaVariables, std::set< storm::expressions::Variable > const &groupMetaVariables, storm::dd::Odd const &rowOdd, storm::dd::Odd const &columnOdd, std::vector< std::set< storm::expressions::Variable > > const &labelMetaVariables=std::vector< std::set< storm::expressions::Variable > >()) const
Definition Add.cpp:736
Add< LibraryType, ValueType > pow(Add< LibraryType, ValueType > const &other) const
Retrieves the function that represents the current ADD to the power of the given ADD.
Definition Add.cpp:119
Bdd< LibraryType > equals(Add< LibraryType, ValueType > const &other) const
Retrieves the function that maps all evaluations to one that have identical function values.
Definition Add.cpp:89
friend class Add
Definition Add.h:44
bool isOne() const
Retrieves whether this ADD represents the constant one function.
Definition Add.cpp:511
Add< LibraryType, ValueType > operator+(Add< LibraryType, ValueType > const &other) const
Adds the two ADDs.
Definition Add.cpp:36
Add< LibraryType, ValueType > operator*(Add< LibraryType, ValueType > const &other) const
Multiplies the two ADDs.
Definition Add.cpp:48
ValueType getMax() const
Retrieves the highest function value of any encoding.
Definition Add.cpp:459
void exportToDot(std::string const &filename, bool showVariablesIfPossible=true) const override
Exports the DD to the given file in the dot format.
Definition Add.cpp:1123
InternalAdd< LibraryType, ValueType > const & getInternalAdd() const
Retrieves the internal ADD.
Definition Add.cpp:1181
Add< LibraryType, ValueType > floor() const
Retrieves the function that floors all values in the current ADD.
Definition Add.cpp:134
Bdd< LibraryType > lessOrEqual(Add< LibraryType, ValueType > const &other) const
Retrieves the function that maps all evaluations to one whose function value in the first ADD are les...
Definition Add.cpp:104
std::pair< storm::storage::SparseMatrix< ValueType >, std::vector< std::vector< ValueType > > > toMatrixVectors(std::vector< storm::dd::Add< LibraryType, ValueType > > const &vectors, std::set< storm::expressions::Variable > const &groupMetaVariables, storm::dd::Odd const &rowOdd, storm::dd::Odd const &columnOdd) const
Converts the ADD to a row-grouped (sparse) matrix and the given vectors to row-grouped vectors.
Definition Add.cpp:946
virtual uint_fast64_t getLevel() const override
Retrieves the level of the topmost variable in the DD.
Definition Add.cpp:531
bool operator==(Add< LibraryType, ValueType > const &other) const
Retrieves whether the two DDs represent the same function.
Definition Add.cpp:26
Add< LibraryType, ValueType > logxy(Add< LibraryType, ValueType > const &other) const
Retrieves the function that represents the logarithm of the current ADD to the bases given by the sec...
Definition Add.cpp:129
Add< LibraryType, ValueType > minimum(Add< LibraryType, ValueType > const &other) const
Retrieves the function that maps all evaluations to the minimum of the function values of the two ADD...
Definition Add.cpp:152
Add< LibraryType, ValueType > & operator+=(Add< LibraryType, ValueType > const &other)
Adds the given ADD to the current one.
Definition Add.cpp:41
storm::storage::SparseMatrix< ValueType > toMatrix() const
Converts the ADD to a (sparse) matrix.
Definition Add.cpp:618
ValueType getMin() const
Retrieves the lowest function value of any encoding.
Definition Add.cpp:454
Bdd< LibraryType > greater(Add< LibraryType, ValueType > const &other) const
Retrieves the function that maps all evaluations to one whose function value in the first ADD are gre...
Definition Add.cpp:109
Add< LibraryType, ValueType > maximum(Add< LibraryType, ValueType > const &other) const
Retrieves the function that maps all evaluations to the maximum of the function values of the two ADD...
Definition Add.cpp:157
ValueType getValue(std::map< storm::expressions::Variable, int_fast64_t > const &metaVariableToValueMap=std::map< storm::expressions::Variable, int_fast64_t >()) const
Retrieves the value of the function when all meta variables are assigned the values of the given mapp...
Definition Add.cpp:492
Add< LibraryType, storm::RationalNumber > sharpenKwekMehlhorn(uint64_t precision) const
Retrieves the function that sharpens all values in the current ADD with the Kwek-Mehlhorn algorithm.
Definition Add.cpp:144
Add< LibraryType, ValueType > renameVariables(std::set< storm::expressions::Variable > const &from, std::set< storm::expressions::Variable > const &to) const
Renames the given meta variables in the ADD.
Definition Add.cpp:200
Add< LibraryType, ValueType > maxAbstract(std::set< storm::expressions::Variable > const &metaVariables) const
Max-abstracts from the given meta variables.
Definition Add.cpp:182
std::pair< storm::storage::SparseMatrix< ValueType >, std::vector< ValueType > > toMatrixVector(storm::dd::Add< LibraryType, ValueType > const &vector, std::set< storm::expressions::Variable > const &groupMetaVariables, storm::dd::Odd const &rowOdd, storm::dd::Odd const &columnOdd) const
Converts the ADD to a row-grouped (sparse) matrix and the given vector to a row-grouped vector.
Definition Add.cpp:900
static Add< LibraryType, ValueType > fromVector(DdManager< LibraryType > const &ddManager, std::vector< ValueType > const &values, Odd const &odd, std::set< storm::expressions::Variable > const &metaVariables)
Builds an ADD representing the given vector.
Definition Add.cpp:1162
Add< LibraryType, ValueType > operator-(Add< LibraryType, ValueType > const &other) const
Subtracts the given ADD from the current one.
Definition Add.cpp:60
AddIterator< LibraryType, ValueType > begin(bool enumerateDontCareMetaVariables=true) const
Retrieves an iterator that points to the first meta variable assignment with a non-zero function valu...
Definition Add.cpp:1133
InternalDdManager< LibraryType > const & getInternalDdManager() const
Retrieves the internal ADD.
Definition Add.cpp:1186
virtual uint_fast64_t getNonZeroCount() const override
Retrieves the number of encodings that are mapped to a non-zero value.
Definition Add.cpp:435
Add< LibraryType, ValueType > sumAbstract(std::set< storm::expressions::Variable > const &metaVariables) const
Sum-abstracts from the given meta variables.
Definition Add.cpp:162
std::enable_if_t< std::is_same_v< TargetValueType, ValueType >, Add< LibraryType, TargetValueType > > toValueType() const
Replaces the leaves in this MTBDD, converting them to double if possible, and -1.0 else.
Definition Add.cpp:1197
virtual uint_fast64_t getNodeCount() const override
Retrieves the number of nodes necessary to represent the DD.
Definition Add.cpp:449
Bdd< LibraryType > getSupport() const override
Retrieves the support of the current ADD.
Definition Add.cpp:430
Bdd< LibraryType > minAbstractRepresentative(std::set< storm::expressions::Variable > const &metaVariables) const
Similar to minAbstract, but does not abstract from the variables but rather picks a valuation of each...
Definition Add.cpp:176
Bdd< LibraryType > greaterOrEqual(Add< LibraryType, ValueType > const &other) const
Retrieves the function that maps all evaluations to one whose function value in the first ADD are gre...
Definition Add.cpp:114
Add< LibraryType, ValueType > minAbstract(std::set< storm::expressions::Variable > const &metaVariables) const
Min-abstracts from the given meta variables.
Definition Add.cpp:169
Odd createOdd() const
Creates an ODD based on the current ADD.
Definition Add.cpp:1176
AddIterator< LibraryType, ValueType > end() const
Retrieves an iterator that points past the end of the container.
Definition Add.cpp:1145
virtual uint_fast64_t getIndex() const override
Retrieves the index of the topmost variable in the DD.
Definition Add.cpp:526
bool isZero() const
Retrieves whether this ADD represents the constant zero function.
Definition Add.cpp:516
Add< LibraryType, ValueType > multiplyMatrix(Add< LibraryType, ValueType > const &otherMatrix, std::set< storm::expressions::Variable > const &summationMetaVariables) const
Multiplies the current ADD (representing a matrix) with the given matrix by summing over the given me...
Definition Add.cpp:356
Add< LibraryType, ValueType > & operator-=(Add< LibraryType, ValueType > const &other)
Subtracts the given ADD from the current one and assigns the result to the current ADD.
Definition Add.cpp:70
Add< LibraryType, ValueType > mod(Add< LibraryType, ValueType > const &other) const
Retrieves the function that represents the current ADD modulo the given ADD.
Definition Add.cpp:124
Add< LibraryType, ValueType > & operator*=(Add< LibraryType, ValueType > const &other)
Multiplies the given ADD with the current one and assigns the result to the current ADD.
Definition Add.cpp:53
Add< LibraryType, ValueType > operator/(Add< LibraryType, ValueType > const &other) const
Divides the current ADD by the given one.
Definition Add.cpp:77
virtual uint_fast64_t getLeafCount() const override
Retrieves the number of leaves of the ADD.
Definition Add.cpp:444
bool isConstant() const
Retrieves whether this ADD represents a constant function.
Definition Add.cpp:521
Bdd< LibraryType > toBdd() const
Converts the ADD to a BDD by mapping all values unequal to zero to 1.
Definition Add.cpp:1171
Add< LibraryType, ValueType > constrain(Add< LibraryType, ValueType > const &constraint) const
Computes the constraint of the current ADD with the given constraint.
Definition Add.cpp:420
bool equalModuloPrecision(Add< LibraryType, ValueType > const &other, ValueType const &precision, bool relative=true) const
Checks whether the current and the given ADD represent the same function modulo some given precision.
Definition Add.cpp:195
Bdd< LibraryType > notEquals(Add< LibraryType, ValueType > const &other) const
Retrieves the function that maps all evaluations to one that have distinct function values.
Definition Add.cpp:94
virtual void exportToText(std::string const &filename) const override
Exports the DD to the given file in the dot format.
Definition Add.cpp:1128
void setValue(storm::expressions::Variable const &metaVariable, int_fast64_t variableValue, ValueType const &targetValue)
Sets the function values of all encodings that have the given value of the meta variable to the given...
Definition Add.cpp:464
Bdd< LibraryType > notZero() const
Computes a BDD that represents the function in which all assignments with a function value unequal to...
Definition Add.cpp:415
Add< LibraryType, ValueType > ceil() const
Retrieves the function that ceils all values in the current ADD.
Definition Add.cpp:139
Add< LibraryType, ValueType > & operator/=(Add< LibraryType, ValueType > const &other)
Divides the current ADD by the given one and assigns the result to the current ADD.
Definition Add.cpp:82
Bdd< LibraryType > maxAbstractRepresentative(std::set< storm::expressions::Variable > const &metaVariables) const
Similar to maxAbstract, but does not abstract from the variables but rather picks a valuation of each...
Definition Add.cpp:189
bool operator!=(Add< LibraryType, ValueType > const &other) const
Retrieves whether the two DDs represent different functions.
Definition Add.cpp:31
std::vector< ValueType > toVector() const
Converts the ADD to a vector.
Definition Add.cpp:536
Add< LibraryType, ValueType > renameVariablesAbstract(std::set< storm::expressions::Variable > const &from, std::set< storm::expressions::Variable > const &to) const
Renames the given meta variables in the ADD.
Definition Add.cpp:231
Add< LibraryType, ValueType > permuteVariables(std::vector< std::pair< storm::expressions::Variable, storm::expressions::Variable > > const &metaVariablePairs) const
Permutes the given pairs of meta variables in the ADD.
Definition Add.cpp:321
Bdd< LibraryType > less(Add< LibraryType, ValueType > const &other) const
Retrieves the function that maps all evaluations to one whose function value in the first ADD are les...
Definition Add.cpp:99
Bdd< LibraryType > existsAbstract(std::set< storm::expressions::Variable > const &metaVariables) const
Existentially abstracts from the given meta variables.
Definition Bdd.cpp:172
storm::storage::BitVector toVector(storm::dd::Odd const &rowOdd) const
Converts the BDD to a bit vector.
Definition Bdd.cpp:491
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 > 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
InternalBdd< LibraryType > const & getInternalBdd() const
Retrieves the internal BDD.
Definition Bdd.cpp:570
void addMetaVariable(storm::expressions::Variable const &metaVariable)
Adds the given meta variable to the set of meta variables that are contained in this DD.
Definition Dd.cpp:51
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
void addMetaVariables(std::set< storm::expressions::Variable > const &metaVariables)
Adds the given set of meta variables to the DD.
Definition Dd.cpp:43
bool containsMetaVariable(storm::expressions::Variable const &metaVariable) const
Retrieves whether the given meta variable is contained in the DD.
Definition Dd.cpp:18
std::vector< uint_fast64_t > getSortedVariableIndices() const
Retrieves the (sorted) list of the variable indices of DD variables contained in this DD.
Definition Dd.cpp:69
static std::set< storm::expressions::Variable > subtractMetaVariables(storm::dd::Dd< LibraryType > const &first, storm::dd::Dd< LibraryType > const &second)
Retrieves the set of meta variables that are contained in the first but not the second DD.
Definition Dd.cpp:82
std::set< storm::expressions::Variable > const & getContainedMetaVariables() const
Retrieves the set of all meta variables contained in the DD.
Definition Dd.cpp:28
DdManager< LibraryType > & getDdManager() const
Retrieves the manager that is responsible for this DD.
Definition Dd.cpp:38
std::size_t getNumberOfDdVariables() const
Retrieves the number of DD variables for this meta variable.
uint_fast64_t getTotalOffset() const
Retrieves the total offset, i.e., the sum of the then- and else-offset.
Definition Odd.cpp:44
A class that holds a possibly non-square matrix in the compressed row storage format.
#define STORM_LOG_ASSERT(cond, message)
Definition macros.h:9
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:39
constexpr bool SupportsSharpening
Whether the Kwek-Mehlhorn sharpening is available: the backend has to support rational numbers and th...
Definition Add.h:34
std::ostream & operator<<(std::ostream &out, Add< LibraryType, ValueType > const &add)
Definition Add.cpp:1150
The contract of a DD backend.
Converts the ADD to a row-grouped (sparse) matrix.
Definition Add.h:678