Browse Source
Further work on abstraction layer for DDs.
Further work on abstraction layer for DDs.
Former-commit-id: 245986076b
tempestpy_adaptions
dehnert
11 years ago
7 changed files with 378 additions and 31 deletions
-
90src/storage/dd/CuddDd.cpp
-
178src/storage/dd/CuddDd.h
-
68src/storage/dd/CuddDdManager.cpp
-
42src/storage/dd/CuddDdManager.h
-
13src/storage/dd/DdMetaVariable.cpp
-
6src/storage/dd/DdMetaVariable.h
-
12src/storage/dd/DdType.h
@ -0,0 +1,90 @@ |
|||
#include "src/storage/dd/CuddDd.h"
|
|||
|
|||
namespace storm { |
|||
namespace dd { |
|||
Dd(std::shared_ptr<DdManager<CUDD>> ddManager, ADD cuddAdd, std::unordered_set<std::string> const& containedMetaVariableNames) noexcept : ddManager(ddManager), cuddAdd(cuddAdd), containedMetaVariableNames(containedMetaVariableNames) { |
|||
// Intentionally left empty.
|
|||
} |
|||
|
|||
Dd<CUDD> Dd<CUDD>::operator+(Dd<CUDD> const& other) const { |
|||
Dd<CUDD> result(*this); |
|||
result += other; |
|||
return result; |
|||
} |
|||
|
|||
Dd<CUDD>& Dd<CUDD>::operator+=(Dd<CUDD> const& other) { |
|||
cuddAdd += other; |
|||
|
|||
// Join the variable sets of the two participating DDs.
|
|||
std::copy(other.getContainedMetaVariableNames().begin(), other.getContainedMetaVariableNames().containedMetaVariableNames.end(), std::inserter(this->containedMetaVariableNames, this->containedMetaVariableNames.end())); |
|||
|
|||
return *this; |
|||
} |
|||
|
|||
Dd<CUDD> Dd<CUDD>::operator*(Dd<CUDD> const& other) const { |
|||
Dd<CUDD> result(*this); |
|||
result *= other; |
|||
return result; |
|||
} |
|||
|
|||
Dd<CUDD>& Dd<CUDD>::operator*=(Dd<CUDD> const& other) { |
|||
cuddAdd *= other; |
|||
|
|||
// Join the variable sets of the two participating DDs.
|
|||
std::copy(other.getContainedMetaVariableNames().begin(), other.getContainedMetaVariableNames().containedMetaVariableNames.end(), std::inserter(this->containedMetaVariableNames, this->containedMetaVariableNames.end())); |
|||
|
|||
return *this; |
|||
} |
|||
|
|||
Dd<CUDD> Dd<CUDD>::operator-(Dd<CUDD> const& other) const { |
|||
Dd<CUDD> result(*this); |
|||
result -= other; |
|||
return result; |
|||
} |
|||
|
|||
Dd<CUDD>& Dd<CUDD>::operator-=(Dd<CUDD> const& other) { |
|||
cuddAdd -= other; |
|||
|
|||
// Join the variable sets of the two participating DDs.
|
|||
std::copy(other.getContainedMetaVariableNames().begin(), other.getContainedMetaVariableNames().containedMetaVariableNames.end(), std::inserter(this->containedMetaVariableNames, this->containedMetaVariableNames.end())); |
|||
|
|||
return *this; |
|||
} |
|||
|
|||
Dd<CUDD> Dd<CUDD>::operator/(Dd<CUDD> const& other) const { |
|||
Dd<CUDD> result(*this); |
|||
result /= other; |
|||
return result; |
|||
} |
|||
|
|||
Dd<CUDD>& Dd<CUDD>::operator/=(Dd<CUDD> const& other) { |
|||
cuddAdd.Divide(other); |
|||
|
|||
// Join the variable sets of the two participating DDs.
|
|||
std::copy(other.getContainedMetaVariableNames().begin(), other.getContainedMetaVariableNames().containedMetaVariableNames.end(), std::inserter(this->containedMetaVariableNames, this->containedMetaVariableNames.end())); |
|||
|
|||
return *this; |
|||
} |
|||
|
|||
Dd<CUDD> Dd<CUDD>::operator~() const { |
|||
Dd<CUDD> result(*this); |
|||
result.complement(); |
|||
return result; |
|||
} |
|||
|
|||
Dd<CUDD>& Dd<CUDD>::complement() { |
|||
cuddAdd = ~cuddAdd; |
|||
return *this; |
|||
} |
|||
|
|||
void Dd<CUDD>::exportToDot(std::string const& filename) const { |
|||
FILE* filePointer = fopen(filename.c_str() , "w"); |
|||
this->getDdManager()->getCuddManager().DumpDot({this->cuddAdd}, nullptr, nullptr, filePointer); |
|||
fclose(filePointer); |
|||
} |
|||
|
|||
std::shared_ptr<DdManager<CUDD>> Dd<CUDD>::getDdManager() const { |
|||
return this->ddManager; |
|||
} |
|||
} |
|||
} |
@ -1,7 +1,75 @@ |
|||
#include "src/storage/dd/CuddDdManager.h"
|
|||
#include "src/exceptions/InvalidArgumentException.h"
|
|||
|
|||
namespace storm { |
|||
namespace dd { |
|||
DdManager<CUDD>::DdManager() noexcept : metaVariableMap(), cuddManager() { |
|||
// Intentionally left empty.
|
|||
} |
|||
|
|||
Dd<CUDD> DdManager<CUDD>::getOne() { |
|||
return Dd<CUDD>(this->shared_from_this(), cuddManager.addOne(), {""}); |
|||
} |
|||
|
|||
Dd<CUDD> DdManager<CUDD>::getZero() { |
|||
return Dd<CUDD>(this->shared_from_this(), cuddManager.addZero(), {""}); |
|||
} |
|||
|
|||
Dd<CUDD> DdManager<CUDD>::getConstant(double value) { |
|||
return Dd<CUDD>(this->shared_from_this(), cuddManager.constant(value), {""}); |
|||
} |
|||
|
|||
void DdManager<CUDD>::addMetaVariable(std::string const& name, int_fast64_t low, int_fast64_t high) { |
|||
std::size_t numberOfBits = std::log2(high - low); |
|||
|
|||
std::vector<Dd<CUDD>> variables; |
|||
for (std::size_t i = 0; i < numberOfBits; ++i) { |
|||
variables.emplace_back(cuddManager.addVar()); |
|||
} |
|||
|
|||
metaVariableMap.emplace(name, low, high, variables, this->shared_from_this()); |
|||
} |
|||
|
|||
void DdManager<CUDD>::addMetaVariablesInterleaved(std::vector<std::string> const& names, int_fast64_t low, int_fast64_t high) { |
|||
if (names.size() == 0) { |
|||
throw storm::exceptions::InvalidArgumentException() << "Illegal to add zero meta variables."; |
|||
} |
|||
|
|||
// Add the variables in interleaved order.
|
|||
std::size_t numberOfBits = std::log2(high - low); |
|||
std::vector<std::vector<Dd<CUDD>>> variables; |
|||
for (uint_fast64_t bit = 0; bit < numberOfBits; ++bit) { |
|||
for (uint_fast64_t i = 0; i < names.size(); ++i) { |
|||
variables[i].emplace_back(cuddManager.addVar()); |
|||
} |
|||
} |
|||
|
|||
// Now add the meta variables.
|
|||
for (uint_fast64_t i = 0; i < names.size(); ++i) { |
|||
metaVariableMap.emplace(names[i], low, high, variables[i], this->shared_from_this()); |
|||
} |
|||
} |
|||
|
|||
DdMetaVariable<CUDD> const& DdManager<CUDD>::getMetaVariable(std::string const& metaVariableName) const { |
|||
auto const& nameVariablePair = metaVariableMap.find(metaVariableName); |
|||
|
|||
if (nameVariablePair == metaVariableMap.end()) { |
|||
throw storm::exceptions::InvalidArgumentException() << "Unknown meta variable name."; |
|||
} |
|||
|
|||
return nameVariablePair->second; |
|||
} |
|||
|
|||
std::unordered_set<std::string> DdManager<CUDD>::getAllMetaVariableNames() const { |
|||
std::unordered_set<std::string> result; |
|||
for (auto const& nameValuePair : metaVariableMap) { |
|||
result.insert(nameValuePair.first); |
|||
} |
|||
return result; |
|||
} |
|||
|
|||
Cudd& DdManager<CUDD>::getCuddManager() { |
|||
return this->cuddManager; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,12 @@ |
|||
#ifndef STORM_STORAGE_DD_DDTYPE_H_ |
|||
#define STORM_STORAGE_DD_DDTYPE_H_ |
|||
|
|||
namespace storm { |
|||
namespace dd { |
|||
enum DdType { |
|||
CUDD |
|||
}; |
|||
} |
|||
} |
|||
|
|||
#endif /* STORM_STORAGE_DD_DDTYPE_H_ */ |
Write
Preview
Loading…
Cancel
Save
Reference in new issue