Storm 1.14.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
DdManager.h
Go to the documentation of this file.
1#pragma once
2
3#include <boost/optional.hpp>
4#include <functional>
5#include <set>
6#include <unordered_map>
7
16
17namespace storm {
18class Environment;
19} // namespace storm
20
21namespace storm {
22namespace dd {
23
24// Declare DdManager class so we can then specialize it for the different DD types.
25template<DdType LibraryType>
26class DdManager : public std::enable_shared_from_this<DdManager<LibraryType>> {
27 public:
28 friend class Bdd<LibraryType>;
29
30 template<DdType LibraryTypePrime, typename ValueType>
31 friend class Add;
32
33 template<DdType LibraryTypePrime, typename ValueType>
34 friend class AddIterator;
35
41 explicit DdManager(storm::Environment const& env);
42
46 static std::shared_ptr<DdManager<LibraryType>> createWithDefaultEnvironment();
47
48 // Explicitly forbid copying a DdManager, but allow moving it.
49 DdManager(DdManager<LibraryType> const& other) = delete;
53
54 std::shared_ptr<DdManager<LibraryType>> asSharedPointer();
55 std::shared_ptr<DdManager<LibraryType> const> asSharedPointer() const;
56
63
69 template<typename ValueType>
71
78
84 template<typename ValueType>
86
92 template<typename ValueType>
94
100 template<typename ValueType>
102
108 template<typename ValueType>
109 Add<LibraryType, ValueType> getConstant(ValueType const& value) const;
110
122 Bdd<LibraryType> getEncoding(storm::expressions::Variable const& variable, int_fast64_t value, bool mostSignificantBitAtTop = true) const;
123
132
140 template<typename ValueType>
142
149 Bdd<LibraryType> getIdentity(std::vector<std::pair<storm::expressions::Variable, storm::expressions::Variable>> const& variablePairs,
150 bool restrictToFirstRange = true) const;
151
159 Bdd<LibraryType> getIdentity(storm::expressions::Variable const& first, storm::expressions::Variable const& second, bool restrictToFirstRange = true) const;
160
168
175 Bdd<LibraryType> getCube(std::set<storm::expressions::Variable> const& variables) const;
176
184 std::vector<storm::expressions::Variable> cloneVariable(storm::expressions::Variable const& variable, std::string const& newVariableName,
185 boost::optional<uint64_t> const& numberOfLayers = boost::none);
186
194 std::pair<storm::expressions::Variable, storm::expressions::Variable> addMetaVariable(
195 std::string const& variableName, int_fast64_t low, int_fast64_t high,
196 boost::optional<std::pair<MetaVariablePosition, storm::expressions::Variable>> const& position = boost::none);
197
204 std::vector<storm::expressions::Variable> addMetaVariable(
205 std::string const& variableName, int_fast64_t low, int_fast64_t high, uint64_t numberOfLayers,
206 boost::optional<std::pair<MetaVariablePosition, storm::expressions::Variable>> const& position = boost::none);
207
214 std::vector<storm::expressions::Variable> addBitVectorMetaVariable(
215 std::string const& variableName, uint64_t bits, uint64_t numberOfLayers,
216 boost::optional<std::pair<MetaVariablePosition, storm::expressions::Variable>> const& position = boost::none);
217
223 std::pair<storm::expressions::Variable, storm::expressions::Variable> addMetaVariable(
224 std::string const& variableName, boost::optional<std::pair<MetaVariablePosition, storm::expressions::Variable>> const& position = boost::none);
225
232 std::vector<storm::expressions::Variable> addMetaVariable(
233 std::string const& variableName, uint64_t numberOfLayers,
234 boost::optional<std::pair<MetaVariablePosition, storm::expressions::Variable>> const& position = boost::none);
235
241 std::set<std::string> getAllMetaVariableNames() const;
242
248 std::size_t getNumberOfMetaVariables() const;
249
256 bool hasMetaVariable(std::string const& variableName) const;
257
264 storm::expressions::Variable getMetaVariable(std::string const& variableName) const;
265
272 bool supportsOrderedInsertion() const;
273
279 void allowDynamicReordering(bool value);
280
286 bool isDynamicReorderingAllowed() const;
287
291 void triggerReordering();
292
300
306 std::set<storm::expressions::Variable> getAllMetaVariables() const;
307
313 std::vector<uint_fast64_t> getSortedVariableIndices() const;
314
321 std::vector<uint_fast64_t> getSortedVariableIndices(std::set<storm::expressions::Variable> const& metaVariables) const;
322
329
336
340 void debugCheck() const;
341
350 void execute(std::function<void()> const& f) const;
351
352 private:
360 std::vector<storm::expressions::Variable> addMetaVariableHelper(
361 MetaVariableType const& type, std::string const& name, uint64_t numberOfDdVariables, uint64_t numberOfLayers,
362 boost::optional<std::pair<MetaVariablePosition, storm::expressions::Variable>> const& position = boost::none,
363 boost::optional<std::pair<int_fast64_t, int_fast64_t>> const& bounds = boost::none);
364
370 std::vector<std::string> getDdVariableNames() const;
371
377 std::vector<storm::expressions::Variable> getDdVariables() const;
378
384 storm::expressions::ExpressionManager const& getExpressionManager() const;
385
391 storm::expressions::ExpressionManager& getExpressionManager();
392
398 InternalDdManager<LibraryType>* getInternalDdManagerPointer();
399
405 InternalDdManager<LibraryType> const* getInternalDdManagerPointer() const;
406
407 // ATTENTION: as the DD packages typically perform garbage collection, the order of members is crucial here:
408 // First, the references to the DDs of the meta variables need to be disposed of and *then* the manager.
409
410 // The DD manager that is customized according to the selected library type.
411 InternalDdManager<LibraryType> internalDdManager;
412
413 // A mapping from variables to the meta variable information.
414 std::unordered_map<storm::expressions::Variable, DdMetaVariable<LibraryType>> metaVariableMap;
415
416 // The manager responsible for the variables.
417 std::shared_ptr<storm::expressions::ExpressionManager> manager;
418};
419} // namespace dd
420} // namespace storm
storm::expressions::Variable getMetaVariable(std::string const &variableName) const
Retrieves the given meta variable by name.
Add< LibraryType, ValueType > getAddOne() const
Retrieves an ADD representing the constant one function.
Definition DdManager.cpp:44
friend class Add
Definition DdManager.h:31
bool hasMetaVariable(std::string const &variableName) const
Retrieves whether the given meta variable name is already in use.
friend class AddIterator
Definition DdManager.h:34
std::shared_ptr< DdManager< LibraryType > > asSharedPointer()
Definition DdManager.cpp:28
static std::shared_ptr< DdManager< LibraryType > > createWithDefaultEnvironment()
Creates a new manager that is configured according to a default environment.
Definition DdManager.cpp:23
Add< LibraryType, ValueType > getAddZero() const
Retrieves an ADD representing the constant zero function.
Definition DdManager.cpp:55
std::vector< uint_fast64_t > getSortedVariableIndices() const
Retrieves the (sorted) list of the variable indices of the DD variables given by the meta variable se...
std::set< storm::expressions::Variable > getAllMetaVariables() const
Retrieves the set of meta variables contained in the DD.
InternalDdManager< LibraryType > & getInternalDdManager()
Retrieves the internal DD manager.
Bdd< LibraryType > getCube(storm::expressions::Variable const &variable) const
Retrieves a BDD that is the cube of the variables representing the given meta variable.
Add< LibraryType, ValueType > getInfinity() const
Retrieves an ADD representing the constant infinity function.
Definition DdManager.cpp:67
void execute(std::function< void()> const &f) const
All code that manipulates DDs shall be called through this function.
Bdd< LibraryType > getBddOne() const
Retrieves a BDD representing the constant one function.
Definition DdManager.cpp:38
DdManager(DdManager< LibraryType > &&other)=default
std::set< std::string > getAllMetaVariableNames() const
Retrieves the names of all meta variables that have been added to the manager.
Bdd< LibraryType > getBddZero() const
Retrieves a BDD representing the constant zero function.
Definition DdManager.cpp:49
void triggerReordering()
Triggers a reordering of the DDs managed by this manager (if supported).
DdManager(DdManager< LibraryType > const &other)=delete
Bdd< LibraryType > getEncoding(storm::expressions::Variable const &variable, int_fast64_t value, bool mostSignificantBitAtTop=true) const
Retrieves the BDD representing the function that maps all inputs which have the given meta variable e...
Definition DdManager.cpp:78
bool isDynamicReorderingAllowed() const
Retrieves whether dynamic reordering is currently allowed (if supported).
std::vector< storm::expressions::Variable > cloneVariable(storm::expressions::Variable const &variable, std::string const &newVariableName, boost::optional< uint64_t > const &numberOfLayers=boost::none)
Clones the given meta variable and optionally changes the number of layers of the variable.
Add< LibraryType, ValueType > getIdentity(storm::expressions::Variable const &variable) const
Retrieves the ADD representing the identity of the meta variable, i.e., a function that maps all lega...
Add< LibraryType, ValueType > getAddUndefined() const
Retrieves an ADD representing an undefined value.
Definition DdManager.cpp:61
bool supportsOrderedInsertion() const
Checks whether this manager supports the ordered insertion of variables, i.e.
Bdd< LibraryType > getRange(storm::expressions::Variable const &variable) const
Retrieves the BDD representing the range of the meta variable, i.e., a function that maps all legal v...
std::pair< storm::expressions::Variable, storm::expressions::Variable > addMetaVariable(std::string const &variableName, int_fast64_t low, int_fast64_t high, boost::optional< std::pair< MetaVariablePosition, storm::expressions::Variable > > const &position=boost::none)
Adds an integer meta variable with the given range with two layers (a 'normal' and a 'primed' one).
DdManager< LibraryType > & operator=(DdManager< LibraryType > const &other)=delete
Add< LibraryType, ValueType > getConstant(ValueType const &value) const
Retrieves an ADD representing the constant function with the given value.
Definition DdManager.cpp:73
DdManager< LibraryType > & operator=(DdManager< LibraryType > &&other)=default
std::vector< storm::expressions::Variable > addBitVectorMetaVariable(std::string const &variableName, uint64_t bits, uint64_t numberOfLayers, boost::optional< std::pair< MetaVariablePosition, storm::expressions::Variable > > const &position=boost::none)
Creates a meta variable with the given number of layers.
DdManager(storm::Environment const &env)
Creates an empty manager without any meta variables.
Definition DdManager.cpp:17
void allowDynamicReordering(bool value)
Sets whether dynamic reordering is allowed for the DDs managed by this manager (if supported).
void debugCheck() const
Performs a debug check if available.
std::size_t getNumberOfMetaVariables() const
Retrieves the number of meta variables that are contained in this manager.
This class is responsible for managing a set of typed variables and all expressions using these varia...