#include "src/storage/dd/sylvan/InternalSylvanBdd.h" #include "src/storage/dd/sylvan/InternalSylvanAdd.h" #include "src/storage/dd/sylvan/SylvanAddIterator.h" #include "src/storage/BitVector.h" #include "src/utility/macros.h" #include "src/exceptions/NotImplementedException.h" #include namespace storm { namespace dd { InternalBdd::InternalBdd(InternalDdManager const* ddManager, sylvan::Bdd const& sylvanBdd) : ddManager(ddManager), sylvanBdd(sylvanBdd) { // Intentionally left empty. } template InternalBdd InternalBdd::fromVector(InternalDdManager const* ddManager, std::vector const& values, Odd const& odd, std::vector const& sortedDdVariableIndices, std::function const& filter) { STORM_LOG_THROW(false, storm::exceptions::NotImplementedException, "Not yet implemented."); } bool InternalBdd::operator==(InternalBdd const& other) const { return sylvanBdd == other.sylvanBdd; } bool InternalBdd::operator!=(InternalBdd const& other) const { return sylvanBdd != other.sylvanBdd; } InternalBdd InternalBdd::relationalProduct(InternalBdd const& relation, std::vector> const& rowVariables) const { STORM_LOG_THROW(false, storm::exceptions::NotImplementedException, "Not yet implemented."); } InternalBdd InternalBdd::ite(InternalBdd const& thenDd, InternalBdd const& elseDd) const { return InternalBdd(ddManager, this->sylvanBdd.Ite(thenDd.sylvanBdd, elseDd.sylvanBdd)); } InternalBdd InternalBdd::operator||(InternalBdd const& other) const { return InternalBdd(ddManager, this->sylvanBdd | other.sylvanBdd); } InternalBdd& InternalBdd::operator|=(InternalBdd const& other) { this->sylvanBdd |= other.sylvanBdd; return *this; } InternalBdd InternalBdd::operator&&(InternalBdd const& other) const { return InternalBdd(ddManager, this->sylvanBdd & other.sylvanBdd); } InternalBdd& InternalBdd::operator&=(InternalBdd const& other) { this->sylvanBdd &= other.sylvanBdd; return *this; } InternalBdd InternalBdd::iff(InternalBdd const& other) const { return InternalBdd(ddManager, !(this->sylvanBdd ^ other.sylvanBdd)); } InternalBdd InternalBdd::exclusiveOr(InternalBdd const& other) const { return InternalBdd(ddManager, this->sylvanBdd ^ other.sylvanBdd); } InternalBdd InternalBdd::implies(InternalBdd const& other) const { return InternalBdd(ddManager, !this->sylvanBdd | other.sylvanBdd); } InternalBdd InternalBdd::operator!() const { return InternalBdd(ddManager, !this->sylvanBdd); } InternalBdd& InternalBdd::complement() { this->sylvanBdd = !this->sylvanBdd; return *this; } InternalBdd InternalBdd::existsAbstract(InternalBdd const& cube) const { return InternalBdd(ddManager, this->sylvanBdd.ExistAbstract(cube.sylvanBdd)); } InternalBdd InternalBdd::universalAbstract(InternalBdd const& cube) const { return InternalBdd(ddManager, this->sylvanBdd.UnivAbstract(cube.sylvanBdd)); } InternalBdd InternalBdd::andExists(InternalBdd const& other, InternalBdd const& cube) const { return InternalBdd(ddManager, this->sylvanBdd.AndAbstract(other.sylvanBdd, cube.sylvanBdd)); } InternalBdd InternalBdd::constrain(InternalBdd const& constraint) const { return InternalBdd(ddManager, this->sylvanBdd.Constrain(constraint.sylvanBdd)); } InternalBdd InternalBdd::restrict(InternalBdd const& constraint) const { return InternalBdd(ddManager, this->sylvanBdd.Restrict(constraint.sylvanBdd)); } InternalBdd InternalBdd::swapVariables(std::vector> const& from, std::vector> const& to) const { std::vector fromIndices; std::vector toIndices; for (auto it1 = from.begin(), ite1 = from.end(), it2 = to.begin(); it1 != ite1; ++it1, ++it2) { fromIndices.push_back(it1->getIndex()); fromIndices.push_back(it2->getIndex()); toIndices.push_back(it2->getIndex()); toIndices.push_back(it1->getIndex()); } return InternalBdd(ddManager, this->sylvanBdd.Permute(fromIndices, toIndices)); } InternalBdd InternalBdd::getSupport() const { return InternalBdd(ddManager, this->sylvanBdd.Support()); } uint_fast64_t InternalBdd::getNonZeroCount(uint_fast64_t numberOfDdVariables) const { if (numberOfDdVariables == 0) { return 0; } return static_cast(this->sylvanBdd.SatCount(numberOfDdVariables)); } uint_fast64_t InternalBdd::getLeafCount() const { // For BDDs, the leaf count is always one, because the only leaf is the false leaf (and true is represented // by a negation edge to false). return 1; } uint_fast64_t InternalBdd::getNodeCount() const { // We have to add one to also count the false-leaf, which is the only leaf appearing in BDDs. return static_cast(this->sylvanBdd.NodeCount()) + 1; } bool InternalBdd::isOne() const { return this->sylvanBdd.isOne(); } bool InternalBdd::isZero() const { return this->sylvanBdd.isZero(); } uint_fast64_t InternalBdd::getIndex() const { return static_cast(this->sylvanBdd.TopVar()); } void InternalBdd::exportToDot(std::string const& filename, std::vector const& ddVariableNamesAsStrings) const { FILE* filePointer = fopen(filename.c_str() , "w"); this->sylvanBdd.PrintDot(filePointer); fclose(filePointer); } sylvan::Bdd& InternalBdd::getSylvanBdd() { return sylvanBdd; } sylvan::Bdd const& InternalBdd::getSylvanBdd() const { return sylvanBdd; } template InternalAdd InternalBdd::toAdd() const { return InternalAdd(ddManager, this->sylvanBdd.toDoubleMtbdd()); } storm::storage::BitVector InternalBdd::toVector(storm::dd::Odd const& rowOdd, std::vector const& ddVariableIndices) const { STORM_LOG_THROW(false, storm::exceptions::NotImplementedException, "Not yet implemented."); } Odd InternalBdd::createOdd(std::vector const& ddVariableIndices) const { STORM_LOG_THROW(false, storm::exceptions::NotImplementedException, "Not yet implemented."); } template void InternalBdd::filterExplicitVector(Odd const& odd, std::vector const& ddVariableIndices, std::vector const& sourceValues, std::vector& targetValues) const { STORM_LOG_THROW(false, storm::exceptions::NotImplementedException, "Not yet implemented."); } template InternalBdd InternalBdd::fromVector(InternalDdManager const* ddManager, std::vector const& values, Odd const& odd, std::vector const& sortedDdVariableIndices, std::function const& filter); template InternalBdd InternalBdd::fromVector(InternalDdManager const* ddManager, std::vector const& values, Odd const& odd, std::vector const& sortedDdVariableIndices, std::function const& filter); template InternalAdd InternalBdd::toAdd() const; template InternalAdd InternalBdd::toAdd() const; template void InternalBdd::filterExplicitVector(Odd const& odd, std::vector const& ddVariableIndices, std::vector const& sourceValues, std::vector& targetValues) const; template void InternalBdd::filterExplicitVector(Odd const& odd, std::vector const& ddVariableIndices, std::vector const& sourceValues, std::vector& targetValues) const; } }