Browse Source

more modifications needed for refactoring of DD stuff

Former-commit-id: b7b7f52231
tempestpy_adaptions
dehnert 9 years ago
parent
commit
f7c26fd4b1
  1. 9
      src/storage/dd/Add.cpp
  2. 4
      src/storage/dd/Add.h
  3. 2
      src/storage/dd/AddIterator.h
  4. 11
      src/storage/dd/Bdd.cpp
  5. 3
      src/storage/dd/Bdd.h
  6. 11
      src/storage/dd/Dd.h
  7. 8
      src/storage/dd/DdManager.cpp
  8. 6
      src/storage/dd/DdManager.h
  9. 8
      src/storage/dd/DdMetaVariable.h
  10. 14
      src/storage/dd/cudd/CuddAddIterator.cpp
  11. 4
      src/storage/dd/cudd/CuddAddIterator.h
  12. 8
      src/storage/dd/cudd/CuddOdd.cpp
  13. 44
      src/storage/dd/cudd/InternalCuddAdd.cpp
  14. 9
      src/storage/dd/cudd/InternalCuddAdd.h
  15. 8
      src/storage/dd/cudd/InternalCuddBdd.cpp
  16. 2
      src/storage/dd/cudd/InternalCuddBdd.h
  17. 4
      src/storage/dd/cudd/InternalCuddDdManager.h

9
src/storage/dd/Add.cpp

@ -595,12 +595,12 @@ namespace storm {
template<DdType LibraryType, typename ValueType>
AddIterator<LibraryType, ValueType> Add<LibraryType, ValueType>::begin(bool enumerateDontCareMetaVariables) const {
return internalAdd.begin(this->getContainedMetaVariables(), enumerateDontCareMetaVariables);
return internalAdd.begin(this->getDdManager(), this->getContainedMetaVariables(), enumerateDontCareMetaVariables);
}
template<DdType LibraryType, typename ValueType>
AddIterator<LibraryType, ValueType> Add<LibraryType, ValueType>::end(bool enumerateDontCareMetaVariables) const {
return internalAdd.end(enumerateDontCareMetaVariables);
return internalAdd.end(this->getDdManager(), enumerateDontCareMetaVariables);
}
template<DdType LibraryType, typename ValueType>
@ -630,6 +630,11 @@ namespace storm {
return Bdd<DdType::CUDD>(this->getDdManager(), internalAdd.toBdd(), this->getContainedMetaVariables());
}
template<DdType LibraryType, typename ValueType>
Add<LibraryType, ValueType>::operator InternalAdd<LibraryType, ValueType>() const {
return internalAdd;
}
template class Add<storm::dd::DdType::CUDD, double>;
}
}

4
src/storage/dd/Add.h

