Browse Source
more work on refactoring DD abstraction layer
more work on refactoring DD abstraction layer
Former-commit-id: 4dc4260798
tempestpy_adaptions
dehnert
9 years ago
14 changed files with 115 additions and 493 deletions
-
20src/storage/dd/Add.h
-
25src/storage/dd/Bdd.cpp
-
2src/storage/dd/DdManager.cpp
-
4src/storage/dd/DdManager.h
-
5src/storage/dd/DdMetaVariable.h
-
1src/storage/dd/Odd.cpp
-
4src/storage/dd/Odd.h
-
52src/storage/dd/cudd/CuddDdManager.cpp
-
217src/storage/dd/cudd/CuddDdManager.h
-
52src/storage/dd/cudd/CuddDdMetaVariable.cpp
-
144src/storage/dd/cudd/CuddDdMetaVariable.h
-
60src/storage/dd/cudd/InternalCuddAdd.h
-
18src/storage/dd/cudd/InternalCuddBdd.cpp
-
4src/storage/dd/cudd/InternalCuddBdd.h
@ -0,0 +1 @@ |
|||
#include "src/storage/dd/Odd.h"
|
@ -1,52 +0,0 @@ |
|||
#include <cmath>
|
|||
#include <string>
|
|||
#include <algorithm>
|
|||
|
|||
#include "src/storage/dd/cudd/CuddDdManager.h"
|
|||
#include "src/utility/macros.h"
|
|||
#include "src/storage/expressions/Variable.h"
|
|||
#include "src/exceptions/InvalidArgumentException.h"
|
|||
#include "src/settings/SettingsManager.h"
|
|||
#include "src/settings/modules/CuddSettings.h"
|
|||
#include "src/storage/expressions/ExpressionManager.h"
|
|||
#include "src/storage/dd/cudd/CuddAdd.h"
|
|||
#include "CuddBdd.h"
|
|||
|
|||
|
|||
namespace storm { |
|||
namespace dd { |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
void DdManager<DdType::CUDD>::allowDynamicReordering(bool value) { |
|||
if (value) { |
|||
this->getCuddManager().AutodynEnable(this->reorderingTechnique); |
|||
} else { |
|||
this->getCuddManager().AutodynDisable(); |
|||
} |
|||
} |
|||
|
|||
bool DdManager<DdType::CUDD>::isDynamicReorderingAllowed() const { |
|||
Cudd_ReorderingType type; |
|||
return this->getCuddManager().ReorderingStatus(&type); |
|||
} |
|||
|
|||
void DdManager<DdType::CUDD>::triggerReordering() { |
|||
this->getCuddManager().ReduceHeap(this->reorderingTechnique, 0); |
|||
} |
|||
|
|||
std::shared_ptr<DdManager<DdType::CUDD> const> DdManager<DdType::CUDD>::asSharedPointer() const { |
|||
return this->shared_from_this(); |
|||
} |
|||
} |
|||
} |
@ -1,217 +0,0 @@ |
|||
#ifndef STORM_STORAGE_DD_CUDDDDMANAGER_H_ |
|||
#define STORM_STORAGE_DD_CUDDDDMANAGER_H_ |
|||
|
|||
#include <unordered_map> |
|||
#include <memory> |
|||
|
|||
#include "src/storage/dd/DdManager.h" |
|||
#include "src/storage/dd/cudd/CuddDdMetaVariable.h" |
|||
#include "src/utility/OsDetection.h" |
|||
|
|||
// Include the C++-interface of CUDD. |
|||
#include "cuddObj.hh" |
|||
|
|||
namespace storm { |
|||
namespace expressions { |
|||
class Variable; |
|||
} |
|||
} |
|||
|
|||
namespace storm { |
|||
namespace dd { |
|||
template<> |
|||
class DdManager<DdType::CUDD> : public std::enable_shared_from_this<DdManager<DdType::CUDD>> { |
|||
public: |
|||
friend class Bdd<DdType::CUDD>; |
|||
friend class Add<DdType::CUDD>; |
|||
friend class Odd<DdType::CUDD>; |
|||
friend class DdForwardIterator<DdType::CUDD>; |
|||
|
|||
/*! |
|||
* Creates an empty manager without any meta variables. |
|||
*/ |
|||
DdManager(); |
|||
|
|||
// Explictly forbid copying a DdManager, but allow moving it. |
|||
DdManager(DdManager<DdType::CUDD> const& other) = delete; |
|||
DdManager<DdType::CUDD>& operator=(DdManager<DdType::CUDD> const& other) = delete; |
|||
#ifndef WINDOWS |
|||
DdManager(DdManager<DdType::CUDD>&& other) = default; |
|||
DdManager<DdType::CUDD>& operator=(DdManager<DdType::CUDD>&& other) = default; |
|||
#endif |
|||
|
|||
/*! |
|||
* Retrieves a BDD representing the constant one function. |
|||
* |
|||
* @return A BDD representing the constant one function. |
|||
*/ |
|||
Bdd<DdType::CUDD> getBddOne() const; |
|||
|
|||
/*! |
|||
* Retrieves an ADD representing the constant one function. |
|||
* |
|||
* @return An ADD representing the constant one function. |
|||
*/ |
|||
Add<DdType::CUDD> getAddOne() const; |
|||
|
|||
/*! |
|||
* Retrieves a BDD representing the constant zero function. |
|||
* |
|||
* @return A BDD representing the constant zero function. |
|||
*/ |
|||
Bdd<DdType::CUDD> getBddZero() const; |
|||
|
|||
/*! |
|||
* Retrieves an ADD representing the constant zero function. |
|||
* |
|||
* @return An ADD representing the constant zero function. |
|||
*/ |
|||
Add<DdType::CUDD> getAddZero() const; |
|||
|
|||
/*! |
|||
* Retrieves an ADD representing the constant function with the given value. |
|||
* |
|||
* @return An ADD representing the constant function with the given value. |
|||
*/ |
|||
Add<DdType::CUDD> getConstant(double value) const; |
|||
|
|||
/*! |
|||
* Retrieves the BDD representing the function that maps all inputs which have the given meta variable equal |
|||
* to the given value one. |
|||
* |
|||
* @param variable The expression variable associated with the meta variable. |
|||
* @param value The value the meta variable is supposed to have. |
|||
* @return The DD representing the function that maps all inputs which have the given meta variable equal |
|||
* to the given value one. |
|||
*/ |
|||
Bdd<DdType::CUDD> getEncoding(storm::expressions::Variable const& variable, int_fast64_t value) const; |
|||
|
|||
/*! |
|||
* Retrieves the BDD representing the range of the meta variable, i.e., a function that maps all legal values |
|||
* of the range of the meta variable to one. |
|||
* |
|||
* @param variable The expression variable associated with the meta variable. |
|||
* @return The range of the meta variable. |
|||
*/ |
|||
Bdd<DdType::CUDD> getRange(storm::expressions::Variable const& variable) const; |
|||
|
|||
/*! |
|||
* Retrieves the ADD representing the identity of the meta variable, i.e., a function that maps all legal |
|||
* values of the range of the meta variable to themselves. |
|||
* |
|||
* @param variable The expression variable associated with the meta variable. |
|||
* @return The identity of the meta variable. |
|||
*/ |
|||
Add<DdType::CUDD> getIdentity(storm::expressions::Variable const& variable) const; |
|||
|
|||
/*! |
|||
* Adds an integer meta variable with the given range. |
|||
* |
|||
* @param variableName The name of the new variable. |
|||
* @param low The lowest value of the range of the variable. |
|||
* @param high The highest value of the range of the variable. |
|||
*/ |
|||
std::pair<storm::expressions::Variable, storm::expressions::Variable> addMetaVariable(std::string const& variableName, int_fast64_t low, int_fast64_t high); |
|||
|
|||
/*! |
|||
* Adds a boolean meta variable. |
|||
* |
|||
* @param variableName The name of the new variable. |
|||
*/ |
|||
std::pair<storm::expressions::Variable, storm::expressions::Variable> addMetaVariable(std::string const& variableName); |
|||
|
|||
/*! |
|||
* Retrieves the names of all meta variables that have been added to the manager. |
|||
* |
|||
* @return The set of all meta variable names of the manager. |
|||
*/ |
|||
std::set<std::string> getAllMetaVariableNames() const; |
|||
|
|||
/*! |
|||
* Retrieves the number of meta variables that are contained in this manager. |
|||
* |
|||
* @return The number of meta variables contained in this manager. |
|||
*/ |
|||
std::size_t getNumberOfMetaVariables() const; |
|||
|
|||
/*! |
|||
* Retrieves whether the given meta variable name is already in use. |
|||
* |
|||
* @param variableName The name of the variable. |
|||
* @return True if the given meta variable name is managed by this manager. |
|||
*/ |
|||
bool hasMetaVariable(std::string const& variableName) const; |
|||
|
|||
/*! |
|||
* Sets whether or not dynamic reordering is allowed for the DDs managed by this manager. |
|||
* |
|||
* @param value If set to true, dynamic reordering is allowed and forbidden otherwise. |
|||
*/ |
|||
void allowDynamicReordering(bool value); |
|||
|
|||
/*! |
|||
* Retrieves whether dynamic reordering is currently allowed. |
|||
* |
|||
* @return True iff dynamic reordering is currently allowed. |
|||
*/ |
|||
bool isDynamicReorderingAllowed() const; |
|||
|
|||
/*! |
|||
* Triggers a reordering of the DDs managed by this manager. |
|||
*/ |
|||
void triggerReordering(); |
|||
|
|||
/*! |
|||
* Retrieves the meta variable with the given name if it exists. |
|||
* |
|||
* @param variable The expression variable associated with the meta variable. |
|||
* @return The corresponding meta variable. |
|||
*/ |
|||
DdMetaVariable<DdType::CUDD> const& getMetaVariable(storm::expressions::Variable const& variable) const; |
|||
|
|||
/*! |
|||
* Retrieves the manager as a shared pointer. |
|||
* |
|||
* @return A shared pointer to the manager. |
|||
*/ |
|||
std::shared_ptr<DdManager<DdType::CUDD> const> asSharedPointer() const; |
|||
|
|||
private: |
|||
/*! |
|||
* Retrieves a list of names of the DD variables in the order of their index. |
|||
* |
|||
* @return A list of DD variable names. |
|||
*/ |
|||
std::vector<std::string> getDdVariableNames() const; |
|||
|
|||
/*! |
|||
* Retrieves a list of expression variables in the order of their index. |
|||
* |
|||
* @return A list of DD variables. |
|||
*/ |
|||
std::vector<storm::expressions::Variable> getDdVariables() const; |
|||
|
|||
/*! |
|||
* Retrieves the underlying expression manager. |
|||
* |
|||
* @return The underlying expression manager. |
|||
*/ |
|||
storm::expressions::ExpressionManager const& getExpressionManager() const; |
|||
|
|||
/*! |
|||
* Retrieves the underlying expression manager. |
|||
* |
|||
* @return The underlying expression manager. |
|||
*/ |
|||
storm::expressions::ExpressionManager& getExpressionManager(); |
|||
|
|||
// A mapping from variables to the meta variable information. |
|||
std::unordered_map<storm::expressions::Variable, DdMetaVariable<DdType::CUDD>> metaVariableMap; |
|||
|
|||
// The manager responsible for the variables. |
|||
std::shared_ptr<storm::expressions::ExpressionManager> manager; |
|||
}; |
|||
} |
|||
} |
|||
|
|||
#endif /* STORM_STORAGE_DD_CUDDDDMANAGER_H_ */ |
@ -1,52 +0,0 @@ |
|||
#include "src/storage/dd/cudd/CuddDdMetaVariable.h"
|
|||
#include "src/storage/dd/cudd/CuddDdManager.h"
|
|||
|
|||
namespace storm { |
|||
namespace dd { |
|||
DdMetaVariable<DdType::CUDD>::DdMetaVariable(std::string const& name, int_fast64_t low, int_fast64_t high, std::vector<Bdd<DdType::CUDD>> const& ddVariables, std::shared_ptr<DdManager<DdType::CUDD>> manager) : name(name), type(MetaVariableType::Int), low(low), high(high), ddVariables(ddVariables), cube(manager->getBddOne()), manager(manager) { |
|||
// Create the cube of all variables of this meta variable.
|
|||
for (auto const& ddVariable : this->ddVariables) { |
|||
this->cube &= ddVariable; |
|||
} |
|||
} |
|||
|
|||
DdMetaVariable<DdType::CUDD>::DdMetaVariable(std::string const& name, std::vector<Bdd<DdType::CUDD>> const& ddVariables, std::shared_ptr<DdManager<DdType::CUDD>> manager) : name(name), type(MetaVariableType::Bool), low(0), high(1), ddVariables(ddVariables), cube(manager->getBddOne()), manager(manager) { |
|||
// Create the cube of all variables of this meta variable.
|
|||
for (auto const& ddVariable : this->ddVariables) { |
|||
this->cube &= ddVariable; |
|||
} |
|||
} |
|||
|
|||
std::string const& DdMetaVariable<DdType::CUDD>::getName() const { |
|||
return this->name; |
|||
} |
|||
|
|||
DdMetaVariable<DdType::CUDD>::MetaVariableType DdMetaVariable<DdType::CUDD>::getType() const { |
|||
return this->type; |
|||
} |
|||
|
|||
int_fast64_t DdMetaVariable<DdType::CUDD>::getLow() const { |
|||
return this->low; |
|||
} |
|||
|
|||
int_fast64_t DdMetaVariable<DdType::CUDD>::getHigh() const { |
|||
return this->high; |
|||
} |
|||
|
|||
std::size_t DdMetaVariable<DdType::CUDD>::getNumberOfDdVariables() const { |
|||
return this->ddVariables.size(); |
|||
} |
|||
|
|||
std::shared_ptr<DdManager<DdType::CUDD>> DdMetaVariable<DdType::CUDD>::getDdManager() const { |
|||
return this->manager; |
|||
} |
|||
|
|||
std::vector<Bdd<DdType::CUDD>> const& DdMetaVariable<DdType::CUDD>::getDdVariables() const { |
|||
return this->ddVariables; |
|||
} |
|||
|
|||
Bdd<DdType::CUDD> const& DdMetaVariable<DdType::CUDD>::getCube() const { |
|||
return this->cube; |
|||
} |
|||
} |
|||
} |
@ -1,144 +0,0 @@ |
|||
#ifndef STORM_STORAGE_DD_DDMETAVARIABLE_H_ |
|||
#define STORM_STORAGE_DD_DDMETAVARIABLE_H_ |
|||
|
|||
#include <memory> |
|||
#include <vector> |
|||
#include <cstdint> |
|||
#include <string> |
|||
|
|||
#include "utility/OsDetection.h" |
|||
#include "src/storage/dd/cudd/CuddBdd.h" |
|||
#include "src/storage/dd/DdMetaVariable.h" |
|||
#include "src/storage/dd/cudd/CuddDdForwardIterator.h" |
|||
|
|||
|
|||
namespace storm { |
|||
namespace dd { |
|||
// Forward-declare some classes. |
|||
template<DdType Type> class DdManager; |
|||
template<DdType Type> class Odd; |
|||
template<DdType Type> class Add; |
|||
|
|||
template<> |
|||
class DdMetaVariable<DdType::CUDD> { |
|||
public: |
|||
// Declare the DdManager class as friend so it can access the internals of a meta variable. |
|||
friend class DdManager<DdType::CUDD>; |
|||
friend class Dd<DdType::CUDD>; |
|||
friend class Bdd<DdType::CUDD>; |
|||
friend class Add<DdType::CUDD>; |
|||
friend class Odd<DdType::CUDD>; |
|||
friend class DdForwardIterator<DdType::CUDD>; |
|||
|
|||
// An enumeration for all legal types of meta variables. |
|||
enum class MetaVariableType { Bool, Int }; |
|||
|
|||
/*! |
|||
* Creates an integer meta variable with the given name and range bounds. |
|||
* |
|||
* @param name The name of the meta variable. |
|||
* @param low The lowest value of the range of the variable. |
|||
* @param high The highest value of the range of the variable. |
|||
* @param ddVariables The vector of variables used to encode this variable. |
|||
* @param manager A pointer to the manager that is responsible for this meta variable. |
|||
*/ |
|||
DdMetaVariable(std::string const& name, int_fast64_t low, int_fast64_t high, std::vector<Bdd<DdType::CUDD>> const& ddVariables, std::shared_ptr<DdManager<DdType::CUDD>> manager); |
|||
|
|||
/*! |
|||
* Creates a boolean meta variable with the given name. |
|||
* @param name The name of the meta variable. |
|||
* @param ddVariables The vector of variables used to encode this variable. |
|||
* @param manager A pointer to the manager that is responsible for this meta variable. |
|||
*/ |
|||
DdMetaVariable(std::string const& name, std::vector<Bdd<DdType::CUDD>> const& ddVariables, std::shared_ptr<DdManager<DdType::CUDD>> manager); |
|||
|
|||
// Explictly generate all default versions of copy/move constructors/assignments. |
|||
DdMetaVariable(DdMetaVariable const& other) = default; |
|||
DdMetaVariable& operator=(DdMetaVariable const& other) = default; |
|||
#ifndef WINDOWS |
|||
DdMetaVariable(DdMetaVariable&& other) = default; |
|||
DdMetaVariable& operator=(DdMetaVariable&& other) = default; |
|||
#endif |
|||
|
|||
/*! |
|||
* Retrieves the name of the meta variable. |
|||
* |
|||
* @return The name of the variable. |
|||
*/ |
|||
std::string const& getName() const; |
|||
|
|||
/*! |
|||
* Retrieves the type of the meta variable. |
|||
* |
|||
* @return The type of the meta variable. |
|||
*/ |
|||
MetaVariableType getType() const; |
|||
|
|||
/*! |
|||
* Retrieves the lowest value of the range of the variable. |
|||
* |
|||
* @return The lowest value of the range of the variable. |
|||
*/ |
|||
int_fast64_t getLow() const; |
|||
|
|||
/*! |
|||
* Retrieves the highest value of the range of the variable. |
|||
* |
|||
* @return The highest value of the range of the variable. |
|||
*/ |
|||
int_fast64_t getHigh() const; |
|||
|
|||
/*! |
|||
* Retrieves the manager that is responsible for this meta variable. |
|||
* |
|||
* A pointer to the manager that is responsible for this meta variable. |
|||
*/ |
|||
std::shared_ptr<DdManager<DdType::CUDD>> getDdManager() const; |
|||
|
|||
/*! |
|||
* Retrieves the number of DD variables for this meta variable. |
|||
* |
|||
* @return The number of DD variables for this meta variable. |
|||
*/ |
|||
std::size_t getNumberOfDdVariables() const; |
|||
|
|||
private: |
|||
/*! |
|||
* Retrieves the variables used to encode the meta variable. |
|||
* |
|||
* @return A vector of variables used to encode the meta variable. |
|||
*/ |
|||
std::vector<Bdd<DdType::CUDD>> const& getDdVariables() const; |
|||
|
|||
/*! |
|||
* Retrieves the cube of all variables that encode this meta variable. |
|||
* |
|||
* @return The cube of all variables that encode this meta variable. |
|||
*/ |
|||
Bdd<DdType::CUDD> const& getCube() const; |
|||
|
|||
// The name of the meta variable. |
|||
std::string name; |
|||
|
|||
// The type of the variable. |
|||
MetaVariableType type; |
|||
|
|||
// The lowest value of the range of the variable. |
|||
int_fast64_t low; |
|||
|
|||
// The highest value of the range of the variable. |
|||
int_fast64_t high; |
|||
|
|||
// The vector of variables that are used to encode the meta variable. |
|||
std::vector<Bdd<DdType::CUDD>> ddVariables; |
|||
|
|||
// The cube consisting of all variables that encode the meta variable. |
|||
Bdd<DdType::CUDD> cube; |
|||
|
|||
// A pointer to the manager responsible for this meta variable. |
|||
std::shared_ptr<DdManager<DdType::CUDD>> manager; |
|||
}; |
|||
} |
|||
} |
|||
|
|||
#endif /* STORM_STORAGE_DD_DDMETAVARIABLE_H_ */ |
@ -0,0 +1,60 @@ |
|||
#ifndef STORM_STORAGE_DD_CUDD_INTERNALCUDDADD_H_ |
|||
#define STORM_STORAGE_DD_CUDD_INTERNALCUDDADD_H_ |
|||
|
|||
#include <set> |
|||
|
|||
#include "src/storage/dd/DdType.h" |
|||
#include "src/storage/dd/InternalAdd.h" |
|||
|
|||
// Include the C++-interface of CUDD. |
|||
#include "cuddObj.hh" |
|||
|
|||
namespace storm { |
|||
namespace storage { |
|||
template<typename T> class SparseMatrix; |
|||
class BitVector; |
|||
template<typename E, typename V> class MatrixEntry; |
|||
} |
|||
|
|||
namespace dd { |
|||
// Forward-declare some classes. |
|||
template<DdType Type> class DdManager; |
|||
template<DdType Type> class Odd; |
|||
template<DdType Type> class Bdd; |
|||
|
|||
template<typename ValueType> |
|||
class InternalAdd<DdType::CUDD, ValueType> : public Dd<DdType::CUDD> { |
|||
public: |
|||
/*! |
|||
* Creates an ADD that encapsulates the given CUDD ADD. |
|||
* |
|||
* @param ddManager The manager responsible for this DD. |
|||
* @param cuddAdd The CUDD ADD to store. |
|||
* @param containedMetaVariables The meta variables that appear in the DD. |
|||
*/ |
|||
Add(InternalDdManager<DdType::CUDD> const* ddManager, ADD cuddAdd); |
|||
|
|||
|
|||
private: |
|||
/*! |
|||
* Retrieves the CUDD ADD object associated with this ADD. |
|||
* |
|||
* @return The CUDD ADD object associated with this ADD. |
|||
*/ |
|||
ADD getCuddAdd() const; |
|||
|
|||
/*! |
|||
* Retrieves the raw DD node of CUDD associated with this ADD. |
|||
* |
|||
* @return The DD node of CUDD associated with this ADD. |
|||
*/ |
|||
DdNode* getCuddDdNode() const; |
|||
|
|||
InternalDdManager<DdType::CUDD> const* ddManager; |
|||
|
|||
ADD cuddBdd; |
|||
} |
|||
} |
|||
} |
|||
|
|||
#endif /* STORM_STORAGE_DD_CUDD_INTERNALCUDDADD_H_ */ |
Write
Preview
Loading…
Cancel
Save
Reference in new issue