14namespace abstraction {
16template<storm::dd::DdType DdType>
18 std::set<storm::expressions::Variable>
const& abstractedVariables,
21 : expressionManager(expressionManager),
22 equivalenceChecker(
std::move(smtSolver)),
23 abstractedVariables(abstractedVariables),
24 constraints(options.constraints),
26 allPredicateIdentities(ddManager->getBddOne()),
27 allLocationIdentities(ddManager->getBddOne()),
28 expressionToBddMap() {
32template<storm::dd::DdType DdType>
34 abstractedVariables.insert(variable);
37template<storm::dd::DdType DdType>
39 addExpressionVariable(variable);
40 addConstraint(constraint);
43template<storm::dd::DdType DdType>
45 constraints.push_back(constraint);
48template<storm::dd::DdType DdType>
51 for (uint64_t index = 0; index < predicates.size(); ++index) {
52 auto const& oldPredicate = predicates[index];
53 if (equivalenceChecker.areEquivalent(oldPredicate, predicate)) {
54 expressionToBddMap[predicate] = expressionToBddMap.at(oldPredicate);
59 std::size_t predicateIndex = predicates.size();
60 predicateToIndexMap[predicate] = predicateIndex;
63 predicates.push_back(predicate);
66 std::stringstream stream;
68 std::pair<storm::expressions::Variable, storm::expressions::Variable> newMetaVariable = ddManager->addMetaVariable(stream.str());
70 predicateDdVariables.push_back(newMetaVariable);
71 extendedPredicateDdVariables.push_back(newMetaVariable);
72 predicateBdds.emplace_back(ddManager->getEncoding(newMetaVariable.first, 1), ddManager->getEncoding(newMetaVariable.second, 1));
73 predicateIdentities.push_back(ddManager->getEncoding(newMetaVariable.first, 1).iff(ddManager->getEncoding(newMetaVariable.second, 1)));
74 allPredicateIdentities &= predicateIdentities.back();
75 sourceVariables.insert(newMetaVariable.first);
76 successorVariables.insert(newMetaVariable.second);
77 sourcePredicateVariables.insert(newMetaVariable.first);
78 successorPredicateVariables.insert(newMetaVariable.second);
79 orderedSourcePredicateVariables.push_back(newMetaVariable.first);
80 orderedSuccessorPredicateVariables.push_back(newMetaVariable.second);
81 ddVariableIndexToPredicateIndexMap[predicateIdentities.back().getIndex()] = predicateIndex;
82 expressionToBddMap[predicate] = predicateBdds[predicateIndex].first && !bottomStateBdds.first;
84 return predicateIndex;
87template<storm::dd::DdType DdType>
89 std::vector<uint_fast64_t> predicateIndices;
90 for (
auto const& predicate : predicates) {
91 predicateIndices.push_back(this->getOrAddPredicate(predicate));
93 return predicateIndices;
96template<storm::dd::DdType DdType>
101template<storm::dd::DdType DdType>
103 return expressionManager.get();
106template<storm::dd::DdType DdType>
108 return expressionManager.get();
111template<storm::dd::DdType DdType>
116template<storm::dd::DdType DdType>
121template<storm::dd::DdType DdType>
126template<storm::dd::DdType DdType>
131template<storm::dd::DdType DdType>
136template<storm::dd::DdType DdType>
138 STORM_LOG_ASSERT(predicateValuation.
size() == this->getNumberOfPredicates(),
"Size of predicate valuation does not match number of predicates.");
140 std::vector<storm::expressions::Expression> result;
141 for (uint64_t index = 0; index < this->getNumberOfPredicates(); ++index) {
142 if (predicateValuation[index]) {
143 result.push_back(this->getPredicateByIndex(index));
145 result.push_back(!this->getPredicateByIndex(index));
152template<storm::dd::DdType DdType>
155 uint64_t offset = 1 + this->getNumberOfDdSourceLocationVariables();
156 STORM_LOG_ASSERT(predicateValuation.
size() == this->getNumberOfPredicates() + offset,
"Size of predicate valuation does not match number of predicates.");
158 std::vector<storm::expressions::Expression> result;
159 for (uint64_t index = 0; index < this->getNumberOfPredicates(); ++index) {
160 if (predicateValuation[index + offset]) {
161 result.push_back(this->getPredicateByIndex(index));
163 result.push_back(!this->getPredicateByIndex(index));
170template<storm::dd::DdType DdType>
172 return predicates[index];
175template<storm::dd::DdType DdType>
177 auto indexIt = predicateToIndexMap.find(predicate);
178 STORM_LOG_THROW(indexIt != predicateToIndexMap.end(), storm::exceptions::InvalidOperationException,
"Cannot retrieve BDD for unknown predicate.");
179 return predicateBdds[indexIt->second].first;
182template<storm::dd::DdType DdType>
184 return predicateToIndexMap.find(predicate) != predicateToIndexMap.end();
187template<storm::dd::DdType DdType>
189 return predicates.size();
192template<storm::dd::DdType DdType>
194 return abstractedVariables;
197template<storm::dd::DdType DdType>
199 STORM_LOG_THROW(player1Variables.empty() && player2Variables.empty() && auxVariables.empty(), storm::exceptions::InvalidOperationException,
200 "Variables have already been created.");
202 for (uint64_t index = 0; index < player1VariableCount; ++index) {
204 player1Variables.push_back(newVariable);
205 player1VariableBdds.push_back(ddManager->getEncoding(newVariable, 1));
207 STORM_LOG_DEBUG(
"Created " << player1VariableCount <<
" player 1 variables.");
209 for (uint64_t index = 0; index < player2VariableCount; ++index) {
211 player2Variables.push_back(newVariable);
212 player2VariableBdds.push_back(ddManager->getEncoding(newVariable, 1));
214 STORM_LOG_DEBUG(
"Created " << player2VariableCount <<
" player 2 variables.");
216 for (uint64_t index = 0; index < auxVariableCount; ++index) {
218 auxVariables.push_back(newVariable);
219 auxVariableBdds.push_back(ddManager->getEncoding(newVariable, 1));
221 STORM_LOG_DEBUG(
"Created " << auxVariableCount <<
" auxiliary variables.");
223 bottomStateVariables = ddManager->addMetaVariable(
"bot");
224 bottomStateBdds = std::make_pair(ddManager->getEncoding(bottomStateVariables.first, 1), ddManager->getEncoding(bottomStateVariables.second, 1));
225 extendedPredicateDdVariables.push_back(bottomStateVariables);
228template<storm::dd::DdType DdType>
230 return encodeChoice(index, 0, end, player1VariableBdds);
233template<storm::dd::DdType DdType>
235 return decodeChoice(valuation, 0, end, player1Variables);
238template<storm::dd::DdType DdType>
240 return encodeChoice(index, start, end, player2VariableBdds);
243template<storm::dd::DdType DdType>
245 return decodeChoice(valuation, 0, end, player2Variables);
248template<storm::dd::DdType DdType>
250 return encodeChoice(index, start, end, auxVariableBdds);
253template<storm::dd::DdType DdType>
255 return decodeChoice(valuation, start, end, auxVariables);
258template<storm::dd::DdType DdType>
260 return player1Variables;
263template<storm::dd::DdType DdType>
265 return std::set<storm::expressions::Variable>(player1Variables.begin(), player1Variables.begin() + count);
268template<storm::dd::DdType DdType>
270 return player2Variables;
273template<storm::dd::DdType DdType>
275 return std::set<storm::expressions::Variable>(player2Variables.begin(), player2Variables.begin() + count);
278template<storm::dd::DdType DdType>
283template<storm::dd::DdType DdType>
285 return auxVariables[index];
288template<storm::dd::DdType DdType>
290 return std::set<storm::expressions::Variable>(auxVariables.begin() + start, auxVariables.begin() + end);
293template<storm::dd::DdType DdType>
295 return sourceVariables;
298template<storm::dd::DdType DdType>
300 return successorVariables;
303template<storm::dd::DdType DdType>
305 return sourcePredicateVariables;
308template<storm::dd::DdType DdType>
310 return successorPredicateVariables;
313template<storm::dd::DdType DdType>
315 return orderedSourcePredicateVariables;
318template<storm::dd::DdType DdType>
320 return orderedSuccessorPredicateVariables;
323template<storm::dd::DdType DdType>
325 return allPredicateIdentities;
327template<storm::dd::DdType DdType>
329 return allLocationIdentities;
332template<storm::dd::DdType DdType>
334 return player1Variables.size();
337template<storm::dd::DdType DdType>
339 return player2Variables.size();
342template<storm::dd::DdType DdType>
344 return auxVariables.size();
347template<storm::dd::DdType DdType>
349 return expressionToBddMap;
352template<storm::dd::DdType DdType>
355 return predicateDdVariables;
358template<storm::dd::DdType DdType>
359std::vector<std::pair<storm::expressions::Variable, storm::expressions::Variable>>
const&
361 return extendedPredicateDdVariables;
364template<storm::dd::DdType DdType>
367 return bottomStateVariables.first;
369 return bottomStateVariables.second;
373template<storm::dd::DdType DdType>
377 return !bottomStateBdds.first;
379 return bottomStateBdds.first;
383 return !bottomStateBdds.second;
385 return bottomStateBdds.second;
390template<storm::dd::DdType DdType>
392 return predicateBdds[predicateIndex].first;
395template<storm::dd::DdType DdType>
397 return predicateBdds[predicateIndex].second;
400template<storm::dd::DdType DdType>
402 return predicateIdentities[predicateIndex];
405template<storm::dd::DdType DdType>
407 auto indexIt = ddVariableIndexToPredicateIndexMap.find(ddVariableIndex);
408 STORM_LOG_THROW(indexIt != ddVariableIndexToPredicateIndexMap.end(), storm::exceptions::InvalidOperationException,
"Unknown DD variable index.");
409 return predicates[indexIt->second];
412template<storm::dd::DdType DdType>
414 std::vector<std::pair<storm::expressions::Variable, uint_fast64_t>>
const& oldPredicates, std::set<uint_fast64_t>
const& newPredicates)
const {
415 std::vector<std::pair<storm::expressions::Variable, uint_fast64_t>> result;
417 auto oldIt = oldPredicates.begin();
418 auto oldIte = oldPredicates.end();
419 auto newIt = newPredicates.begin();
420 auto newIte = newPredicates.end();
422 for (; newIt != newIte; ++newIt) {
423 if (oldIt == oldIte || oldIt->second != *newIt) {
424 result.push_back(std::make_pair(expressionManager.get().declareFreshBooleanVariable(), *newIt));
433template<storm::dd::DdType DdType>
437 for (uint_fast64_t bitIndex = end; bitIndex > start; --bitIndex) {
438 if ((index & 1) != 0) {
439 result &= variables[bitIndex - 1];
441 result &= !variables[bitIndex - 1];
449template<storm::dd::DdType DdType>
451 std::vector<storm::expressions::Variable>
const& variables)
const {
452 uint_fast64_t result = 0;
453 for (uint_fast64_t variableIndex = start; variableIndex < end; ++variableIndex) {
462template<storm::dd::DdType DdType>
469 auto it = add.
begin();
470 auto stateValuePair = *it;
471 for (uint_fast64_t index = 0; index < this->getOrderedSourcePredicateVariables().size(); ++index) {
472 auto const& successorVariable = this->getOrderedSourcePredicateVariables()[index];
473 if (stateValuePair.first.getBooleanValue(successorVariable)) {
474 statePredicates.
set(index);
478 return statePredicates;
481template<storm::dd::DdType DdType>
482template<
typename ValueType>
485 std::map<uint_fast64_t, std::pair<storm::storage::BitVector, ValueType>> result;
488 for (
auto const& successorValuePair : lowerChoiceAsAdd) {
489 uint_fast64_t updateIndex = this->decodeAux(successorValuePair.first, 0, this->getAuxVariableCount());
492 for (uint_fast64_t index = 0; index < this->getOrderedSuccessorPredicateVariables().size(); ++index) {
493 auto const& successorVariable = this->getOrderedSuccessorPredicateVariables()[index];
494 if (successorValuePair.first.getBooleanValue(successorVariable)) {
495 successor.
set(index);
499 result[updateIndex] = std::make_pair(successor, successorValuePair.second);
504template<storm::dd::DdType DdType>
505template<
typename ValueType>
507 std::set<storm::expressions::Variable>
const& player2Variables,
storm::dd::Bdd<DdType> const& choices)
const {
508 std::vector<storm::dd::Bdd<DdType>> splitChoices = choices.
split(player2Variables);
510 std::vector<std::map<uint_fast64_t, std::pair<storm::storage::BitVector, ValueType>>> result;
511 for (
auto const& choice : splitChoices) {
512 result.emplace_back(this->decodeChoiceToUpdateSuccessorMapping<ValueType>(choice));
518template<storm::dd::DdType DdType>
526 auto it = add.
begin();
527 auto stateValuePair = *it;
528 uint64_t choiceIndex = this->decodePlayer1Choice(stateValuePair.first, this->getPlayer1VariableCount());
529 uint64_t updateIndex = this->decodeAux(stateValuePair.first, 0, this->getAuxVariableCount());
530 for (uint_fast64_t index = 0; index < this->getOrderedSourcePredicateVariables().size(); ++index) {
531 auto const& successorVariable = this->getOrderedSourcePredicateVariables()[index];
533 if (stateValuePair.first.getBooleanValue(successorVariable)) {
534 statePredicates.
set(index);
538 return std::make_tuple(statePredicates, choiceIndex, updateIndex);
541template<storm::dd::DdType DdType>
544 auto newMetaVariable = ddManager->addMetaVariable(
"loc_" + std::to_string(locationVariablePairs.size()), 0, highestLocationIndex);
546 locationExpressionVariables.insert(locationExpressionVariable);
547 locationExpressionToDdVariableMap.emplace(locationExpressionVariable, newMetaVariable);
548 locationVariablePairs.emplace_back(newMetaVariable);
549 allSourceLocationVariables.insert(newMetaVariable.first);
550 sourceVariables.insert(newMetaVariable.first);
551 allSuccessorLocationVariables.insert(newMetaVariable.second);
552 successorVariables.insert(newMetaVariable.second);
553 extendedPredicateDdVariables.emplace_back(newMetaVariable);
554 allLocationIdentities &= ddManager->getIdentity(newMetaVariable.first, newMetaVariable.second);
555 return std::make_pair(locationVariablePairs.back(), locationVariablePairs.size() - 1);
558template<storm::dd::DdType DdType>
561 return locationVariablePairs[locationVariableIndex].first;
563 return locationVariablePairs[locationVariableIndex].second;
567template<storm::dd::DdType DdType>
569 return allSourceLocationVariables;
572template<storm::dd::DdType DdType>
574 return allSuccessorLocationVariables;
577template<storm::dd::DdType DdType>
580 auto const& metaVariablePair = locationExpressionToDdVariableMap.at(locationExpressionVariable);
582 return metaVariablePair.first;
584 return metaVariablePair.second;
588template<storm::dd::DdType DdType>
591 for (
auto const& locationVariableToMetaVariablePair : locationExpressionToDdVariableMap) {
592 result += ddManager->getMetaVariable(locationVariableToMetaVariablePair.second.first).getNumberOfDdVariables();
597template<storm::dd::DdType DdType>
599 return locationExpressionVariables;
602template<storm::dd::DdType DdType>
604 return this->getDdManager().
getEncoding(locationVariable, locationIndex);
610template std::map<uint_fast64_t, std::pair<storm::storage::BitVector, double>>
612template std::map<uint_fast64_t, std::pair<storm::storage::BitVector, double>>
614template std::map<uint_fast64_t, std::pair<storm::storage::BitVector, storm::RationalNumber>>
617template std::vector<std::map<uint_fast64_t, std::pair<storm::storage::BitVector, double>>>
620template std::vector<std::map<uint_fast64_t, std::pair<storm::storage::BitVector, double>>>
623template std::vector<std::map<uint_fast64_t, std::pair<storm::storage::BitVector, storm::RationalNumber>>>
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...
bool isZero() const
Retrieves whether this DD represents the constant zero function.
virtual uint_fast64_t getNonZeroCount() const override
Retrieves the number of encodings that are mapped to a non-zero value.
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.
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).
This class is responsible for managing a set of typed variables and all expressions using these varia...
The base class of all valuations of variables.
virtual bool getBooleanValue(Variable const &booleanVariable) const =0
Retrieves the value of the given boolean variable.
A bit vector that is internally represented as a vector of 64-bit values.
void set(uint_fast64_t index, bool value=true)
Sets the given truth value at the given index.
size_t size() const
Retrieves the number of bits this bit vector can store.
#define STORM_LOG_DEBUG(message)
#define STORM_LOG_ASSERT(cond, message)
#define STORM_LOG_THROW(cond, exception, message)