Storm 2.0.0.3
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
InternalCuddDdManager.cpp
Go to the documentation of this file.
2
6
7namespace storm {
8namespace dd {
9
10#ifdef STORM_HAVE_CUDD
11InternalDdManager<DdType::CUDD>::InternalDdManager(storm::CuddDdManagerEnvironment const& environment) : cuddManager(), numberOfDdVariables(0) {
12 this->cuddManager.SetMaxMemory(static_cast<unsigned long>(environment.getMaximalMemory() * 1024ul * 1024ul));
13 this->cuddManager.SetEpsilon(environment.getConstantPrecision());
14
15 // Dynamic reordering is currently broken with CUDD, as several places (most notably the construction of DDs) rely on
16 // the variable order not changing. We therefore disable it unconditionally. See stormchecker/storm#119.
17 this->getCuddManager().AutodynDisable();
18}
19
20InternalDdManager<DdType::CUDD>::~InternalDdManager() {
21 // Intentionally left empty.
22}
23
24InternalBdd<DdType::CUDD> InternalDdManager<DdType::CUDD>::getBddOne() const {
25 return InternalBdd<DdType::CUDD>(this, cuddManager.bddOne());
26}
27
28template<typename ValueType>
29InternalAdd<DdType::CUDD, ValueType> InternalDdManager<DdType::CUDD>::getAddOne() const {
30 return InternalAdd<DdType::CUDD, ValueType>(this, cuddManager.addOne());
31}
32
33InternalBdd<DdType::CUDD> InternalDdManager<DdType::CUDD>::getBddZero() const {
34 return InternalBdd<DdType::CUDD>(this, cuddManager.bddZero());
35}
36
37InternalBdd<DdType::CUDD> InternalDdManager<DdType::CUDD>::getBddEncodingLessOrEqualThan(uint64_t bound, InternalBdd<DdType::CUDD> const& cube,
38 uint64_t numberOfDdVariables) const {
39 return InternalBdd<DdType::CUDD>(this, cudd::BDD(cuddManager, this->getBddEncodingLessOrEqualThanRec(0, (1ull << numberOfDdVariables) - 1, bound,
40 cube.getCuddDdNode(), numberOfDdVariables)));
41}
42
43DdNodePtr InternalDdManager<DdType::CUDD>::getBddEncodingLessOrEqualThanRec(uint64_t minimalValue, uint64_t maximalValue, uint64_t bound, DdNodePtr cube,
44 uint64_t remainingDdVariables) const {
45 if (maximalValue <= bound) {
46 return Cudd_ReadOne(cuddManager.getManager());
47 } else if (minimalValue > bound) {
48 return Cudd_ReadLogicZero(cuddManager.getManager());
49 }
50
51 STORM_LOG_ASSERT(remainingDdVariables > 0, "Expected more remaining DD variables.");
52 STORM_LOG_ASSERT(!Cudd_IsConstant(cube), "Expected non-constant cube.");
53 uint64_t newRemainingDdVariables = remainingDdVariables - 1;
54 DdNodePtr elseResult =
55 getBddEncodingLessOrEqualThanRec(minimalValue, maximalValue & ~(1ull << newRemainingDdVariables), bound, Cudd_T(cube), newRemainingDdVariables);
56 Cudd_Ref(elseResult);
57 DdNodePtr thenResult =
58 getBddEncodingLessOrEqualThanRec(minimalValue | (1ull << newRemainingDdVariables), maximalValue, bound, Cudd_T(cube), newRemainingDdVariables);
59 Cudd_Ref(thenResult);
60 STORM_LOG_ASSERT(thenResult != elseResult, "Expected different results.");
61
62 bool complemented = Cudd_IsComplement(thenResult);
63 DdNodePtr result =
64 cuddUniqueInter(cuddManager.getManager(), Cudd_NodeReadIndex(cube), Cudd_Regular(thenResult), complemented ? Cudd_Not(elseResult) : elseResult);
65 if (complemented) {
66 result = Cudd_Not(result);
67 }
68 Cudd_Deref(thenResult);
69 Cudd_Deref(elseResult);
70 return result;
71}
72
73template<typename ValueType>
74InternalAdd<DdType::CUDD, ValueType> InternalDdManager<DdType::CUDD>::getAddZero() const {
75 return InternalAdd<DdType::CUDD, ValueType>(this, cuddManager.addZero());
76}
77
78template<typename ValueType>
79InternalAdd<DdType::CUDD, ValueType> InternalDdManager<DdType::CUDD>::getAddUndefined() const {
80 STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "Undefined values are not supported by CUDD.");
81}
82
83template<typename ValueType>
84InternalAdd<DdType::CUDD, ValueType> InternalDdManager<DdType::CUDD>::getConstant(ValueType const& value) const {
85 return InternalAdd<DdType::CUDD, ValueType>(this, cuddManager.constant(value));
86}
87
88std::vector<InternalBdd<DdType::CUDD>> InternalDdManager<DdType::CUDD>::createDdVariables(uint64_t numberOfLayers,
89 boost::optional<uint_fast64_t> const& position) {
90 std::vector<InternalBdd<DdType::CUDD>> result;
91
92 if (position) {
93 for (uint64_t layer = 0; layer < numberOfLayers; ++layer) {
94 result.emplace_back(InternalBdd<DdType::CUDD>(this, cuddManager.bddNewVarAtLevel(position.get() + layer)));
95 }
96 } else {
97 for (uint64_t layer = 0; layer < numberOfLayers; ++layer) {
98 result.emplace_back(InternalBdd<DdType::CUDD>(this, cuddManager.bddVar()));
99 }
100 }
101
102 // Connect the variables so they are not 'torn apart' by dynamic reordering.
103 // Note that MTR_FIXED preserves the order of the layers. While this is not always necessary to preserve,
104 // (for example) the hybrid engine relies on this connection, so we choose MTR_FIXED instead of MTR_DEFAULT.
105 cuddManager.MakeTreeNode(result.front().getIndex(), numberOfLayers, MTR_FIXED);
106
107 // Keep track of the number of variables.
108 numberOfDdVariables += numberOfLayers;
109
110 return result;
111}
112
113bool InternalDdManager<DdType::CUDD>::supportsOrderedInsertion() const {
114 return true;
115}
116
117void InternalDdManager<DdType::CUDD>::allowDynamicReordering(bool value) {
118 STORM_LOG_THROW(!value, storm::exceptions::NotSupportedException, "Dynamic reordering is not supported for CUDD.");
119}
120
121bool InternalDdManager<DdType::CUDD>::isDynamicReorderingAllowed() const {
122 return false;
123}
124
125void InternalDdManager<DdType::CUDD>::triggerReordering() {
126 STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "Dynamic reordering is not supported for CUDD.");
127}
128
129void InternalDdManager<DdType::CUDD>::debugCheck() const {
130 this->getCuddManager().CheckKeys();
131 this->getCuddManager().DebugCheck();
132}
133
134void InternalDdManager<DdType::CUDD>::execute(std::function<void()> const& f) const {
135 f();
136}
137
138cudd::Cudd& InternalDdManager<DdType::CUDD>::getCuddManager() {
139 return cuddManager;
140}
141
142cudd::Cudd const& InternalDdManager<DdType::CUDD>::getCuddManager() const {
143 return cuddManager;
144}
145
146uint_fast64_t InternalDdManager<DdType::CUDD>::getNumberOfDdVariables() const {
147 return numberOfDdVariables;
148}
149
150#else
151
153 STORM_LOG_THROW(false, storm::exceptions::MissingLibraryException,
154 "This version of Storm was compiled without support for CUDD. Yet, a method was called that requires this support. Please choose a version "
155 "of Storm with CUDD support.");
156}
157
159 // Intentionally left empty.
160}
161
163 STORM_LOG_THROW(false, storm::exceptions::MissingLibraryException,
164 "This version of Storm was compiled without support for CUDD. Yet, a method was called that requires this support. Please choose a version "
165 "of Storm with CUDD support.");
166}
167
168template<typename ValueType>
170 STORM_LOG_THROW(false, storm::exceptions::MissingLibraryException,
171 "This version of Storm was compiled without support for CUDD. Yet, a method was called that requires this support. Please choose a version "
172 "of Storm with CUDD support.");
173}
174
176 STORM_LOG_THROW(false, storm::exceptions::MissingLibraryException,
177 "This version of Storm was compiled without support for CUDD. Yet, a method was called that requires this support. Please choose a version "
178 "of Storm with CUDD support.");
179}
180
182 uint64_t numberOfDdVariables) const {
183 STORM_LOG_THROW(false, storm::exceptions::MissingLibraryException,
184 "This version of Storm was compiled without support for CUDD. Yet, a method was called that requires this support. Please choose a version "
185 "of Storm with CUDD support.");
186}
187
188template<typename ValueType>
190 STORM_LOG_THROW(false, storm::exceptions::MissingLibraryException,
191 "This version of Storm was compiled without support for CUDD. Yet, a method was called that requires this support. Please choose a version "
192 "of Storm with CUDD support.");
193}
194
195template<typename ValueType>
197 STORM_LOG_THROW(false, storm::exceptions::MissingLibraryException,
198 "This version of Storm was compiled without support for CUDD. Yet, a method was called that requires this support. Please choose a version "
199 "of Storm with CUDD support.");
200}
201
202template<typename ValueType>
204 STORM_LOG_THROW(false, storm::exceptions::MissingLibraryException,
205 "This version of Storm was compiled without support for CUDD. Yet, a method was called that requires this support. Please choose a version "
206 "of Storm with CUDD support.");
207}
208
209std::vector<InternalBdd<DdType::CUDD>> InternalDdManager<DdType::CUDD>::createDdVariables(uint64_t numberOfLayers,
210 boost::optional<uint_fast64_t> const& position) {
211 STORM_LOG_THROW(false, storm::exceptions::MissingLibraryException,
212 "This version of Storm was compiled without support for CUDD. Yet, a method was called that requires this support. Please choose a version "
213 "of Storm with CUDD support.");
214}
215
217 STORM_LOG_THROW(false, storm::exceptions::MissingLibraryException,
218 "This version of Storm was compiled without support for CUDD. Yet, a method was called that requires this support. Please choose a version "
219 "of Storm with CUDD support.");
220}
221
223 STORM_LOG_THROW(false, storm::exceptions::MissingLibraryException,
224 "This version of Storm was compiled without support for CUDD. Yet, a method was called that requires this support. Please choose a version "
225 "of Storm with CUDD support.");
226}
227
229 STORM_LOG_THROW(false, storm::exceptions::MissingLibraryException,
230 "This version of Storm was compiled without support for CUDD. Yet, a method was called that requires this support. Please choose a version "
231 "of Storm with CUDD support.");
232}
233
235 STORM_LOG_THROW(false, storm::exceptions::MissingLibraryException,
236 "This version of Storm was compiled without support for CUDD. Yet, a method was called that requires this support. Please choose a version "
237 "of Storm with CUDD support.");
238}
239
241 STORM_LOG_THROW(false, storm::exceptions::MissingLibraryException,
242 "This version of Storm was compiled without support for CUDD. Yet, a method was called that requires this support. Please choose a version "
243 "of Storm with CUDD support.");
244}
245
246void InternalDdManager<DdType::CUDD>::execute(std::function<void()> const& f) const {
247 STORM_LOG_THROW(false, storm::exceptions::MissingLibraryException,
248 "This version of Storm was compiled without support for CUDD. Yet, a method was called that requires this support. Please choose a version "
249 "of Storm with CUDD support.");
250}
251
253 STORM_LOG_THROW(false, storm::exceptions::MissingLibraryException,
254 "This version of Storm was compiled without support for CUDD. Yet, a method was called that requires this support. Please choose a version "
255 "of Storm with CUDD support.");
256}
257#endif
258
261
264
267} // namespace dd
268} // namespace storm
uint64_t getMaximalMemory() const
Retrieves the maximal amount of memory (in megabytes) that CUDD can occupy.
double getConstantPrecision() const
Retrieves the precision up to which constants are considered to be different.
InternalDdManager(storm::CuddDdManagerEnvironment const &environment)
Creates a new internal manager for CUDD DDs.
#define STORM_LOG_ASSERT(cond, message)
Definition macros.h:9
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:39
The contract of a DD backend.