15#ifdef STORM_HAVE_SYLVAN
17#pragma clang diagnostic push
18#pragma clang diagnostic ignored "-Wzero-length-array"
19#pragma clang diagnostic ignored "-Wc99-extensions"
23VOID_TASK_0(gc_start) {
32VOID_TASK_2(execute_sylvan, std::function<
void()>
const*, f, std::exception_ptr*, e) {
35 }
catch (std::exception& exception) {
36 *e = std::current_exception();
41#pragma clang diagnostic pop
44uint_fast64_t InternalDdManager<DdType::Sylvan>::numberOfInstances = 0;
45bool InternalDdManager<DdType::Sylvan>::suspended =
false;
49uint_fast64_t InternalDdManager<DdType::Sylvan>::nextFreeVariableIndex = 0;
51uint_fast64_t findLargestPowerOfTwoFitting(uint_fast64_t number) {
52 for (uint_fast64_t index = 0; index < 64; ++index) {
53 if ((number & (1ull << (63 - index))) != 0) {
60InternalDdManager<DdType::Sylvan>::InternalDdManager() {
61 if (numberOfInstances == 0) {
63 size_t const task_deque_size = 1024 * 1024;
65 lace_set_stacksize(1024 * 1024 * 16);
69 sylvan_set_limits(storm::settings::getModule<storm::settings::modules::SylvanSettings>().getMaximalMemory() * 1024 * 1024, 0, 0);
70 sylvan_init_package();
72 sylvan::Sylvan::initBdd();
73 sylvan::Sylvan::initMtbdd();
74 sylvan::Sylvan::initCustomMtbdd();
77 sylvan_gc_hook_pregc(TASK(gc_start));
78 sylvan_gc_hook_postgc(TASK(gc_end));
87InternalDdManager<DdType::Sylvan>::~InternalDdManager() {
89 if (numberOfInstances == 0) {
95 sylvan::Sylvan::quitPackage();
100InternalBdd<DdType::Sylvan> InternalDdManager<DdType::Sylvan>::getBddOne()
const {
101 return InternalBdd<DdType::Sylvan>(
this, sylvan::Bdd::bddOne());
105InternalAdd<DdType::Sylvan, double> InternalDdManager<DdType::Sylvan>::getAddOne()
const {
106 return InternalAdd<DdType::Sylvan, double>(
this, sylvan::Mtbdd::doubleTerminal(storm::utility::one<double>()));
110InternalAdd<DdType::Sylvan, uint_fast64_t> InternalDdManager<DdType::Sylvan>::getAddOne()
const {
111 return InternalAdd<DdType::Sylvan, uint_fast64_t>(
this, sylvan::Mtbdd::int64Terminal(storm::utility::one<uint_fast64_t>()));
115InternalAdd<DdType::Sylvan, storm::RationalNumber> InternalDdManager<DdType::Sylvan>::getAddOne()
const {
116 return InternalAdd<DdType::Sylvan, storm::RationalNumber>(
this, sylvan::Mtbdd::stormRationalNumberTerminal(storm::utility::one<storm::RationalNumber>()));
120InternalAdd<DdType::Sylvan, storm::RationalFunction> InternalDdManager<DdType::Sylvan>::getAddOne()
const {
121 return InternalAdd<DdType::Sylvan, storm::RationalFunction>(
this,
122 sylvan::Mtbdd::stormRationalFunctionTerminal(storm::utility::one<storm::RationalFunction>()));
125InternalBdd<DdType::Sylvan> InternalDdManager<DdType::Sylvan>::getBddZero()
const {
126 return InternalBdd<DdType::Sylvan>(
this, sylvan::Bdd::bddZero());
129InternalBdd<DdType::Sylvan> InternalDdManager<DdType::Sylvan>::getBddEncodingLessOrEqualThan(uint64_t bound, InternalBdd<DdType::Sylvan>
const& cube,
130 uint64_t numberOfDdVariables)
const {
131 return InternalBdd<DdType::Sylvan>(
this, sylvan::Bdd(this->getBddEncodingLessOrEqualThanRec(0, (1ull << numberOfDdVariables) - 1, bound,
132 cube.getSylvanBdd().GetBDD(), numberOfDdVariables)));
135BDD InternalDdManager<DdType::Sylvan>::getBddEncodingLessOrEqualThanRec(uint64_t minimalValue, uint64_t maximalValue, uint64_t bound, BDD cube,
136 uint64_t remainingDdVariables)
const {
137 if (maximalValue <= bound) {
139 }
else if (minimalValue > bound) {
143 STORM_LOG_ASSERT(remainingDdVariables > 0,
"Expected more remaining DD variables.");
144 uint64_t newRemainingDdVariables = remainingDdVariables - 1;
146 getBddEncodingLessOrEqualThanRec(minimalValue, maximalValue & ~(1ull << newRemainingDdVariables), bound, sylvan_high(cube), newRemainingDdVariables);
147 bdd_refs_push(elseResult);
149 getBddEncodingLessOrEqualThanRec(minimalValue | (1ull << newRemainingDdVariables), maximalValue, bound, sylvan_high(cube), newRemainingDdVariables);
150 bdd_refs_push(elseResult);
151 BDD result = sylvan_makenode(sylvan_var(cube), elseResult, thenResult);
157InternalAdd<DdType::Sylvan, double> InternalDdManager<DdType::Sylvan>::getAddZero()
const {
158 return InternalAdd<DdType::Sylvan, double>(
this, sylvan::Mtbdd::doubleTerminal(storm::utility::zero<double>()));
162InternalAdd<DdType::Sylvan, uint_fast64_t> InternalDdManager<DdType::Sylvan>::getAddZero()
const {
163 return InternalAdd<DdType::Sylvan, uint_fast64_t>(
this, sylvan::Mtbdd::int64Terminal(storm::utility::zero<uint_fast64_t>()));
167InternalAdd<DdType::Sylvan, storm::RationalNumber> InternalDdManager<DdType::Sylvan>::getAddZero()
const {
168 return InternalAdd<DdType::Sylvan, storm::RationalNumber>(
this, sylvan::Mtbdd::stormRationalNumberTerminal(storm::utility::zero<storm::RationalNumber>()));
172InternalAdd<DdType::Sylvan, storm::RationalFunction> InternalDdManager<DdType::Sylvan>::getAddZero()
const {
173 return InternalAdd<DdType::Sylvan, storm::RationalFunction>(
this,
174 sylvan::Mtbdd::stormRationalFunctionTerminal(storm::utility::zero<storm::RationalFunction>()));
177template<
typename ValueType>
178InternalAdd<DdType::Sylvan, ValueType> InternalDdManager<DdType::Sylvan>::getAddUndefined()
const {
179 return InternalAdd<DdType::Sylvan, ValueType>(
this, sylvan::Mtbdd(sylvan::Bdd::bddZero()));
183InternalAdd<DdType::Sylvan, double> InternalDdManager<DdType::Sylvan>::getConstant(
double const& value)
const {
184 return InternalAdd<DdType::Sylvan, double>(
this, sylvan::Mtbdd::doubleTerminal(value));
188InternalAdd<DdType::Sylvan, uint_fast64_t> InternalDdManager<DdType::Sylvan>::getConstant(uint_fast64_t
const& value)
const {
189 return InternalAdd<DdType::Sylvan, uint_fast64_t>(
this, sylvan::Mtbdd::int64Terminal(value));
193InternalAdd<DdType::Sylvan, storm::RationalNumber> InternalDdManager<DdType::Sylvan>::getConstant(storm::RationalNumber
const& value)
const {
194 return InternalAdd<DdType::Sylvan, storm::RationalNumber>(
this, sylvan::Mtbdd::stormRationalNumberTerminal(value));
198InternalAdd<DdType::Sylvan, storm::RationalFunction> InternalDdManager<DdType::Sylvan>::getConstant(
storm::RationalFunction const& value)
const {
199 return InternalAdd<DdType::Sylvan, storm::RationalFunction>(
this, sylvan::Mtbdd::stormRationalFunctionTerminal(value));
202std::vector<InternalBdd<DdType::Sylvan>> InternalDdManager<DdType::Sylvan>::createDdVariables(uint64_t numberOfLayers,
203 boost::optional<uint_fast64_t>
const& position) {
204 STORM_LOG_THROW(!position, storm::exceptions::NotSupportedException,
"The manager does not support ordered insertion.");
206 std::vector<InternalBdd<DdType::Sylvan>> result;
208 for (uint64_t layer = 0; layer < numberOfLayers; ++layer) {
209 result.emplace_back(InternalBdd<DdType::Sylvan>(
this, sylvan::Bdd::bddVar(nextFreeVariableIndex)));
210 ++nextFreeVariableIndex;
216bool InternalDdManager<DdType::Sylvan>::supportsOrderedInsertion()
const {
220void InternalDdManager<DdType::Sylvan>::allowDynamicReordering(
bool) {
221 STORM_LOG_THROW(
false, storm::exceptions::NotSupportedException,
"Operation is not supported by sylvan.");
224bool InternalDdManager<DdType::Sylvan>::isDynamicReorderingAllowed()
const {
225 STORM_LOG_THROW(
false, storm::exceptions::NotSupportedException,
"Operation is not supported by sylvan.");
228void InternalDdManager<DdType::Sylvan>::triggerReordering() {
229 STORM_LOG_THROW(
false, storm::exceptions::NotSupportedException,
"Operation is not supported by sylvan.");
232void InternalDdManager<DdType::Sylvan>::debugCheck()
const {
233 STORM_LOG_THROW(
false, storm::exceptions::NotSupportedException,
"Operation is not supported by sylvan.");
236void InternalDdManager<DdType::Sylvan>::execute(std::function<
void()>
const& f)
const {
238 std::exception_ptr e =
nullptr;
242 RUN(execute_sylvan, &f, &e);
247 RUN(execute_sylvan, &f, &e);
250 std::rethrow_exception(e);
254uint_fast64_t InternalDdManager<DdType::Sylvan>::getNumberOfDdVariables()
const {
255 return nextFreeVariableIndex;
260 "This version of Storm was compiled without support for Sylvan. Yet, a method was called that requires this support. Please choose a "
261 "version of Storm with Sylvan support.");
268 "This version of Storm was compiled without support for Sylvan. Yet, a method was called that requires this support. Please choose a "
269 "version of Storm with Sylvan support.");
272template<
typename ValueType>
275 "This version of Storm was compiled without support for Sylvan. Yet, a method was called that requires this support. Please choose a "
276 "version of Storm with Sylvan support.");
281 "This version of Storm was compiled without support for Sylvan. Yet, a method was called that requires this support. Please choose a "
282 "version of Storm with Sylvan support.");
286 uint64_t numberOfDdVariables)
const {
288 "This version of Storm was compiled without support for Sylvan. Yet, a method was called that requires this support. Please choose a "
289 "version of Storm with Sylvan support.");
292template<
typename ValueType>
295 "This version of Storm was compiled without support for Sylvan. Yet, a method was called that requires this support. Please choose a "
296 "version of Storm with Sylvan support.");
299template<
typename ValueType>
302 "This version of Storm was compiled without support for Sylvan. Yet, a method was called that requires this support. Please choose a "
303 "version of Storm with Sylvan support.");
306template<
typename ValueType>
309 "This version of Storm was compiled without support for Sylvan. Yet, a method was called that requires this support. Please choose a "
310 "version of Storm with Sylvan support.");
314 boost::optional<uint_fast64_t>
const& position) {
316 "This version of Storm was compiled without support for Sylvan. Yet, a method was called that requires this support. Please choose a "
317 "version of Storm with Sylvan support.");
322 "This version of Storm was compiled without support for Sylvan. Yet, a method was called that requires this support. Please choose a "
323 "version of Storm with Sylvan support.");
328 "This version of Storm was compiled without support for Sylvan. Yet, a method was called that requires this support. Please choose a "
329 "version of Storm with Sylvan support.");
334 "This version of Storm was compiled without support for Sylvan. Yet, a method was called that requires this support. Please choose a "
335 "version of Storm with Sylvan support.");
340 "This version of Storm was compiled without support for Sylvan. Yet, a method was called that requires this support. Please choose a "
341 "version of Storm with Sylvan support.");
346 "This version of Storm was compiled without support for Sylvan. Yet, a method was called that requires this support. Please choose a "
347 "version of Storm with Sylvan support.");
352 "This version of Storm was compiled without support for Sylvan. Yet, a method was called that requires this support. Please choose a "
353 "version of Storm with Sylvan support.");
358 "This version of Storm was compiled without support for Sylvan. Yet, a method was called that requires this support. Please choose a "
359 "version of Storm with Sylvan support.");
363#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)