18#ifdef STORM_HAVE_SYLVAN
20#pragma clang diagnostic push
21#pragma clang diagnostic ignored "-Wzero-length-array"
22#pragma clang diagnostic ignored "-Wc99-extensions"
26VOID_TASK_0(gc_start) {
35VOID_TASK_2(execute_sylvan, std::function<
void()>
const*, f, std::exception_ptr*, e) {
38 }
catch (std::exception& exception) {
39 *e = std::current_exception();
44#pragma clang diagnostic pop
47uint_fast64_t InternalDdManager<DdType::Sylvan>::numberOfInstances = 0;
48bool InternalDdManager<DdType::Sylvan>::suspended =
false;
52uint_fast64_t InternalDdManager<DdType::Sylvan>::nextFreeVariableIndex = 0;
54uint_fast64_t findLargestPowerOfTwoFitting(uint_fast64_t number) {
55 for (uint_fast64_t index = 0; index < 64; ++index) {
56 if ((number & (1ull << (63 - index))) != 0) {
63InternalDdManager<DdType::Sylvan>::InternalDdManager() {
64 if (numberOfInstances == 0) {
66 size_t const task_deque_size = 1024 * 1024;
68 lace_set_stacksize(1024 * 1024 * 16);
72 sylvan_set_limits(storm::settings::getModule<storm::settings::modules::SylvanSettings>().getMaximalMemory() * 1024 * 1024, 0, 0);
73 sylvan_init_package();
75 sylvan::Sylvan::initBdd();
76 sylvan::Sylvan::initMtbdd();
77 sylvan::Sylvan::initCustomMtbdd();
80 sylvan_gc_hook_pregc(TASK(gc_start));
81 sylvan_gc_hook_postgc(TASK(gc_end));
90InternalDdManager<DdType::Sylvan>::~InternalDdManager() {
92 if (numberOfInstances == 0) {
98 sylvan::Sylvan::quitPackage();
103InternalBdd<DdType::Sylvan> InternalDdManager<DdType::Sylvan>::getBddOne()
const {
104 return InternalBdd<DdType::Sylvan>(
this, sylvan::Bdd::bddOne());
108InternalAdd<DdType::Sylvan, double> InternalDdManager<DdType::Sylvan>::getAddOne()
const {
109 return InternalAdd<DdType::Sylvan, double>(
this, sylvan::Mtbdd::doubleTerminal(storm::utility::one<double>()));
113InternalAdd<DdType::Sylvan, uint_fast64_t> InternalDdManager<DdType::Sylvan>::getAddOne()
const {
114 return InternalAdd<DdType::Sylvan, uint_fast64_t>(
this, sylvan::Mtbdd::int64Terminal(storm::utility::one<uint_fast64_t>()));
118InternalAdd<DdType::Sylvan, storm::RationalNumber> InternalDdManager<DdType::Sylvan>::getAddOne()
const {
119 return InternalAdd<DdType::Sylvan, storm::RationalNumber>(
this, sylvan::Mtbdd::stormRationalNumberTerminal(storm::utility::one<storm::RationalNumber>()));
123InternalAdd<DdType::Sylvan, storm::RationalFunction> InternalDdManager<DdType::Sylvan>::getAddOne()
const {
124 return InternalAdd<DdType::Sylvan, storm::RationalFunction>(
this,
125 sylvan::Mtbdd::stormRationalFunctionTerminal(storm::utility::one<storm::RationalFunction>()));
128InternalBdd<DdType::Sylvan> InternalDdManager<DdType::Sylvan>::getBddZero()
const {
129 return InternalBdd<DdType::Sylvan>(
this, sylvan::Bdd::bddZero());
132InternalBdd<DdType::Sylvan> InternalDdManager<DdType::Sylvan>::getBddEncodingLessOrEqualThan(uint64_t bound, InternalBdd<DdType::Sylvan>
const& cube,
133 uint64_t numberOfDdVariables)
const {
134 return InternalBdd<DdType::Sylvan>(
this, sylvan::Bdd(this->getBddEncodingLessOrEqualThanRec(0, (1ull << numberOfDdVariables) - 1, bound,
135 cube.getSylvanBdd().GetBDD(), numberOfDdVariables)));
138BDD InternalDdManager<DdType::Sylvan>::getBddEncodingLessOrEqualThanRec(uint64_t minimalValue, uint64_t maximalValue, uint64_t bound, BDD cube,
139 uint64_t remainingDdVariables)
const {
140 if (maximalValue <= bound) {
142 }
else if (minimalValue > bound) {
146 STORM_LOG_ASSERT(remainingDdVariables > 0,
"Expected more remaining DD variables.");
147 uint64_t newRemainingDdVariables = remainingDdVariables - 1;
149 getBddEncodingLessOrEqualThanRec(minimalValue, maximalValue & ~(1ull << newRemainingDdVariables), bound, sylvan_high(cube), newRemainingDdVariables);
150 bdd_refs_push(elseResult);
152 getBddEncodingLessOrEqualThanRec(minimalValue | (1ull << newRemainingDdVariables), maximalValue, bound, sylvan_high(cube), newRemainingDdVariables);
153 bdd_refs_push(elseResult);
154 BDD result = sylvan_makenode(sylvan_var(cube), elseResult, thenResult);
160InternalAdd<DdType::Sylvan, double> InternalDdManager<DdType::Sylvan>::getAddZero()
const {
161 return InternalAdd<DdType::Sylvan, double>(
this, sylvan::Mtbdd::doubleTerminal(storm::utility::zero<double>()));
165InternalAdd<DdType::Sylvan, uint_fast64_t> InternalDdManager<DdType::Sylvan>::getAddZero()
const {
166 return InternalAdd<DdType::Sylvan, uint_fast64_t>(
this, sylvan::Mtbdd::int64Terminal(storm::utility::zero<uint_fast64_t>()));
170InternalAdd<DdType::Sylvan, storm::RationalNumber> InternalDdManager<DdType::Sylvan>::getAddZero()
const {
171 return InternalAdd<DdType::Sylvan, storm::RationalNumber>(
this, sylvan::Mtbdd::stormRationalNumberTerminal(storm::utility::zero<storm::RationalNumber>()));
175InternalAdd<DdType::Sylvan, storm::RationalFunction> InternalDdManager<DdType::Sylvan>::getAddZero()
const {
176 return InternalAdd<DdType::Sylvan, storm::RationalFunction>(
this,
177 sylvan::Mtbdd::stormRationalFunctionTerminal(storm::utility::zero<storm::RationalFunction>()));
180template<
typename ValueType>
181InternalAdd<DdType::Sylvan, ValueType> InternalDdManager<DdType::Sylvan>::getAddUndefined()
const {
182 return InternalAdd<DdType::Sylvan, ValueType>(
this, sylvan::Mtbdd(sylvan::Bdd::bddZero()));
186InternalAdd<DdType::Sylvan, double> InternalDdManager<DdType::Sylvan>::getConstant(
double const& value)
const {
187 return InternalAdd<DdType::Sylvan, double>(
this, sylvan::Mtbdd::doubleTerminal(value));
191InternalAdd<DdType::Sylvan, uint_fast64_t> InternalDdManager<DdType::Sylvan>::getConstant(uint_fast64_t
const& value)
const {
192 return InternalAdd<DdType::Sylvan, uint_fast64_t>(
this, sylvan::Mtbdd::int64Terminal(value));
196InternalAdd<DdType::Sylvan, storm::RationalNumber> InternalDdManager<DdType::Sylvan>::getConstant(storm::RationalNumber
const& value)
const {
197 return InternalAdd<DdType::Sylvan, storm::RationalNumber>(
this, sylvan::Mtbdd::stormRationalNumberTerminal(value));
201InternalAdd<DdType::Sylvan, storm::RationalFunction> InternalDdManager<DdType::Sylvan>::getConstant(
storm::RationalFunction const& value)
const {
202 return InternalAdd<DdType::Sylvan, storm::RationalFunction>(
this, sylvan::Mtbdd::stormRationalFunctionTerminal(value));
205std::vector<InternalBdd<DdType::Sylvan>> InternalDdManager<DdType::Sylvan>::createDdVariables(uint64_t numberOfLayers,
206 boost::optional<uint_fast64_t>
const& position) {
207 STORM_LOG_THROW(!position, storm::exceptions::NotSupportedException,
"The manager does not support ordered insertion.");
209 std::vector<InternalBdd<DdType::Sylvan>> result;
211 for (uint64_t layer = 0; layer < numberOfLayers; ++layer) {
212 result.emplace_back(InternalBdd<DdType::Sylvan>(
this, sylvan::Bdd::bddVar(nextFreeVariableIndex)));
213 ++nextFreeVariableIndex;
219bool InternalDdManager<DdType::Sylvan>::supportsOrderedInsertion()
const {
223void InternalDdManager<DdType::Sylvan>::allowDynamicReordering(
bool) {
224 STORM_LOG_THROW(
false, storm::exceptions::NotSupportedException,
"Operation is not supported by sylvan.");
227bool InternalDdManager<DdType::Sylvan>::isDynamicReorderingAllowed()
const {
228 STORM_LOG_THROW(
false, storm::exceptions::NotSupportedException,
"Operation is not supported by sylvan.");
231void InternalDdManager<DdType::Sylvan>::triggerReordering() {
232 STORM_LOG_THROW(
false, storm::exceptions::NotSupportedException,
"Operation is not supported by sylvan.");
235void InternalDdManager<DdType::Sylvan>::debugCheck()
const {
236 STORM_LOG_THROW(
false, storm::exceptions::NotSupportedException,
"Operation is not supported by sylvan.");
239void InternalDdManager<DdType::Sylvan>::execute(std::function<
void()>
const& f)
const {
241 std::exception_ptr e =
nullptr;
245 RUN(execute_sylvan, &f, &e);
250 RUN(execute_sylvan, &f, &e);
253 std::rethrow_exception(e);
257uint_fast64_t InternalDdManager<DdType::Sylvan>::getNumberOfDdVariables()
const {
258 return nextFreeVariableIndex;
263 "This version of Storm was compiled without support for Sylvan. Yet, a method was called that requires this support. Please choose a "
264 "version of Storm with Sylvan support.");
271 "This version of Storm was compiled without support for Sylvan. Yet, a method was called that requires this support. Please choose a "
272 "version of Storm with Sylvan support.");
275template<
typename ValueType>
278 "This version of Storm was compiled without support for Sylvan. Yet, a method was called that requires this support. Please choose a "
279 "version of Storm with Sylvan support.");
284 "This version of Storm was compiled without support for Sylvan. Yet, a method was called that requires this support. Please choose a "
285 "version of Storm with Sylvan support.");
289 uint64_t numberOfDdVariables)
const {
291 "This version of Storm was compiled without support for Sylvan. Yet, a method was called that requires this support. Please choose a "
292 "version of Storm with Sylvan support.");
295template<
typename ValueType>
298 "This version of Storm was compiled without support for Sylvan. Yet, a method was called that requires this support. Please choose a "
299 "version of Storm with Sylvan support.");
302template<
typename ValueType>
305 "This version of Storm was compiled without support for Sylvan. Yet, a method was called that requires this support. Please choose a "
306 "version of Storm with Sylvan support.");
309template<
typename ValueType>
312 "This version of Storm was compiled without support for Sylvan. Yet, a method was called that requires this support. Please choose a "
313 "version of Storm with Sylvan support.");
317 boost::optional<uint_fast64_t>
const& position) {
319 "This version of Storm was compiled without support for Sylvan. Yet, a method was called that requires this support. Please choose a "
320 "version of Storm with Sylvan support.");
325 "This version of Storm was compiled without support for Sylvan. Yet, a method was called that requires this support. Please choose a "
326 "version of Storm with Sylvan support.");
331 "This version of Storm was compiled without support for Sylvan. Yet, a method was called that requires this support. Please choose a "
332 "version of Storm with Sylvan support.");
337 "This version of Storm was compiled without support for Sylvan. Yet, a method was called that requires this support. Please choose a "
338 "version of Storm with Sylvan support.");
343 "This version of Storm was compiled without support for Sylvan. Yet, a method was called that requires this support. Please choose a "
344 "version of Storm with Sylvan support.");
349 "This version of Storm was compiled without support for Sylvan. Yet, a method was called that requires this support. Please choose a "
350 "version of Storm with Sylvan support.");
355 "This version of Storm was compiled without support for Sylvan. Yet, a method was called that requires this support. Please choose a "
356 "version of Storm with Sylvan support.");
361 "This version of Storm was compiled without support for Sylvan. Yet, a method was called that requires this support. Please choose a "
362 "version of Storm with Sylvan support.");
366#ifndef STORM_HAVE_SYLVAN
This class represents the settings for Sylvan.
uint64_t getNumberOfThreads() const
Retrieves the amount of threads available to Sylvan.
#define STORM_LOG_TRACE(message)
#define STORM_LOG_ASSERT(cond, message)
#define STORM_LOG_THROW(cond, exception, message)