Browse Source

Added matrix-matrix multiplication to DD interface. (This includes matrix-vector multiplication as a special case).

Former-commit-id: d5d8fef738
tempestpy_adaptions
dehnert 11 years ago
parent
commit
cb35b3315d
  1. 54
      src/storage/dd/CuddDd.cpp
  2. 31
      src/storage/dd/CuddDd.h
  3. 4
      src/storage/dd/CuddDdManager.cpp
  4. 3
      src/storage/dd/CuddDdManager.h

54
src/storage/dd/CuddDd.cpp

@ -5,7 +5,7 @@
namespace storm {
namespace dd {
Dd<CUDD>::Dd(std::shared_ptr<DdManager<CUDD>> ddManager, ADD cuddAdd, std::unordered_set<std::string> const& containedMetaVariableNames) noexcept : ddManager(ddManager), cuddAdd(cuddAdd), containedMetaVariableNames(containedMetaVariableNames) {
Dd<CUDD>::Dd(std::shared_ptr<DdManager<CUDD>> ddManager, ADD cuddAdd, std::set<std::string> const& containedMetaVariableNames) noexcept : ddManager(ddManager), cuddAdd(cuddAdd), containedMetaVariableNames(containedMetaVariableNames) {
// Intentionally left empty.
}
@ -23,7 +23,7 @@ namespace storm {
this->getCuddAdd() += other.getCuddAdd();
// Join the variable sets of the two participating DDs.
std::copy(other.getContainedMetaVariableNames().begin(), other.getContainedMetaVariableNames().end(), std::inserter(this->containedMetaVariableNames, this->containedMetaVariableNames.end()));
this->getContainedMetaVariableNames().insert(other.getContainedMetaVariableNames().begin(), other.getContainedMetaVariableNames().end());
return *this;
}
@ -38,7 +38,7 @@ namespace storm {
this->getCuddAdd() *= other.getCuddAdd();
// Join the variable sets of the two participating DDs.
std::copy(other.getContainedMetaVariableNames().begin(), other.getContainedMetaVariableNames().end(), std::inserter(this->containedMetaVariableNames, this->containedMetaVariableNames.end()));
this->getContainedMetaVariableNames().insert(other.getContainedMetaVariableNames().begin(), other.getContainedMetaVariableNames().end());
return *this;
}
@ -53,7 +53,7 @@ namespace storm {
this->getCuddAdd() -= other.getCuddAdd();
// Join the variable sets of the two participating DDs.
std::copy(other.getContainedMetaVariableNames().begin(), other.getContainedMetaVariableNames().end(), std::inserter(this->containedMetaVariableNames, this->containedMetaVariableNames.end()));
this->getContainedMetaVariableNames().insert(other.getContainedMetaVariableNames().begin(), other.getContainedMetaVariableNames().end());
return *this;
}
@ -68,7 +68,7 @@ namespace storm {
this->getCuddAdd().Divide(other.getCuddAdd());
// Join the variable sets of the two participating DDs.
std::copy(other.getContainedMetaVariableNames().begin(), other.getContainedMetaVariableNames().end(), std::inserter(this->containedMetaVariableNames, this->containedMetaVariableNames.end()));
this->getContainedMetaVariableNames().insert(other.getContainedMetaVariableNames().begin(), other.getContainedMetaVariableNames().end());
return *this;
}
@ -120,7 +120,7 @@ namespace storm {
return result;
}
void Dd<CUDD>::existsAbstract(std::unordered_set<std::string> const& metaVariableNames) {
void Dd<CUDD>::existsAbstract(std::set<std::string> const& metaVariableNames) {
Dd<CUDD> cubeDd(this->getDdManager()->getOne());
for (auto const& metaVariableName : metaVariableNames) {
@ -137,7 +137,7 @@ namespace storm {
this->getCuddAdd().OrAbstract(cubeDd.getCuddAdd());
}
void Dd<CUDD>::sumAbstract(std::unordered_set<std::string> const& metaVariableNames) {
void Dd<CUDD>::sumAbstract(std::set<std::string> const& metaVariableNames) {
Dd<CUDD> cubeDd(this->getDdManager()->getOne());
for (auto const& metaVariableName : metaVariableNames) {
@ -154,7 +154,7 @@ namespace storm {
this->getCuddAdd().ExistAbstract(cubeDd.getCuddAdd());
}
void Dd<CUDD>::minAbstract(std::unordered_set<std::string> const& metaVariableNames) {
void Dd<CUDD>::minAbstract(std::set<std::string> const& metaVariableNames) {
Dd<CUDD> cubeDd(this->getDdManager()->getOne());
for (auto const& metaVariableName : metaVariableNames) {
@ -171,7 +171,7 @@ namespace storm {
this->getCuddAdd().Minimum(cubeDd.getCuddAdd());
}
void Dd<CUDD>::maxAbstract(std::unordered_set<std::string> const& metaVariableNames) {
void Dd<CUDD>::maxAbstract(std::set<std::string> const& metaVariableNames) {
Dd<CUDD> cubeDd(this->getDdManager()->getOne());
for (auto const& metaVariableName : metaVariableNames) {
@ -210,11 +210,39 @@ namespace storm {
this->removeContainedMetaVariable(metaVariablePair.second);
this->addContainedMetaVariable(metaVariablePair.first);
}
// Add the variables to swap to the corresponding vectors.
for (auto const& ddVariable : variable1.getDdVariables()) {
from.push_back(ddVariable.getCuddAdd());
}
for (auto const& ddVariable : variable2.getDdVariables()) {
to.push_back(ddVariable.getCuddAdd());
}
}
// FIXME: complete this and add matrix-matrix multiplication.
// Finally, call CUDD to swap the variables.
this->getCuddAdd().SwapVariables(from, to);
}
Dd<CUDD> Dd<CUDD>::multiplyMatrix(Dd<CUDD> const& otherMatrix, std::set<std::string> const& summationMetaVariableNames) {
std::vector<ADD> summationDdVariables;
// Create the CUDD summation variables.
for (auto const& metaVariableName : summationMetaVariableNames) {
for (auto const& ddVariable : this->getDdManager()->getMetaVariable(metaVariableName).getDdVariables()) {
summationDdVariables.push_back(ddVariable.getCuddAdd());
}
}
std::set<std::string> unionOfMetaVariableNames;
std::set_union(this->getContainedMetaVariableNames().begin(), this->getContainedMetaVariableNames().end(), otherMatrix.getContainedMetaVariableNames().begin(), otherMatrix.getContainedMetaVariableNames().end(), std::inserter(unionOfMetaVariableNames, unionOfMetaVariableNames.begin()));
std::set<std::string> containedMetaVariableNames;
std::set_difference(unionOfMetaVariableNames.begin(), unionOfMetaVariableNames.end(), summationMetaVariableNames.begin(), summationMetaVariableNames.end(), std::inserter(containedMetaVariableNames, containedMetaVariableNames.begin()));
return Dd<CUDD>(this->getDdManager(), this->getCuddAdd().MatrixMultiply(otherMatrix.getCuddAdd(), summationDdVariables), containedMetaVariableNames);
}
uint_fast64_t Dd<CUDD>::getNonZeroCount() const {
std::size_t numberOfDdVariables = 0;
for (auto const& metaVariableName : this->containedMetaVariableNames) {
@ -276,7 +304,7 @@ namespace storm {
return metaVariable != containedMetaVariableNames.end();
}
bool Dd<CUDD>::containsMetaVariables(std::unordered_set<std::string> metaVariableNames) const {
bool Dd<CUDD>::containsMetaVariables(std::set<std::string> metaVariableNames) const {
for (auto const& metaVariableName : metaVariableNames) {
auto const& metaVariable = containedMetaVariableNames.find(metaVariableName);
@ -287,11 +315,11 @@ namespace storm {
return true;
}
std::unordered_set<std::string> const& Dd<CUDD>::getContainedMetaVariableNames() const {
std::set<std::string> const& Dd<CUDD>::getContainedMetaVariableNames() const {
return this->containedMetaVariableNames;
}
std::unordered_set<std::string>& Dd<CUDD>::getContainedMetaVariableNames() {
std::set<std::string>& Dd<CUDD>::getContainedMetaVariableNames() {
return this->containedMetaVariableNames;
}

31
src/storage/dd/CuddDd.h

@ -1,8 +1,8 @@
#ifndef STORM_STORAGE_DD_CUDDDD_H_
#define STORM_STORAGE_DD_CUDDDD_H_
#include <unordered_set>
#include <unordered_map>
#include <set>
#include <memory>
#include "src/storage/dd/Dd.h"
@ -179,28 +179,28 @@ namespace storm {
*
* @param metaVariableNames The names of all meta variables from which to abstract.
*/
void existsAbstract(std::unordered_set<std::string> const& metaVariableNames);
void existsAbstract(std::set<std::string> const& metaVariableNames);
/*!
* Sum-abstracts from the given meta variables.
*
* @param metaVariableNames The names of all meta variables from which to abstract.
*/
void sumAbstract(std::unordered_set<std::string> const& metaVariableNames);
void sumAbstract(std::set<std::string> const& metaVariableNames);
/*!
* Min-abstracts from the given meta variables.
*
* @param metaVariableNames The names of all meta variables from which to abstract.
*/
void minAbstract(std::unordered_set<std::string> const& metaVariableNames);
void minAbstract(std::set<std::string> const& metaVariableNames);
/*!
* Max-abstracts from the given meta variables.
*
* @param metaVariableNames The names of all meta variables from which to abstract.
*/
void maxAbstract(std::unordered_set<std::string> const& metaVariableNames);
void maxAbstract(std::set<std::string> const& metaVariableNames);
/*!
* Swaps the given pairs of meta variables in the DD. The pairs of meta variables must be guaranteed to have
@ -210,6 +210,17 @@ namespace storm {
*/
void swapVariables(std::vector<std::pair<std::string, std::string>> const& metaVariablePairs);
/*!
* Multiplies the current DD (representing a matrix) with the given matrix by summing over the given meta
* variables.
*
* @param otherMatrix The matrix with which to multiply.
* @param summationMetaVariableNames The names of the meta variables over which to sum during the matrix-
* matrix multiplication.
* @return A DD representing the result of the matrix-matrix multiplication.
*/
Dd<CUDD> multiplyMatrix(Dd<CUDD> const& otherMatrix, std::set<std::string> const& summationMetaVariableNames);
/*!
* Retrieves the number of encodings that are mapped to a non-zero value.
*
@ -310,21 +321,21 @@ namespace storm {
* @param metaVariableNames The names of the meta variable for which to query membership.
* @return True iff all meta variables are contained in the DD.
*/
bool containsMetaVariables(std::unordered_set<std::string> metaVariableNames) const;
bool containsMetaVariables(std::set<std::string> metaVariableNames) const;
/*!
* Retrieves the set of all names of meta variables contained in the DD.
*
* @return The set of names of all meta variables contained in the DD.
*/
std::unordered_set<std::string> const& getContainedMetaVariableNames() const;
std::set<std::string> const& getContainedMetaVariableNames() const;
/*!
* Retrieves the set of all names of meta variables contained in the DD.
*
* @return The set of names of all meta variables contained in the DD.
*/
std::unordered_set<std::string>& getContainedMetaVariableNames();
std::set<std::string>& getContainedMetaVariableNames();
/*!
* Exports the DD to the given file in the dot format.
@ -376,7 +387,7 @@ namespace storm {
* @param cuddAdd The CUDD ADD to store.
* @param
*/
Dd(std::shared_ptr<DdManager<CUDD>> ddManager, ADD cuddAdd, std::unordered_set<std::string> const& containedMetaVariableNames) noexcept;
Dd(std::shared_ptr<DdManager<CUDD>> ddManager, ADD cuddAdd, std::set<std::string> const& containedMetaVariableNames) noexcept;
// A pointer to the manager responsible for this DD.
std::shared_ptr<DdManager<CUDD>> ddManager;
@ -385,7 +396,7 @@ namespace storm {
ADD cuddAdd;
// The names of all meta variables that appear in this DD.
std::unordered_set<std::string> containedMetaVariableNames;
std::set<std::string> containedMetaVariableNames;
};
}
}

4
src/storage/dd/CuddDdManager.cpp

@ -97,8 +97,8 @@ namespace storm {
return nameVariablePair->second;
}
std::unordered_set<std::string> DdManager<CUDD>::getAllMetaVariableNames() const {
std::unordered_set<std::string> result;
std::set<std::string> DdManager<CUDD>::getAllMetaVariableNames() const {
std::set<std::string> result;
for (auto const& nameValuePair : metaVariableMap) {
result.insert(nameValuePair.first);
}

3
src/storage/dd/CuddDdManager.h

@ -1,7 +1,6 @@
#ifndef STORM_STORAGE_DD_CUDDDDMANAGER_H_
#define STORM_STORAGE_DD_CUDDDDMANAGER_H_
#include <unordered_set>
#include <unordered_map>
#include "src/storage/dd/DdManager.h"
@ -102,7 +101,7 @@ namespace storm {
*
* @return The set of all meta variable names of the manager.
*/
std::unordered_set<std::string> getAllMetaVariableNames() const;
std::set<std::string> getAllMetaVariableNames() const;
private:
/*!

Loading…
Cancel
Save