@ -25,6 +25,7 @@ namespace storm {
public:
friend class DdManager<LibraryType>;
friend class Bdd<LibraryType>;
friend class Odd<LibraryType>;
// Instantiate all copy/move constructors/assignments with the default implementation.
Add() = default;
@ -629,8 +630,7 @@ namespace storm {
/*!
* We provide a conversion operator from the BDD to its internal type to ease calling the internal functions.
*/
operator InternalAdd<LibraryType, ValueType>();
operator InternalAdd<LibraryType, ValueType> const() const;
operator InternalAdd<LibraryType, ValueType>() const;
/*!
* Converts the ADD to a row-grouped (sparse) double matrix. If the optional vector is given, it is also

2
src/storage/dd/AddIterator.h

@ -7,7 +7,7 @@ namespace storm {
namespace dd {
// Declare DdIterator class so we can then specialize it for the different DD types.
template<DdType Type, typename ValueType>
class DdForwardIterator;
class AddIterator;
}
}

11
src/storage/dd/Bdd.cpp

@ -37,7 +37,7 @@ namespace storm {
template<DdType LibraryType>
template<typename ValueType>
Bdd<LibraryType> Bdd<LibraryType>::fromVector(std::shared_ptr<DdManager<LibraryType> const> ddManager, std::vector<ValueType> const& values, Odd<DdType::CUDD> const& odd, std::set<storm::expressions::Variable> const& metaVariables, std::function<bool (ValueType const&)> const& filter) {
return Bdd<LibraryType>(ddManager, InternalBdd<LibraryType>::fromVector(ddManager, values, odd, ddManager->getSortedVariableIndices(metaVariables), filter), metaVariables);
return Bdd<LibraryType>(ddManager, InternalBdd<LibraryType>::fromVector(&ddManager->internalDdManager, values, odd, ddManager->getSortedVariableIndices(metaVariables), filter), metaVariables);
}
template<DdType LibraryType>
@ -176,7 +176,7 @@ namespace storm {
template<DdType LibraryType>
storm::storage::BitVector Bdd<LibraryType>::toVector(storm::dd::Odd<LibraryType> const& rowOdd) const {
return internalBdd.toVector(rowOdd);
return internalBdd.toVector(rowOdd, this->getDdManager()->getSortedVariableIndices());
}
template<DdType LibraryType>
@ -233,12 +233,7 @@ namespace storm {
}
template<DdType LibraryType>
Bdd<LibraryType>::operator InternalBdd<LibraryType>() {
return internalBdd;
}
template<DdType LibraryType>
Bdd<LibraryType>::operator InternalBdd<LibraryType> const() const {
Bdd<LibraryType>::operator InternalBdd<LibraryType>() const {
return internalBdd;
}

3
src/storage/dd/Bdd.h

@ -241,8 +241,7 @@ namespace storm {
/*!
* We provide a conversion operator from the BDD to its internal type to ease calling the internal functions.
*/
operator InternalBdd<LibraryType>();
operator InternalBdd<LibraryType> const() const;
operator InternalBdd<LibraryType>() const;
/*!
* Creates a DD that encapsulates the given CUDD ADD.

11
src/storage/dd/Dd.h

@ -11,14 +11,21 @@
namespace storm {
namespace dd {
// Forward-declare some classes.
template<DdType LibraryType> class DdManager;
template<DdType LibraryType> class Bdd;
template<DdType LibraryType>
class DdManager;
template<DdType LibraryType>
class Bdd;
template<DdType LibraryType>
class Odd;
template<DdType LibraryType>
class Dd {
public:
// Declare the DdManager so it can access the internals of a DD.
friend class DdManager<LibraryType>;
friend class Odd<LibraryType>;
// Instantiate all copy/move constructors/assignments with the default implementation.
Dd() = default;

8
src/storage/dd/DdManager.cpp

@ -118,8 +118,8 @@ namespace storm {
variables.emplace_back(Bdd<DdType::CUDD>(this->shared_from_this(), ddVariablePair.second, {unprimed}));
}
metaVariableMap.emplace(unprimed, DdMetaVariable<LibraryType>(name, low, high, variables, this->shared_from_this()));
metaVariableMap.emplace(primed, DdMetaVariable<LibraryType>(name + "'", low, high, variablesPrime, this->shared_from_this()));
metaVariableMap.emplace(unprimed, DdMetaVariable<LibraryType>(name, low, high, variables));
metaVariableMap.emplace(primed, DdMetaVariable<LibraryType>(name + "'", low, high, variablesPrime));
return std::make_pair(unprimed, primed);
}
@ -141,8 +141,8 @@ namespace storm {
variables.emplace_back(Bdd<DdType::CUDD>(this->shared_from_this(), ddVariablePair.first, {unprimed}));
variablesPrime.emplace_back(Bdd<DdType::CUDD>(this->shared_from_this(), ddVariablePair.second, {primed}));
metaVariableMap.emplace(unprimed, DdMetaVariable<LibraryType>(name, variables, this->shared_from_this()));
metaVariableMap.emplace(primed, DdMetaVariable<LibraryType>(name + "'", variablesPrime, this->shared_from_this()));
metaVariableMap.emplace(unprimed, DdMetaVariable<LibraryType>(name, variables));
metaVariableMap.emplace(primed, DdMetaVariable<LibraryType>(name + "'", variablesPrime));
return std::make_pair(unprimed, primed);
}

6
src/storage/dd/DdManager.h

@ -8,6 +8,7 @@
#include "src/storage/dd/DdMetaVariable.h"
#include "src/storage/dd/Bdd.h"
#include "src/storage/dd/Add.h"
#include "src/storage/dd/AddIterator.h"
#include "src/storage/expressions/Variable.h"
@ -15,12 +16,17 @@
namespace storm {
namespace dd {
template<DdType LibraryType>
class Odd;
// Declare DdManager class so we can then specialize it for the different DD types.
template<DdType LibraryType>
class DdManager : public std::enable_shared_from_this<DdManager<LibraryType>> {
public:
friend class Bdd<LibraryType>;
friend class Add<LibraryType, double>;
friend class AddIterator<LibraryType, double>;
friend class Odd<LibraryType>;
/*!
* Creates an empty manager without any meta variables.

8
src/storage/dd/DdMetaVariable.h

@ -5,6 +5,7 @@
#include "src/storage/dd/DdType.h"
#include "src/storage/dd/Bdd.h"
#include "src/storage/dd/AddIterator.h"
namespace storm {
namespace dd {
@ -23,7 +24,12 @@ namespace storm {
public:
friend class DdManager<LibraryType>;
friend class Bdd<LibraryType>;
friend class Add<LibraryType, double>;
template <DdType LibraryTypePrime, typename ValueTypePrime>
friend class Add;
template <DdType LibraryTypePrime, typename ValueTypePrime>
friend class AddIterator;
/*!
* Retrieves the name of the meta variable.

14
src/storage/dd/cudd/CuddAddIterator.cpp

@ -1,5 +1,5 @@
#include "src/storage/dd/cudd/CuddAddIterator.h"
#include "src/storage/dd/cudd/CuddDdManager.h"
#include "src/storage/dd/DdManager.h"
#include "src/storage/dd/DdMetaVariable.h"
#include "src/utility/macros.h"
#include "src/storage/expressions/ExpressionManager.h"
@ -7,12 +7,12 @@
namespace storm {
namespace dd {
template<typename ValueType>
AddIterator<DdType::CUDD, ValueType>::DdForwardIterator() : ddManager(), generator(), cube(), value(), isAtEnd(), metaVariables(), enumerateDontCareMetaVariables(), cubeCounter(), relevantDontCareDdVariables(), currentValuation() {
AddIterator<DdType::CUDD, ValueType>::AddIterator() : ddManager(), generator(), cube(), value(), isAtEnd(), metaVariables(), enumerateDontCareMetaVariables(), cubeCounter(), relevantDontCareDdVariables(), currentValuation() {
// Intentionally left empty.
}
template<typename ValueType>
AddIterator<DdType::CUDD, ValueType>::DdForwardIterator(std::shared_ptr<DdManager<DdType::CUDD> const> ddManager, DdGen* generator, int* cube, double value, bool isAtEnd, std::set<storm::expressions::Variable> const* metaVariables, bool enumerateDontCareMetaVariables) : ddManager(ddManager), generator(generator), cube(cube), value(value), isAtEnd(isAtEnd), metaVariables(metaVariables), enumerateDontCareMetaVariables(enumerateDontCareMetaVariables), cubeCounter(), relevantDontCareDdVariables(), currentValuation(ddManager->getExpressionManager().getSharedPointer()) {
AddIterator<DdType::CUDD, ValueType>::AddIterator(std::shared_ptr<DdManager<DdType::CUDD> const> ddManager, DdGen* generator, int* cube, double value, bool isAtEnd, std::set<storm::expressions::Variable> const* metaVariables, bool enumerateDontCareMetaVariables) : ddManager(ddManager), generator(generator), cube(cube), value(value), isAtEnd(isAtEnd), metaVariables(metaVariables), enumerateDontCareMetaVariables(enumerateDontCareMetaVariables), cubeCounter(), relevantDontCareDdVariables(), currentValuation(ddManager->getExpressionManager().getSharedPointer()) {
// If the given generator is not yet at its end, we need to create the current valuation from the cube from
// scratch.
if (!this->isAtEnd) {
@ -22,7 +22,7 @@ namespace storm {
}
template<typename ValueType>
AddIterator<DdType::CUDD, ValueType>::DdForwardIterator(AddIterator<DdType::CUDD, ValueType>&& other) : ddManager(other.ddManager), generator(other.generator), cube(other.cube), value(other.value), isAtEnd(other.isAtEnd), metaVariables(other.metaVariables), cubeCounter(other.cubeCounter), relevantDontCareDdVariables(other.relevantDontCareDdVariables), currentValuation(other.currentValuation) {
AddIterator<DdType::CUDD, ValueType>::AddIterator(AddIterator<DdType::CUDD, ValueType>&& other) : ddManager(other.ddManager), generator(other.generator), cube(other.cube), value(other.value), isAtEnd(other.isAtEnd), metaVariables(other.metaVariables), cubeCounter(other.cubeCounter), relevantDontCareDdVariables(other.relevantDontCareDdVariables), currentValuation(other.currentValuation) {
// Null-out the pointers of which we took possession.
other.cube = nullptr;
other.generator = nullptr;
@ -49,7 +49,7 @@ namespace storm {
}
template<typename ValueType>
AddIterator<DdType::CUDD, ValueType>::~DdForwardIterator() {
AddIterator<DdType::CUDD, ValueType>::~AddIterator() {
// We free the pointers sind Cudd allocates them using malloc rather than new/delete.
if (this->cube != nullptr) {
free(this->cube);
@ -89,7 +89,7 @@ namespace storm {
for (uint_fast64_t index = 0; index < this->relevantDontCareDdVariables.size(); ++index) {
auto const& ddMetaVariable = this->ddManager->getMetaVariable(std::get<0>(this->relevantDontCareDdVariables[index]));
if (ddMetaVariable.getType() == DdMetaVariable<DdType::CUDD>::MetaVariableType::Bool) {
if (ddMetaVariable.getType() == MetaVariableType::Bool) {
if ((this->cubeCounter & (1ull << index)) != 0) {
currentValuation.setBooleanValue(std::get<0>(this->relevantDontCareDdVariables[index]), true);
} else {
@ -117,7 +117,7 @@ namespace storm {
bool metaVariableAppearsInCube = false;
std::vector<std::tuple<storm::expressions::Variable, uint_fast64_t>> localRelenvantDontCareDdVariables;
auto const& ddMetaVariable = this->ddManager->getMetaVariable(metaVariable);
if (ddMetaVariable.getType() == DdMetaVariable<DdType::CUDD>::MetaVariableType::Bool) {
if (ddMetaVariable.getType() == MetaVariableType::Bool) {
if (this->cube[ddMetaVariable.getDdVariables().front().getIndex()] == 0) {
metaVariableAppearsInCube = true;
currentValuation.setBooleanValue(metaVariable, false);

4
src/storage/dd/cudd/CuddAddIterator.h

@ -20,12 +20,12 @@ namespace storm {
class DdManager;
template<DdType Type, typename ValueType>
class Add;
class InternalAdd;
template<typename ValueType>
class AddIterator<DdType::CUDD, ValueType> {
public:
friend class Add<DdType::CUDD, ValueType>;
friend class InternalAdd<DdType::CUDD, ValueType>;
// Default-instantiate the constructor.
AddIterator();

8
src/storage/dd/cudd/CuddOdd.cpp

@ -8,8 +8,8 @@
#include "src/exceptions/InvalidArgumentException.h"
#include "src/utility/macros.h"
#include "src/storage/dd/cudd/CuddDdManager.h"
#include "src/storage/dd/cudd/CuddDdMetaVariable.h"
#include "src/storage/dd/DdManager.h"
#include "src/storage/dd/DdMetaVariable.h"
namespace storm {
namespace dd {
@ -23,7 +23,7 @@ namespace storm {
std::vector<std::unordered_map<DdNode*, std::shared_ptr<Odd<DdType::CUDD>>>> uniqueTableForLevels(ddVariableIndices.size() + 1);
// Now construct the ODD structure from the ADD.
std::shared_ptr<Odd<DdType::CUDD>> rootOdd = buildOddFromAddRec(add.getCuddDdNode(), manager->getCuddManager(), 0, ddVariableIndices.size(), ddVariableIndices, uniqueTableForLevels);
std::shared_ptr<Odd<DdType::CUDD>> rootOdd = buildOddFromAddRec(add.internalAdd.getCuddDdNode(), manager->internalDdManager.getCuddManager(), 0, ddVariableIndices.size(), ddVariableIndices, uniqueTableForLevels);
// Finally, move the children of the root ODD into this ODD.
this->elseNode = std::move(rootOdd->elseNode);
@ -42,7 +42,7 @@ namespace storm {
std::vector<std::unordered_map<std::pair<DdNode*, bool>, std::shared_ptr<Odd<DdType::CUDD>>, HashFunctor>> uniqueTableForLevels(ddVariableIndices.size() + 1);
// Now construct the ODD structure from the BDD.
std::shared_ptr<Odd<DdType::CUDD>> rootOdd = buildOddFromBddRec(Cudd_Regular(bdd.getCuddDdNode()), manager->getCuddManager(), 0, Cudd_IsComplement(bdd.getCuddDdNode()), ddVariableIndices.size(), ddVariableIndices, uniqueTableForLevels);
std::shared_ptr<Odd<DdType::CUDD>> rootOdd = buildOddFromBddRec(Cudd_Regular(bdd.getCuddDdNode()), manager->internalDdManager.getCuddManager(), 0, Cudd_IsComplement(bdd.getCuddDdNode()), ddVariableIndices.size(), ddVariableIndices, uniqueTableForLevels);
// Finally, move the children of the root ODD into this ODD.
this->elseNode = std::move(rootOdd->elseNode);

44
src/storage/dd/cudd/InternalCuddAdd.cpp

@ -39,6 +39,7 @@ namespace storm {
template<typename ValueType>
InternalAdd<DdType::CUDD, ValueType>& InternalAdd<DdType::CUDD, ValueType>::operator|=(InternalAdd<DdType::CUDD, ValueType> const& other) {
this->cuddAdd = this->getCuddAdd() | other.getCuddAdd();
return *this;
}
template<typename ValueType>
@ -49,6 +50,7 @@ namespace storm {
template<typename ValueType>
InternalAdd<DdType::CUDD, ValueType>& InternalAdd<DdType::CUDD, ValueType>::operator+=(InternalAdd<DdType::CUDD, ValueType> const& other) {
this->cuddAdd = this->getCuddAdd() + other.getCuddAdd();
return *this;
}
template<typename ValueType>
@ -59,6 +61,7 @@ namespace storm {
template<typename ValueType>
InternalAdd<DdType::CUDD, ValueType>& InternalAdd<DdType::CUDD, ValueType>::operator*=(InternalAdd<DdType::CUDD, ValueType> const& other) {
this->cuddAdd = this->getCuddAdd() * other.getCuddAdd();
return *this;
}
template<typename ValueType>
@ -69,16 +72,18 @@ namespace storm {
template<typename ValueType>
InternalAdd<DdType::CUDD, ValueType>& InternalAdd<DdType::CUDD, ValueType>::operator-=(InternalAdd<DdType::CUDD, ValueType> const& other) {
this->cuddAdd = this->getCuddAdd() - other.getCuddAdd();
return *this;
}
template<typename ValueType>
InternalAdd<DdType::CUDD, ValueType> InternalAdd<DdType::CUDD, ValueType>::operator/(InternalAdd<DdType::CUDD, ValueType> const& other) const {
return InternalAdd<DdType::CUDD, ValueType>(ddManager, this->getCuddAdd() / other.getCuddAdd());
return InternalAdd<DdType::CUDD, ValueType>(ddManager, this->getCuddAdd().Divide(other.getCuddAdd()));
}
template<typename ValueType>
InternalAdd<DdType::CUDD, ValueType>& InternalAdd<DdType::CUDD, ValueType>::operator/=(InternalAdd<DdType::CUDD, ValueType> const& other) {
this->cuddAdd = this->getCuddAdd() / other.getCuddAdd();
this->cuddAdd = this->getCuddAdd().Divide(other.getCuddAdd());
return *this;
}
template<typename ValueType>
@ -148,17 +153,17 @@ namespace storm {
template<typename ValueType>
InternalAdd<DdType::CUDD, ValueType> InternalAdd<DdType::CUDD, ValueType>::sumAbstract(InternalBdd<DdType::CUDD> const& cube) const {
return InternalAdd<DdType::CUDD, ValueType>(ddManager, this->getCuddAdd().ExistAbstract(cube.getCuddBdd()));
return InternalAdd<DdType::CUDD, ValueType>(ddManager, this->getCuddAdd().ExistAbstract(cube.toAdd<ValueType>().getCuddAdd()));
}
template<typename ValueType>
InternalAdd<DdType::CUDD, ValueType> InternalAdd<DdType::CUDD, ValueType>::minAbstract(InternalBdd<DdType::CUDD> const& cube) const {
return InternalAdd<DdType::CUDD, ValueType>(ddManager, this->getCuddAdd().MinAbstract(cube.getCuddBdd()));
return InternalAdd<DdType::CUDD, ValueType>(ddManager, this->getCuddAdd().MinAbstract(cube.toAdd<ValueType>().getCuddAdd()));
}
template<typename ValueType>
InternalAdd<DdType::CUDD, ValueType> InternalAdd<DdType::CUDD, ValueType>::maxAbstract(InternalBdd<DdType::CUDD> const& cube) const {
return InternalAdd<DdType::CUDD, ValueType>(ddManager, this->getCuddAdd().MaxAbstract(cube.getCuddBdd()));
return InternalAdd<DdType::CUDD, ValueType>(ddManager, this->getCuddAdd().MaxAbstract(cube.toAdd<ValueType>().getCuddAdd()));
}
template<typename ValueType>
@ -178,7 +183,7 @@ namespace storm {
fromAdd.push_back(it1->getCuddAdd());
toAdd.push_back(it2->getCuddAdd());
}
return InternalBdd<DdType::CUDD>(ddManager, this->getCuddBdd().SwapVariables(fromAdd, toAdd));
return InternalAdd<DdType::CUDD, ValueType>(ddManager, this->getCuddAdd().SwapVariables(fromAdd, toAdd));
}
template<typename ValueType>
@ -186,7 +191,7 @@ namespace storm {
// Create the CUDD summation variables.
std::vector<ADD> summationAdds;
for (auto const& ddVariable : summationDdVariables) {
summationAdds.push_back(ddVariable.toAdd().getCuddAdd());
summationAdds.push_back(ddVariable.getCuddAdd());
}
return InternalAdd<DdType::CUDD, ValueType>(ddManager, this->getCuddAdd().MatrixMultiply(otherMatrix.getCuddAdd(), summationAdds));
@ -302,7 +307,7 @@ namespace storm {
// Open the file, dump the DD and close it again.
FILE* filePointer = fopen(filename.c_str() , "w");
std::vector<ADD> cuddAddVector = { this->getCuddAdd() };
this->getDdManager()->getCuddManager().DumpDot(cuddAddVector, &ddVariableNames[0], &ddNames[0], filePointer);
ddManager->getCuddManager().DumpDot(cuddAddVector, &ddVariableNames[0], &ddNames[0], filePointer);
fclose(filePointer);
// Finally, delete the names.
@ -315,16 +320,16 @@ namespace storm {
}
template<typename ValueType>
AddIterator<DdType::CUDD, ValueType> InternalAdd<DdType::CUDD, ValueType>::begin(std::set<storm::expressions::Variable> const& metaVariables, bool enumerateDontCareMetaVariables) const {
AddIterator<DdType::CUDD, ValueType> InternalAdd<DdType::CUDD, ValueType>::begin(std::shared_ptr<DdManager<DdType::CUDD> const> fullDdManager, std::set<storm::expressions::Variable> const& metaVariables, bool enumerateDontCareMetaVariables) const {
int* cube;
double value;
DdGen* generator = this->getCuddAdd().FirstCube(&cube, &value);
return AddIterator<DdType::CUDD, ValueType>(ddManager, generator, cube, value, (Cudd_IsGenEmpty(generator) != 0), &metaVariables, enumerateDontCareMetaVariables);
return AddIterator<DdType::CUDD, ValueType>(fullDdManager, generator, cube, value, (Cudd_IsGenEmpty(generator) != 0), &metaVariables, enumerateDontCareMetaVariables);
}
template<typename ValueType>
AddIterator<DdType::CUDD, ValueType> InternalAdd<DdType::CUDD, ValueType>::end(bool enumerateDontCareMetaVariables) const {
return AddIterator<DdType::CUDD, ValueType>(ddManager, nullptr, nullptr, 0, true, nullptr, enumerateDontCareMetaVariables);
AddIterator<DdType::CUDD, ValueType> InternalAdd<DdType::CUDD, ValueType>::end(std::shared_ptr<DdManager<DdType::CUDD> const> fullDdManager, bool enumerateDontCareMetaVariables) const {
return AddIterator<DdType::CUDD, ValueType>(fullDdManager, nullptr, nullptr, 0, true, nullptr, enumerateDontCareMetaVariables);
}
template<typename ValueType>
@ -404,10 +409,10 @@ namespace storm {
}
template<typename ValueType>
storm::storage::SparseMatrix<ValueType> InternalAdd<DdType::CUDD, ValueType>::toMatrix(storm::dd::Odd<DdType::CUDD> const& rowOdd, std::vector<uint_fast64_t> const& ddRowVariableIndices, storm::dd::Odd<DdType::CUDD> const& columnOdd, std::vector<uint_fast64_t> const& ddColumnVariableIndices) const {
storm::storage::SparseMatrix<ValueType> InternalAdd<DdType::CUDD, ValueType>::toMatrix(uint_fast64_t numberOfDdVariables, storm::dd::Odd<DdType::CUDD> const& rowOdd, std::vector<uint_fast64_t> const& ddRowVariableIndices, storm::dd::Odd<DdType::CUDD> const& columnOdd, std::vector<uint_fast64_t> const& ddColumnVariableIndices) const {
// Prepare the vectors that represent the matrix.
std::vector<uint_fast64_t> rowIndications(rowOdd.getTotalOffset() + 1);
std::vector<storm::storage::MatrixEntry<uint_fast64_t, double>> columnsAndValues(this->getNonZeroCount());
std::vector<storm::storage::MatrixEntry<uint_fast64_t, double>> columnsAndValues(this->getNonZeroCount(numberOfDdVariables));
// Create a trivial row grouping.
std::vector<uint_fast64_t> trivialRowGroupIndices(rowIndications.size());
@ -450,7 +455,7 @@ namespace storm {
template<typename ValueType>
void InternalAdd<DdType::CUDD, ValueType>::toMatrixRec(DdNode const* dd, std::vector<uint_fast64_t>& rowIndications, std::vector<storm::storage::MatrixEntry<uint_fast64_t, double>>& columnsAndValues, std::vector<uint_fast64_t> const& rowGroupOffsets, Odd<DdType::CUDD> const& rowOdd, Odd<DdType::CUDD> const& columnOdd, uint_fast64_t currentRowLevel, uint_fast64_t currentColumnLevel, uint_fast64_t maxLevel, uint_fast64_t currentRowOffset, uint_fast64_t currentColumnOffset, std::vector<uint_fast64_t> const& ddRowVariableIndices, std::vector<uint_fast64_t> const& ddColumnVariableIndices, bool generateValues) const {
// For the empty DD, we do not need to add any entries.
if (dd == Cudd_ReadZero(this->getDdManager()->getCuddManager().getManager())) {
if (dd == Cudd_ReadZero(ddManager->getCuddManager().getManager())) {
return;
}
@ -503,10 +508,9 @@ namespace storm {
template<typename ValueType>
storm::storage::SparseMatrix<ValueType> InternalAdd<DdType::CUDD, ValueType>::toMatrix(std::vector<uint_fast64_t> const& ddGroupVariableIndices, InternalBdd<DdType::CUDD> const& groupVariableCube, storm::dd::Odd<DdType::CUDD> const& rowOdd, std::vector<uint_fast64_t> const& ddRowVariableIndices, storm::dd::Odd<DdType::CUDD> const& columnOdd, std::vector<uint_fast64_t> const& ddColumnVariableIndices, InternalBdd<DdType::CUDD> const& columnVariableCube) const {
// Start by computing the offsets (in terms of rows) for each row group.
InternalAdd<DdType::CUDD, ValueType> stateToNumberOfChoices = this->notZero().existsAbstract(columnVariableCube).toAdd().sumAbstract(groupVariableCube);
std::vector<ValueType> rowGroupIndicesAsValueType = stateToNumberOfChoices.toVector(rowOdd);
std::vector<uint_fast64_t> rowGroupIndices(rowGroupIndicesAsValueType.size() + 1);
std::transform(rowGroupIndicesAsValueType.begin(), rowGroupIndicesAsValueType.end(), rowGroupIndices.begin(), [] (ValueType const& value) { return static_cast<uint_fast64_t>(value); });
InternalAdd<DdType::CUDD, uint_fast64_t> stateToNumberOfChoices = this->notZero().existsAbstract(columnVariableCube).template toAdd<uint_fast64_t>().sumAbstract(groupVariableCube);
std::vector<ValueType> rowGroupIndices = stateToNumberOfChoices.toVector(rowOdd);
rowGroupIndices.resize(rowGroupIndices.size() + 1);
uint_fast64_t tmp = 0;
uint_fast64_t tmp2 = 0;
for (uint_fast64_t i = 1; i < rowGroupIndices.size(); ++i) {
@ -540,7 +544,7 @@ namespace storm {
}
// Since we modified the rowGroupIndices, we need to restore the correct values.
std::function<uint_fast64_t (uint_fast64_t const&, double const&)> fct = [] (uint_fast64_t const& a, double const& b) -> uint_fast64_t { return a - static_cast<uint_fast64_t>(b); };
std::function<uint_fast64_t (uint_fast64_t const&, uint_fast64_t const&)> fct = [] (uint_fast64_t const& a, double const& b) -> uint_fast64_t { return a - static_cast<uint_fast64_t>(b); };
composeVectorRec(stateToRowGroupCount.getCuddDdNode(), 0, ddRowVariableIndices.size(), 0, rowOdd, ddRowVariableIndices, rowGroupIndices, fct);
// Now that we computed the number of entries in each row, compute the corresponding offsets in the entry vector.

9
src/storage/dd/cudd/InternalCuddAdd.h

@ -23,6 +23,9 @@ namespace storm {
}
namespace dd {
template<DdType LibraryType>
class DdManager;
template<DdType LibraryType>
class InternalDdManager;
@ -486,7 +489,7 @@ namespace storm {
* if a meta variable does not at all influence the the function value.
* @return An iterator that points to the first meta variable assignment with a non-zero function value.
*/
AddIterator<DdType::CUDD, ValueType> begin(std::set<storm::expressions::Variable> const& metaVariables, bool enumerateDontCareMetaVariables = true) const;
AddIterator<DdType::CUDD, ValueType> begin(std::shared_ptr<DdManager<DdType::CUDD> const> fullDdManager, std::set<storm::expressions::Variable> const& metaVariables, bool enumerateDontCareMetaVariables = true) const;
/*!
* Retrieves an iterator that points past the end of the container.
@ -495,7 +498,7 @@ namespace storm {
* if a meta variable does not at all influence the the function value.
* @return An iterator that points past the end of the container.
*/
AddIterator<DdType::CUDD, ValueType> end(bool enumerateDontCareMetaVariables = true) const;
AddIterator<DdType::CUDD, ValueType> end(std::shared_ptr<DdManager<DdType::CUDD> const> fullDdManager, bool enumerateDontCareMetaVariables = true) const;
/*!
* Converts the ADD to a vector. The given offset-labeled DD is used to determine the correct row of
@ -510,7 +513,7 @@ namespace storm {
void composeVector(storm::dd::Odd<DdType::CUDD> const& odd, std::vector<uint_fast64_t> const& ddVariableIndices, std::vector<ValueType>& targetVector, std::function<ValueType (ValueType const&, ValueType const&)> const& function) const;
storm::storage::SparseMatrix<ValueType> toMatrix(storm::dd::Odd<DdType::CUDD> const& rowOdd, std::vector<uint_fast64_t> const& ddRowVariableIndices, storm::dd::Odd<DdType::CUDD> const& columnOdd, std::vector<uint_fast64_t> const& ddColumnVariableIndices) const;
storm::storage::SparseMatrix<ValueType> toMatrix(uint_fast64_t numberOfDdVariables, storm::dd::Odd<DdType::CUDD> const& rowOdd, std::vector<uint_fast64_t> const& ddRowVariableIndices, storm::dd::Odd<DdType::CUDD> const& columnOdd, std::vector<uint_fast64_t> const& ddColumnVariableIndices) const;
storm::storage::SparseMatrix<ValueType> toMatrix(std::vector<uint_fast64_t> const& ddGroupVariableIndices, InternalBdd<DdType::CUDD> const& groupVariableCube, storm::dd::Odd<DdType::CUDD> const& rowOdd, std::vector<uint_fast64_t> const& ddRowVariableIndices, storm::dd::Odd<DdType::CUDD> const& columnOdd, std::vector<uint_fast64_t> const& ddColumnVariableIndices, InternalBdd<DdType::CUDD> const& columnVariableCube) const;

8
src/storage/dd/cudd/InternalCuddBdd.cpp

@ -1,6 +1,9 @@
#include "src/storage/dd/cudd/InternalCuddBdd.h"
#include "src/storage/dd/cudd/InternalCuddDdManager.h"
#include "src/storage/dd/cudd/CuddOdd.h"
#include "src/storage/BitVector.h"
namespace storm {
namespace dd {
@ -228,10 +231,9 @@ namespace storm {
}
}
storm::storage::BitVector InternalBdd<DdType::CUDD>::toVector(storm::dd::Odd<DdType::CUDD> const& rowOdd) const {
std::vector<uint_fast64_t> ddVariableIndices = this->getSortedVariableIndices();
storm::storage::BitVector InternalBdd<DdType::CUDD>::toVector(storm::dd::Odd<DdType::CUDD> const& rowOdd, std::vector<uint_fast64_t> const& ddVariableIndices) const {
storm::storage::BitVector result(rowOdd.getTotalOffset());
this->toVectorRec(this->getCuddDdNode(), this->getDdManager()->getCuddManager(), result, rowOdd, Cudd_IsComplement(this->getCuddDdNode()), 0, ddVariableIndices.size(), 0, ddVariableIndices);
this->toVectorRec(this->getCuddDdNode(), ddManager->getCuddManager(), result, rowOdd, Cudd_IsComplement(this->getCuddDdNode()), 0, ddVariableIndices.size(), 0, ddVariableIndices);
return result;
}

2
src/storage/dd/cudd/InternalCuddBdd.h

@ -288,7 +288,7 @@ namespace storm {
* @param rowOdd The ODD used for determining the correct row.
* @return The bit vector that is represented by this BDD.
*/
storm::storage::BitVector toVector(storm::dd::Odd<DdType::CUDD> const& rowOdd) const;
storm::storage::BitVector toVector(storm::dd::Odd<DdType::CUDD> const& rowOdd, std::vector<uint_fast64_t> const& ddVariableIndices) const;
private:
/*!

4
src/storage/dd/cudd/InternalCuddDdManager.h

@ -17,11 +17,15 @@ namespace storm {
template<DdType LibraryType>
class InternalBdd;
template<DdType LibraryType>
class Odd;
template<>
class InternalDdManager<DdType::CUDD> {
public:
friend class InternalAdd<DdType::CUDD, double>;
friend class InternalBdd<DdType::CUDD>;
friend class Odd<DdType::CUDD>;
/*!
* Creates a new internal manager for CUDD DDs.

Loading…
Cancel
Save