Browse Source
Fixed Sylvan bugs.
Fixed Sylvan bugs.
Added a lot of debugging options and output, controlled by #define's.
Added more template specializations for storm::RationalFunction.
Former-commit-id: 416c32d196
tempestpy_adaptions
PBerger
9 years ago
13 changed files with 925 additions and 389 deletions
-
324resources/3rdparty/sylvan/src/storm_function_wrapper.cpp
-
15resources/3rdparty/sylvan/src/storm_function_wrapper.h
-
127resources/3rdparty/sylvan/src/sylvan_mtbdd.c
-
69resources/3rdparty/sylvan/src/sylvan_mtbdd_storm.c
-
6resources/3rdparty/sylvan/src/sylvan_obj.cpp
-
22resources/3rdparty/sylvan/src/sylvan_obj_mtbdd_storm.hpp
-
30resources/3rdparty/sylvan/src/sylvan_obj_storm.cpp
-
99resources/3rdparty/sylvan/src/sylvan_storm_rational_function.c
-
4resources/3rdparty/sylvan/src/sylvan_storm_rational_function.h
-
16src/storage/dd/DdManager.cpp
-
240src/storage/dd/sylvan/InternalSylvanAdd.cpp
-
341src/storage/dd/sylvan/InternalSylvanDdManager.cpp
-
21test/functional/storage/SylvanDdTest.cpp
@ -1,132 +1,192 @@ |
|||||
#include "storm_function_wrapper.h"
|
|
||||
|
|
||||
#include <cstring>
|
|
||||
#include "src/adapters/CarlAdapter.h"
|
|
||||
|
|
||||
void storm_rational_function_init(storm_rational_function_ptr* a) { |
|
||||
storm_rational_function_ptr srf_ptr = static_cast<storm_rational_function_ptr>(malloc(sizeof(storm_rational_function_ptr_struct))); |
|
||||
|
|
||||
if (srf_ptr == nullptr) { |
|
||||
return; |
|
||||
} |
|
||||
|
|
||||
srf_ptr->storm_rational_function = new storm::RationalFunction(*(storm::RationalFunction*)((*a)->storm_rational_function)); |
|
||||
|
|
||||
*a = srf_ptr; |
|
||||
} |
|
||||
|
|
||||
void storm_rational_function_destroy(storm_rational_function_ptr a) { |
|
||||
delete (storm::RationalFunction*)a->storm_rational_function; |
|
||||
a->storm_rational_function = nullptr; |
|
||||
free((void*)a); |
|
||||
} |
|
||||
|
|
||||
int storm_rational_function_equals(storm_rational_function_ptr a, storm_rational_function_ptr b) { |
|
||||
storm::RationalFunction* srf_a = (storm::RationalFunction*)a->storm_rational_function; |
|
||||
storm::RationalFunction* srf_b = (storm::RationalFunction*)b->storm_rational_function; |
|
||||
|
|
||||
if (*srf_a == *srf_b) { |
|
||||
return 0; |
|
||||
} |
|
||||
|
|
||||
return -1; |
|
||||
} |
|
||||
|
|
||||
storm_rational_function_ptr storm_rational_function_plus(storm_rational_function_ptr a, storm_rational_function_ptr b) { |
|
||||
storm::RationalFunction& srf_a = *(storm::RationalFunction*)a->storm_rational_function; |
|
||||
storm::RationalFunction& srf_b = *(storm::RationalFunction*)b->storm_rational_function; |
|
||||
|
|
||||
storm::RationalFunction* result_srf = new storm::RationalFunction(srf_a); |
|
||||
*result_srf += srf_b; |
|
||||
|
|
||||
storm_rational_function_ptr result = (storm_rational_function_ptr)malloc(sizeof(storm_rational_function_ptr_struct)); |
|
||||
result->storm_rational_function = (void*)result_srf; |
|
||||
|
|
||||
return result; |
|
||||
} |
|
||||
|
|
||||
storm_rational_function_ptr storm_rational_function_minus(storm_rational_function_ptr a, storm_rational_function_ptr b) { |
|
||||
storm::RationalFunction& srf_a = *(storm::RationalFunction*)a->storm_rational_function; |
|
||||
storm::RationalFunction& srf_b = *(storm::RationalFunction*)b->storm_rational_function; |
|
||||
|
|
||||
storm::RationalFunction* result_srf = new storm::RationalFunction(srf_a); |
|
||||
*result_srf -= srf_b; |
|
||||
|
|
||||
storm_rational_function_ptr result = (storm_rational_function_ptr)malloc(sizeof(storm_rational_function_ptr_struct)); |
|
||||
result->storm_rational_function = (void*)result_srf; |
|
||||
|
|
||||
return result; |
|
||||
} |
|
||||
|
|
||||
storm_rational_function_ptr storm_rational_function_times(storm_rational_function_ptr a, storm_rational_function_ptr b) { |
|
||||
storm::RationalFunction& srf_a = *(storm::RationalFunction*)a->storm_rational_function; |
|
||||
storm::RationalFunction& srf_b = *(storm::RationalFunction*)b->storm_rational_function; |
|
||||
|
|
||||
storm::RationalFunction* result_srf = new storm::RationalFunction(srf_a); |
|
||||
*result_srf *= srf_b; |
|
||||
|
|
||||
storm_rational_function_ptr result = (storm_rational_function_ptr)malloc(sizeof(storm_rational_function_ptr_struct)); |
|
||||
result->storm_rational_function = (void*)result_srf; |
|
||||
|
|
||||
return result; |
|
||||
} |
|
||||
|
|
||||
storm_rational_function_ptr storm_rational_function_divide(storm_rational_function_ptr a, storm_rational_function_ptr b) { |
|
||||
storm::RationalFunction& srf_a = *(storm::RationalFunction*)a->storm_rational_function; |
|
||||
storm::RationalFunction& srf_b = *(storm::RationalFunction*)b->storm_rational_function; |
|
||||
|
|
||||
storm::RationalFunction* result_srf = new storm::RationalFunction(srf_a); |
|
||||
*result_srf /= srf_b; |
|
||||
|
|
||||
storm_rational_function_ptr result = (storm_rational_function_ptr)malloc(sizeof(storm_rational_function_ptr_struct)); |
|
||||
result->storm_rational_function = (void*)result_srf; |
|
||||
|
|
||||
return result; |
|
||||
} |
|
||||
|
|
||||
uint64_t storm_rational_function_hash(storm_rational_function_ptr const a, uint64_t const seed) { |
|
||||
storm::RationalFunction& srf_a = *(storm::RationalFunction*)a->storm_rational_function; |
|
||||
|
|
||||
size_t hash = carl::hash_value(srf_a); |
|
||||
uint64_t result = hash ^ seed; |
|
||||
|
|
||||
return result; |
|
||||
} |
|
||||
|
|
||||
storm_rational_function_ptr storm_rational_function_negate(storm_rational_function_ptr a) { |
|
||||
storm::RationalFunction& srf_a = *(storm::RationalFunction*)a->storm_rational_function; |
|
||||
|
|
||||
storm::RationalFunction* result_srf = new storm::RationalFunction(srf_a); |
|
||||
*result_srf = -srf_a; |
|
||||
|
|
||||
storm_rational_function_ptr result = (storm_rational_function_ptr)malloc(sizeof(storm_rational_function_ptr_struct)); |
|
||||
result->storm_rational_function = (void*)result_srf; |
|
||||
|
|
||||
return result; |
|
||||
} |
|
||||
|
|
||||
int storm_rational_function_is_zero(storm_rational_function_ptr a) { |
|
||||
storm::RationalFunction& srf_a = *(storm::RationalFunction*)a->storm_rational_function; |
|
||||
|
|
||||
if (srf_a.isZero()) { |
|
||||
return 1; |
|
||||
} else { |
|
||||
return 0; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
storm_rational_function_ptr storm_rational_function_get_zero() { |
|
||||
static storm::RationalFunction zeroFunction(0); |
|
||||
static storm_rational_function_ptr_struct functionStruct; |
|
||||
functionStruct.storm_rational_function = (void*)&zeroFunction; |
|
||||
|
|
||||
return &functionStruct; |
|
||||
} |
|
||||
|
|
||||
storm_rational_function_ptr storm_rational_function_get_one() { |
|
||||
static storm::RationalFunction oneFunction(1); |
|
||||
static storm_rational_function_ptr_struct functionStruct; |
|
||||
functionStruct.storm_rational_function = (void*)&oneFunction; |
|
||||
|
|
||||
return &functionStruct; |
|
||||
} |
|
||||
|
#include "storm_function_wrapper.h"
|
||||
|
|
||||
|
#include <cstring>
|
||||
|
#include <iostream>
|
||||
|
#include <sstream>
|
||||
|
#include "src/adapters/CarlAdapter.h"
|
||||
|
|
||||
|
#undef DEBUG_STORM_FUNCTION_WRAPPER
|
||||
|
|
||||
|
#ifdef DEBUG_STORM_FUNCTION_WRAPPER
|
||||
|
#define LOG_I(funcName) std::cout << "Entering function " << funcName << std::endl;
|
||||
|
#define LOG_O(funcName) std::cout << "Leaving function " << funcName << std::endl;
|
||||
|
#else
|
||||
|
#define LOG_I(funcName)
|
||||
|
#define LOG_O(funcName)
|
||||
|
#endif
|
||||
|
|
||||
|
void storm_rational_function_init(storm_rational_function_ptr* a) { |
||||
|
LOG_I("init") |
||||
|
storm_rational_function_ptr srf_ptr = new storm::RationalFunction(*((storm::RationalFunction*)(*a))); |
||||
|
|
||||
|
if (srf_ptr == nullptr) { |
||||
|
std::cerr << "Could not allocate memory in storm_rational_function_init()!" << std::endl; |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
*a = srf_ptr; |
||||
|
LOG_O("init") |
||||
|
} |
||||
|
|
||||
|
void storm_rational_function_destroy(storm_rational_function_ptr a) { |
||||
|
LOG_I("destroy") |
||||
|
delete (storm::RationalFunction*)a; |
||||
|
LOG_O("destroy") |
||||
|
} |
||||
|
|
||||
|
int storm_rational_function_equals(storm_rational_function_ptr a, storm_rational_function_ptr b) { |
||||
|
LOG_I("equals") |
||||
|
storm::RationalFunction& srf_a = *(storm::RationalFunction*)a; |
||||
|
storm::RationalFunction& srf_b = *(storm::RationalFunction*)b; |
||||
|
|
||||
|
LOG_O("equals") |
||||
|
|
||||
|
int result = 0; |
||||
|
if (srf_a == srf_b) { |
||||
|
result = 1; |
||||
|
} |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
storm_rational_function_ptr storm_rational_function_plus(storm_rational_function_ptr a, storm_rational_function_ptr b) { |
||||
|
LOG_I("plus") |
||||
|
storm::RationalFunction& srf_a = *(storm::RationalFunction*)a; |
||||
|
storm::RationalFunction& srf_b = *(storm::RationalFunction*)b; |
||||
|
|
||||
|
storm::RationalFunction* result_srf = new storm::RationalFunction(srf_a); |
||||
|
if (result_srf == nullptr) { |
||||
|
std::cerr << "Could not allocate memory in storm_rational_function_plus()!" << std::endl; |
||||
|
return (storm_rational_function_ptr)nullptr; |
||||
|
} |
||||
|
|
||||
|
*result_srf += srf_b; |
||||
|
|
||||
|
storm_rational_function_ptr result = (storm_rational_function_ptr)result_srf; |
||||
|
|
||||
|
LOG_O("plus") |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
storm_rational_function_ptr storm_rational_function_minus(storm_rational_function_ptr a, storm_rational_function_ptr b) { |
||||
|
LOG_I("minus") |
||||
|
storm::RationalFunction& srf_a = *(storm::RationalFunction*)a; |
||||
|
storm::RationalFunction& srf_b = *(storm::RationalFunction*)b; |
||||
|
|
||||
|
storm::RationalFunction* result_srf = new storm::RationalFunction(srf_a); |
||||
|
if (result_srf == nullptr) { |
||||
|
std::cerr << "Could not allocate memory in storm_rational_function_minus()!" << std::endl; |
||||
|
return (storm_rational_function_ptr)nullptr; |
||||
|
} |
||||
|
|
||||
|
*result_srf -= srf_b; |
||||
|
|
||||
|
storm_rational_function_ptr result = (storm_rational_function_ptr)result_srf; |
||||
|
|
||||
|
LOG_O("minus") |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
storm_rational_function_ptr storm_rational_function_times(storm_rational_function_ptr a, storm_rational_function_ptr b) { |
||||
|
LOG_I("times") |
||||
|
storm::RationalFunction& srf_a = *(storm::RationalFunction*)a; |
||||
|
storm::RationalFunction& srf_b = *(storm::RationalFunction*)b; |
||||
|
|
||||
|
storm::RationalFunction* result_srf = new storm::RationalFunction(srf_a); |
||||
|
if (result_srf == nullptr) { |
||||
|
std::cerr << "Could not allocate memory in storm_rational_function_times()!" << std::endl; |
||||
|
return (storm_rational_function_ptr)nullptr; |
||||
|
} |
||||
|
|
||||
|
*result_srf *= srf_b; |
||||
|
|
||||
|
storm_rational_function_ptr result = (storm_rational_function_ptr)result_srf; |
||||
|
|
||||
|
LOG_O("times") |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
storm_rational_function_ptr storm_rational_function_divide(storm_rational_function_ptr a, storm_rational_function_ptr b) { |
||||
|
LOG_I("divide") |
||||
|
storm::RationalFunction& srf_a = *(storm::RationalFunction*)a; |
||||
|
storm::RationalFunction& srf_b = *(storm::RationalFunction*)b; |
||||
|
|
||||
|
storm::RationalFunction* result_srf = new storm::RationalFunction(srf_a); |
||||
|
if (result_srf == nullptr) { |
||||
|
std::cerr << "Could not allocate memory in storm_rational_function_divide()!" << std::endl; |
||||
|
return (storm_rational_function_ptr)nullptr; |
||||
|
} |
||||
|
|
||||
|
*result_srf /= srf_b; |
||||
|
|
||||
|
storm_rational_function_ptr result = (storm_rational_function_ptr)result_srf; |
||||
|
|
||||
|
LOG_O("divide") |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
uint64_t storm_rational_function_hash(storm_rational_function_ptr const a, uint64_t const seed) { |
||||
|
LOG_I("hash") |
||||
|
storm::RationalFunction& srf_a = *(storm::RationalFunction*)a; |
||||
|
|
||||
|
size_t hash = carl::hash_value(srf_a); |
||||
|
uint64_t result = hash ^ seed; |
||||
|
|
||||
|
LOG_O("hash") |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
storm_rational_function_ptr storm_rational_function_negate(storm_rational_function_ptr a) { |
||||
|
LOG_I("negate") |
||||
|
storm::RationalFunction& srf_a = *(storm::RationalFunction*)a; |
||||
|
|
||||
|
storm::RationalFunction* result_srf = new storm::RationalFunction(srf_a); |
||||
|
if (result_srf == nullptr) { |
||||
|
std::cerr << "Could not allocate memory in storm_rational_function_negate()!" << std::endl; |
||||
|
return (storm_rational_function_ptr)nullptr; |
||||
|
} |
||||
|
|
||||
|
*result_srf = -srf_a; |
||||
|
|
||||
|
storm_rational_function_ptr result = (storm_rational_function_ptr)result_srf; |
||||
|
|
||||
|
LOG_O("negate") |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
int storm_rational_function_is_zero(storm_rational_function_ptr a) { |
||||
|
LOG_I("isZero") |
||||
|
storm::RationalFunction& srf_a = *(storm::RationalFunction*)a; |
||||
|
|
||||
|
if (srf_a.isZero()) { |
||||
|
return 1; |
||||
|
} else { |
||||
|
return 0; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
storm_rational_function_ptr storm_rational_function_get_zero() { |
||||
|
static storm::RationalFunction zeroFunction(0); |
||||
|
LOG_I("getZero") |
||||
|
//return new storm::RationalFunction(0);
|
||||
|
return (storm_rational_function_ptr)(&zeroFunction); |
||||
|
} |
||||
|
|
||||
|
storm_rational_function_ptr storm_rational_function_get_one() { |
||||
|
static storm::RationalFunction oneFunction(1); |
||||
|
LOG_I("getOne") |
||||
|
//return new storm::RationalFunction(1);
|
||||
|
return (storm_rational_function_ptr)(&oneFunction); |
||||
|
} |
||||
|
|
||||
|
void print_storm_rational_function(storm_rational_function_ptr a) { |
||||
|
storm::RationalFunction& srf_a = *(storm::RationalFunction*)a; |
||||
|
std::cout << srf_a << std::flush; |
||||
|
} |
||||
|
|
||||
|
void print_storm_rational_function_to_file(storm_rational_function_ptr a, FILE* out) { |
||||
|
std::stringstream ss; |
||||
|
storm::RationalFunction& srf_a = *(storm::RationalFunction*)a; |
||||
|
ss << srf_a; |
||||
|
std::string s = ss.str(); |
||||
|
fprintf(out, "%s", s.c_str()); |
||||
|
} |
@ -1,175 +1,166 @@ |
|||||
#include "src/storage/dd/sylvan/InternalSylvanDdManager.h"
|
|
||||
|
|
||||
#include <cmath>
|
|
||||
|
|
||||
#include "src/settings/SettingsManager.h"
|
|
||||
#include "src/settings/modules/SylvanSettings.h"
|
|
||||
|
|
||||
#include "src/utility/constants.h"
|
|
||||
#include "src/utility/macros.h"
|
|
||||
#include "src/exceptions/NotSupportedException.h"
|
|
||||
|
|
||||
#include "src/utility/sylvan.h"
|
|
||||
|
|
||||
#include "storm-config.h"
|
|
||||
// TODO: Remove this later on.
|
|
||||
#ifndef STORM_HAVE_CARL
|
|
||||
#define STORM_HAVE_CARL 1
|
|
||||
#endif
|
|
||||
|
|
||||
namespace storm { |
|
||||
namespace dd { |
|
||||
uint_fast64_t InternalDdManager<DdType::Sylvan>::numberOfInstances = 0; |
|
||||
|
|
||||
// It is important that the variable pairs start at an even offset, because sylvan assumes this to be true for
|
|
||||
// some operations.
|
|
||||
uint_fast64_t InternalDdManager<DdType::Sylvan>::nextFreeVariableIndex = 0; |
|
||||
|
|
||||
uint_fast64_t findLargestPowerOfTwoFitting(uint_fast64_t number) { |
|
||||
for (uint_fast64_t index = 0; index < 64; ++index) { |
|
||||
if ((number & (1ull << (63 - index))) != 0) { |
|
||||
return 63 - index; |
|
||||
} |
|
||||
} |
|
||||
return 0; |
|
||||
} |
|
||||
|
|
||||
InternalDdManager<DdType::Sylvan>::InternalDdManager() { |
|
||||
if (numberOfInstances == 0) { |
|
||||
// Initialize lace: auto-detect number of workers.
|
|
||||
lace_init(storm::settings::getModule<storm::settings::modules::SylvanSettings>().getNumberOfThreads(), 1000000); |
|
||||
lace_startup(0, 0, 0); |
|
||||
|
|
||||
// Each node takes 24 bytes and the maximal memory is specified in megabytes.
|
|
||||
uint_fast64_t totalNodesToStore = storm::settings::getModule<storm::settings::modules::SylvanSettings>().getMaximalMemory() * 1024 * 1024 / 24; |
|
||||
|
|
||||
// Compute the power of two that still fits within the total numbers to store.
|
|
||||
uint_fast64_t powerOfTwo = findLargestPowerOfTwoFitting(totalNodesToStore); |
|
||||
|
|
||||
sylvan::Sylvan::initPackage(1ull << std::max(16ull, powerOfTwo > 24 ? powerOfTwo - 8 : 0ull), 1ull << (powerOfTwo - 1), 1ull << std::max(16ull, powerOfTwo > 24 ? powerOfTwo - 12 : 0ull), 1ull << (powerOfTwo - 1)); |
|
||||
sylvan::Sylvan::initBdd(1); |
|
||||
sylvan::Sylvan::initMtbdd(); |
|
||||
} |
|
||||
++numberOfInstances; |
|
||||
} |
|
||||
|
|
||||
InternalDdManager<DdType::Sylvan>::~InternalDdManager() { |
|
||||
--numberOfInstances; |
|
||||
if (numberOfInstances == 0) { |
|
||||
// Enable this to print the sylvan statistics to a file.
|
|
||||
// FILE* filePointer = fopen("sylvan.stats", "w");
|
|
||||
// sylvan_stats_report(filePointer, 0);
|
|
||||
// fclose(filePointer);
|
|
||||
|
|
||||
sylvan::Sylvan::quitPackage(); |
|
||||
lace_exit(); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
InternalBdd<DdType::Sylvan> InternalDdManager<DdType::Sylvan>::getBddOne() const { |
|
||||
return InternalBdd<DdType::Sylvan>(this, sylvan::Bdd::bddOne()); |
|
||||
} |
|
||||
|
|
||||
template<> |
|
||||
InternalAdd<DdType::Sylvan, double> InternalDdManager<DdType::Sylvan>::getAddOne() const { |
|
||||
return InternalAdd<DdType::Sylvan, double>(this, sylvan::Mtbdd::doubleTerminal(storm::utility::one<double>())); |
|
||||
} |
|
||||
|
|
||||
template<> |
|
||||
InternalAdd<DdType::Sylvan, uint_fast64_t> InternalDdManager<DdType::Sylvan>::getAddOne() const { |
|
||||
return InternalAdd<DdType::Sylvan, uint_fast64_t>(this, sylvan::Mtbdd::int64Terminal(storm::utility::one<uint_fast64_t>())); |
|
||||
} |
|
||||
|
|
||||
#ifdef STORM_HAVE_CARL
|
|
||||
template<> |
|
||||
InternalAdd<DdType::Sylvan, storm::RationalFunction> InternalDdManager<DdType::Sylvan>::getAddOne() const { |
|
||||
storm::RationalFunction rationalFunction = storm::utility::one<storm::RationalFunction>(); |
|
||||
storm_rational_function_ptr_struct helperStruct; |
|
||||
helperStruct.storm_rational_function = (void*)(&rationalFunction); |
|
||||
uint64_t value = (uint64_t)&helperStruct; |
|
||||
|
|
||||
return InternalAdd<DdType::Sylvan, storm::RationalFunction>(this, sylvan::Mtbdd::terminal(sylvan_storm_rational_function_get_type(), value)); |
|
||||
} |
|
||||
#endif
|
|
||||
|
|
||||
InternalBdd<DdType::Sylvan> InternalDdManager<DdType::Sylvan>::getBddZero() const { |
|
||||
return InternalBdd<DdType::Sylvan>(this, sylvan::Bdd::bddZero()); |
|
||||
} |
|
||||
|
|
||||
template<> |
|
||||
InternalAdd<DdType::Sylvan, double> InternalDdManager<DdType::Sylvan>::getAddZero() const { |
|
||||
return InternalAdd<DdType::Sylvan, double>(this, sylvan::Mtbdd::doubleTerminal(storm::utility::zero<double>())); |
|
||||
} |
|
||||
|
|
||||
template<> |
|
||||
InternalAdd<DdType::Sylvan, uint_fast64_t> InternalDdManager<DdType::Sylvan>::getAddZero() const { |
|
||||
return InternalAdd<DdType::Sylvan, uint_fast64_t>(this, sylvan::Mtbdd::int64Terminal(storm::utility::zero<uint_fast64_t>())); |
|
||||
} |
|
||||
|
|
||||
#ifdef STORM_HAVE_CARL
|
|
||||
template<> |
|
||||
InternalAdd<DdType::Sylvan, storm::RationalFunction> InternalDdManager<DdType::Sylvan>::getAddZero() const { |
|
||||
storm::RationalFunction rationalFunction = storm::utility::zero<storm::RationalFunction>(); |
|
||||
storm_rational_function_ptr_struct helperStruct; |
|
||||
helperStruct.storm_rational_function = (void*)(&rationalFunction); |
|
||||
uint64_t value = (uint64_t)&helperStruct; |
|
||||
|
|
||||
return InternalAdd<DdType::Sylvan, storm::RationalFunction>(this, sylvan::Mtbdd::terminal(sylvan_storm_rational_function_get_type(), value)); |
|
||||
} |
|
||||
#endif
|
|
||||
|
|
||||
template<> |
|
||||
InternalAdd<DdType::Sylvan, double> InternalDdManager<DdType::Sylvan>::getConstant(double const& value) const { |
|
||||
return InternalAdd<DdType::Sylvan, double>(this, sylvan::Mtbdd::doubleTerminal(value)); |
|
||||
} |
|
||||
|
|
||||
template<> |
|
||||
InternalAdd<DdType::Sylvan, uint_fast64_t> InternalDdManager<DdType::Sylvan>::getConstant(uint_fast64_t const& value) const { |
|
||||
return InternalAdd<DdType::Sylvan, uint_fast64_t>(this, sylvan::Mtbdd::int64Terminal(value)); |
|
||||
} |
|
||||
|
|
||||
#ifdef STORM_HAVE_CARL
|
|
||||
template<> |
|
||||
InternalAdd<DdType::Sylvan, storm::RationalFunction> InternalDdManager<DdType::Sylvan>::getConstant(storm::RationalFunction const& value) const { |
|
||||
return InternalAdd<DdType::Sylvan, storm::RationalFunction>(this, sylvan::Mtbdd::stormRationalFunctionTerminal(value)); |
|
||||
} |
|
||||
#endif
|
|
||||
|
|
||||
std::pair<InternalBdd<DdType::Sylvan>, InternalBdd<DdType::Sylvan>> InternalDdManager<DdType::Sylvan>::createNewDdVariablePair() { |
|
||||
InternalBdd<DdType::Sylvan> first = InternalBdd<DdType::Sylvan>(this, sylvan::Bdd::bddVar(nextFreeVariableIndex)); |
|
||||
InternalBdd<DdType::Sylvan> second = InternalBdd<DdType::Sylvan>(this, sylvan::Bdd::bddVar(nextFreeVariableIndex + 1)); |
|
||||
nextFreeVariableIndex += 2; |
|
||||
return std::make_pair(first, second); |
|
||||
} |
|
||||
|
|
||||
void InternalDdManager<DdType::Sylvan>::allowDynamicReordering(bool value) { |
|
||||
STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "Operation is not supported by sylvan."); |
|
||||
} |
|
||||
|
|
||||
bool InternalDdManager<DdType::Sylvan>::isDynamicReorderingAllowed() const { |
|
||||
STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "Operation is not supported by sylvan."); |
|
||||
} |
|
||||
|
|
||||
void InternalDdManager<DdType::Sylvan>::triggerReordering() { |
|
||||
STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "Operation is not supported by sylvan."); |
|
||||
} |
|
||||
|
|
||||
template InternalAdd<DdType::Sylvan, double> InternalDdManager<DdType::Sylvan>::getAddOne() const; |
|
||||
template InternalAdd<DdType::Sylvan, uint_fast64_t> InternalDdManager<DdType::Sylvan>::getAddOne() const; |
|
||||
#ifdef STORM_HAVE_CARL
|
|
||||
template InternalAdd<DdType::Sylvan, storm::RationalFunction> InternalDdManager<DdType::Sylvan>::getAddOne() const; |
|
||||
#endif
|
|
||||
|
|
||||
template InternalAdd<DdType::Sylvan, double> InternalDdManager<DdType::Sylvan>::getAddZero() const; |
|
||||
template InternalAdd<DdType::Sylvan, uint_fast64_t> InternalDdManager<DdType::Sylvan>::getAddZero() const; |
|
||||
#ifdef STORM_HAVE_CARL
|
|
||||
template InternalAdd<DdType::Sylvan, storm::RationalFunction> InternalDdManager<DdType::Sylvan>::getAddZero() const; |
|
||||
#endif
|
|
||||
|
|
||||
template InternalAdd<DdType::Sylvan, double> InternalDdManager<DdType::Sylvan>::getConstant(double const& value) const; |
|
||||
template InternalAdd<DdType::Sylvan, uint_fast64_t> InternalDdManager<DdType::Sylvan>::getConstant(uint_fast64_t const& value) const; |
|
||||
#ifdef STORM_HAVE_CARL
|
|
||||
template InternalAdd<DdType::Sylvan, storm::RationalFunction> InternalDdManager<DdType::Sylvan>::getConstant(storm::RationalFunction const& value) const; |
|
||||
#endif
|
|
||||
} |
|
||||
} |
|
||||
|
#include "src/storage/dd/sylvan/InternalSylvanDdManager.h"
|
||||
|
|
||||
|
#include <cmath>
|
||||
|
#include <iostream>
|
||||
|
|
||||
|
#include "src/settings/SettingsManager.h"
|
||||
|
#include "src/settings/modules/SylvanSettings.h"
|
||||
|
|
||||
|
#include "src/utility/constants.h"
|
||||
|
#include "src/utility/macros.h"
|
||||
|
#include "src/exceptions/NotSupportedException.h"
|
||||
|
|
||||
|
#include "src/utility/sylvan.h"
|
||||
|
|
||||
|
#include "storm-config.h"
|
||||
|
// TODO: Remove this later on.
|
||||
|
#ifndef STORM_HAVE_CARL
|
||||
|
#define STORM_HAVE_CARL 1
|
||||
|
#endif
|
||||
|
|
||||
|
namespace storm { |
||||
|
namespace dd { |
||||
|
uint_fast64_t InternalDdManager<DdType::Sylvan>::numberOfInstances = 0; |
||||
|
|
||||
|
// It is important that the variable pairs start at an even offset, because sylvan assumes this to be true for
|
||||
|
// some operations.
|
||||
|
uint_fast64_t InternalDdManager<DdType::Sylvan>::nextFreeVariableIndex = 0; |
||||
|
|
||||
|
uint_fast64_t findLargestPowerOfTwoFitting(uint_fast64_t number) { |
||||
|
for (uint_fast64_t index = 0; index < 64; ++index) { |
||||
|
if ((number & (1ull << (63 - index))) != 0) { |
||||
|
return 63 - index; |
||||
|
} |
||||
|
} |
||||
|
return 0; |
||||
|
} |
||||
|
|
||||
|
InternalDdManager<DdType::Sylvan>::InternalDdManager() { |
||||
|
if (numberOfInstances == 0) { |
||||
|
// Initialize lace: auto-detect number of workers.
|
||||
|
lace_init(storm::settings::getModule<storm::settings::modules::SylvanSettings>().getNumberOfThreads(), 1000000); |
||||
|
lace_startup(0, 0, 0); |
||||
|
|
||||
|
// Each node takes 24 bytes and the maximal memory is specified in megabytes.
|
||||
|
uint_fast64_t totalNodesToStore = storm::settings::getModule<storm::settings::modules::SylvanSettings>().getMaximalMemory() * 1024 * 1024 / 24; |
||||
|
|
||||
|
// Compute the power of two that still fits within the total numbers to store.
|
||||
|
uint_fast64_t powerOfTwo = findLargestPowerOfTwoFitting(totalNodesToStore); |
||||
|
|
||||
|
sylvan::Sylvan::initPackage(1ull << std::max(16ull, powerOfTwo > 24 ? powerOfTwo - 8 : 0ull), 1ull << (powerOfTwo - 1), 1ull << std::max(16ull, powerOfTwo > 24 ? powerOfTwo - 12 : 0ull), 1ull << (powerOfTwo - 1)); |
||||
|
sylvan::Sylvan::initBdd(1); |
||||
|
sylvan::Sylvan::initMtbdd(); |
||||
|
} |
||||
|
++numberOfInstances; |
||||
|
} |
||||
|
|
||||
|
InternalDdManager<DdType::Sylvan>::~InternalDdManager() { |
||||
|
--numberOfInstances; |
||||
|
if (numberOfInstances == 0) { |
||||
|
// Enable this to print the sylvan statistics to a file.
|
||||
|
// FILE* filePointer = fopen("sylvan.stats", "w");
|
||||
|
// sylvan_stats_report(filePointer, 0);
|
||||
|
// fclose(filePointer);
|
||||
|
|
||||
|
sylvan::Sylvan::quitPackage(); |
||||
|
lace_exit(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
InternalBdd<DdType::Sylvan> InternalDdManager<DdType::Sylvan>::getBddOne() const { |
||||
|
return InternalBdd<DdType::Sylvan>(this, sylvan::Bdd::bddOne()); |
||||
|
} |
||||
|
|
||||
|
template<> |
||||
|
InternalAdd<DdType::Sylvan, double> InternalDdManager<DdType::Sylvan>::getAddOne() const { |
||||
|
return InternalAdd<DdType::Sylvan, double>(this, sylvan::Mtbdd::doubleTerminal(storm::utility::one<double>())); |
||||
|
} |
||||
|
|
||||
|
template<> |
||||
|
InternalAdd<DdType::Sylvan, uint_fast64_t> InternalDdManager<DdType::Sylvan>::getAddOne() const { |
||||
|
return InternalAdd<DdType::Sylvan, uint_fast64_t>(this, sylvan::Mtbdd::int64Terminal(storm::utility::one<uint_fast64_t>())); |
||||
|
} |
||||
|
|
||||
|
#ifdef STORM_HAVE_CARL
|
||||
|
template<> |
||||
|
InternalAdd<DdType::Sylvan, storm::RationalFunction> InternalDdManager<DdType::Sylvan>::getAddOne() const { |
||||
|
return InternalAdd<DdType::Sylvan, storm::RationalFunction>(this, sylvan::Mtbdd::stormRationalFunctionTerminal(storm::utility::one<storm::RationalFunction>())); |
||||
|
} |
||||
|
#endif
|
||||
|
|
||||
|
InternalBdd<DdType::Sylvan> InternalDdManager<DdType::Sylvan>::getBddZero() const { |
||||
|
return InternalBdd<DdType::Sylvan>(this, sylvan::Bdd::bddZero()); |
||||
|
} |
||||
|
|
||||
|
template<> |
||||
|
InternalAdd<DdType::Sylvan, double> InternalDdManager<DdType::Sylvan>::getAddZero() const { |
||||
|
return InternalAdd<DdType::Sylvan, double>(this, sylvan::Mtbdd::doubleTerminal(storm::utility::zero<double>())); |
||||
|
} |
||||
|
|
||||
|
template<> |
||||
|
InternalAdd<DdType::Sylvan, uint_fast64_t> InternalDdManager<DdType::Sylvan>::getAddZero() const { |
||||
|
return InternalAdd<DdType::Sylvan, uint_fast64_t>(this, sylvan::Mtbdd::int64Terminal(storm::utility::zero<uint_fast64_t>())); |
||||
|
} |
||||
|
|
||||
|
#ifdef STORM_HAVE_CARL
|
||||
|
template<> |
||||
|
InternalAdd<DdType::Sylvan, storm::RationalFunction> InternalDdManager<DdType::Sylvan>::getAddZero() const { |
||||
|
return InternalAdd<DdType::Sylvan, storm::RationalFunction>(this, sylvan::Mtbdd::stormRationalFunctionTerminal(storm::utility::zero<storm::RationalFunction>())); |
||||
|
} |
||||
|
#endif
|
||||
|
|
||||
|
template<> |
||||
|
InternalAdd<DdType::Sylvan, double> InternalDdManager<DdType::Sylvan>::getConstant(double const& value) const { |
||||
|
return InternalAdd<DdType::Sylvan, double>(this, sylvan::Mtbdd::doubleTerminal(value)); |
||||
|
} |
||||
|
|
||||
|
template<> |
||||
|
InternalAdd<DdType::Sylvan, uint_fast64_t> InternalDdManager<DdType::Sylvan>::getConstant(uint_fast64_t const& value) const { |
||||
|
return InternalAdd<DdType::Sylvan, uint_fast64_t>(this, sylvan::Mtbdd::int64Terminal(value)); |
||||
|
} |
||||
|
|
||||
|
#ifdef STORM_HAVE_CARL
|
||||
|
template<> |
||||
|
InternalAdd<DdType::Sylvan, storm::RationalFunction> InternalDdManager<DdType::Sylvan>::getConstant(storm::RationalFunction const& value) const { |
||||
|
return InternalAdd<DdType::Sylvan, storm::RationalFunction>(this, sylvan::Mtbdd::stormRationalFunctionTerminal(value)); |
||||
|
} |
||||
|
#endif
|
||||
|
|
||||
|
std::pair<InternalBdd<DdType::Sylvan>, InternalBdd<DdType::Sylvan>> InternalDdManager<DdType::Sylvan>::createNewDdVariablePair() { |
||||
|
InternalBdd<DdType::Sylvan> first = InternalBdd<DdType::Sylvan>(this, sylvan::Bdd::bddVar(nextFreeVariableIndex)); |
||||
|
InternalBdd<DdType::Sylvan> second = InternalBdd<DdType::Sylvan>(this, sylvan::Bdd::bddVar(nextFreeVariableIndex + 1)); |
||||
|
nextFreeVariableIndex += 2; |
||||
|
return std::make_pair(first, second); |
||||
|
} |
||||
|
|
||||
|
void InternalDdManager<DdType::Sylvan>::allowDynamicReordering(bool value) { |
||||
|
STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "Operation is not supported by sylvan."); |
||||
|
} |
||||
|
|
||||
|
bool InternalDdManager<DdType::Sylvan>::isDynamicReorderingAllowed() const { |
||||
|
STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "Operation is not supported by sylvan."); |
||||
|
} |
||||
|
|
||||
|
void InternalDdManager<DdType::Sylvan>::triggerReordering() { |
||||
|
STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "Operation is not supported by sylvan."); |
||||
|
} |
||||
|
|
||||
|
template InternalAdd<DdType::Sylvan, double> InternalDdManager<DdType::Sylvan>::getAddOne() const; |
||||
|
template InternalAdd<DdType::Sylvan, uint_fast64_t> InternalDdManager<DdType::Sylvan>::getAddOne() const; |
||||
|
#ifdef STORM_HAVE_CARL
|
||||
|
template InternalAdd<DdType::Sylvan, storm::RationalFunction> InternalDdManager<DdType::Sylvan>::getAddOne() const; |
||||
|
#endif
|
||||
|
|
||||
|
template InternalAdd<DdType::Sylvan, double> InternalDdManager<DdType::Sylvan>::getAddZero() const; |
||||
|
template InternalAdd<DdType::Sylvan, uint_fast64_t> InternalDdManager<DdType::Sylvan>::getAddZero() const; |
||||
|
#ifdef STORM_HAVE_CARL
|
||||
|
template InternalAdd<DdType::Sylvan, storm::RationalFunction> InternalDdManager<DdType::Sylvan>::getAddZero() const; |
||||
|
#endif
|
||||
|
|
||||
|
template InternalAdd<DdType::Sylvan, double> InternalDdManager<DdType::Sylvan>::getConstant(double const& value) const; |
||||
|
template InternalAdd<DdType::Sylvan, uint_fast64_t> InternalDdManager<DdType::Sylvan>::getConstant(uint_fast64_t const& value) const; |
||||
|
#ifdef STORM_HAVE_CARL
|
||||
|
template InternalAdd<DdType::Sylvan, storm::RationalFunction> InternalDdManager<DdType::Sylvan>::getConstant(storm::RationalFunction const& value) const; |
||||
|
#endif
|
||||
|
} |
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue