From e8fab0718c387baf732a949a9188b30a410f63bf Mon Sep 17 00:00:00 2001 From: dehnert Date: Wed, 21 Jun 2017 20:37:24 +0200 Subject: [PATCH] fixed issues in division operations of sylvan for rational numbers and rational functions (division by zero not correctly handled) --- .../3rdparty/sylvan/src/storm_wrapper.cpp | 19 +++++++++++++++++++ resources/3rdparty/sylvan/src/storm_wrapper.h | 2 ++ .../3rdparty/sylvan/src/sylvan_mtbdd_storm.c | 12 +++++++++--- .../src/sylvan_storm_rational_function.c | 3 +++ .../sylvan/src/sylvan_storm_rational_number.c | 3 +++ 5 files changed, 36 insertions(+), 3 deletions(-) diff --git a/resources/3rdparty/sylvan/src/storm_wrapper.cpp b/resources/3rdparty/sylvan/src/storm_wrapper.cpp index 4678bec87..b042227fd 100644 --- a/resources/3rdparty/sylvan/src/storm_wrapper.cpp +++ b/resources/3rdparty/sylvan/src/storm_wrapper.cpp @@ -109,6 +109,15 @@ storm_rational_number_ptr storm_rational_number_get_one() { return (storm_rational_number_ptr)result_srn; } +storm_rational_number_ptr storm_rational_number_get_infinity() { +#ifndef RATIONAL_NUMBER_THREAD_SAFE + std::lock_guard lock(rationalNumberMutex); +#endif + + storm::RationalNumber* result_srn = new storm::RationalNumber(storm::utility::infinity()); + return (storm_rational_number_ptr)result_srn; +} + int storm_rational_number_is_zero(storm_rational_number_ptr a) { #ifndef RATIONAL_NUMBER_THREAD_SAFE std::lock_guard lock(rationalNumberMutex); @@ -404,6 +413,16 @@ storm_rational_function_ptr storm_rational_function_get_one() { return (storm_rational_function_ptr)result_srf; } +storm_rational_function_ptr storm_rational_function_get_infinity() { +#ifndef RATIONAL_FUNCTION_THREAD_SAFE + std::lock_guard lock(rationalFunctionMutex); +#endif + + storm::RationalFunction* result_srf = new storm::RationalFunction(storm::utility::infinity()); + return (storm_rational_function_ptr)result_srf; +} + + int storm_rational_function_is_zero(storm_rational_function_ptr a) { #ifndef RATIONAL_FUNCTION_THREAD_SAFE std::lock_guard lock(rationalFunctionMutex); diff --git a/resources/3rdparty/sylvan/src/storm_wrapper.h b/resources/3rdparty/sylvan/src/storm_wrapper.h index 810269ecc..2fb6bb214 100644 --- a/resources/3rdparty/sylvan/src/storm_wrapper.h +++ b/resources/3rdparty/sylvan/src/storm_wrapper.h @@ -25,6 +25,7 @@ extern "C" { storm_rational_number_ptr storm_rational_number_clone(storm_rational_number_ptr a); storm_rational_number_ptr storm_rational_number_get_zero(); storm_rational_number_ptr storm_rational_number_get_one(); + storm_rational_number_ptr storm_rational_number_get_infinity(); int storm_rational_number_is_zero(storm_rational_number_ptr a); uint64_t storm_rational_number_hash(storm_rational_number_ptr const a, uint64_t const seed); double storm_rational_number_get_value_double(storm_rational_number_ptr a); @@ -71,6 +72,7 @@ extern "C" { storm_rational_function_ptr storm_rational_function_clone(storm_rational_function_ptr a); storm_rational_function_ptr storm_rational_function_get_zero(); storm_rational_function_ptr storm_rational_function_get_one(); + storm_rational_number_ptr storm_rational_function_get_infinity(); int storm_rational_function_is_zero(storm_rational_function_ptr a); uint64_t storm_rational_function_hash(storm_rational_function_ptr const a, uint64_t const seed); double storm_rational_function_get_value_double(storm_rational_function_ptr a); diff --git a/resources/3rdparty/sylvan/src/sylvan_mtbdd_storm.c b/resources/3rdparty/sylvan/src/sylvan_mtbdd_storm.c index 1915886f1..76792affe 100644 --- a/resources/3rdparty/sylvan/src/sylvan_mtbdd_storm.c +++ b/resources/3rdparty/sylvan/src/sylvan_mtbdd_storm.c @@ -43,10 +43,16 @@ TASK_IMPL_2(MTBDD, mtbdd_op_divide, MTBDD*, pa, MTBDD*, pb) double vval_a = *(double*)&val_a; double vval_b = *(double*)&val_b; if (vval_a == 0.0) return a; - else if (vval_b == 0.0) return b; - else { + else if (vval_b == 0.0) { + if (vval_a > 0.0) { + return mtbdd_double(INFINITY); + } else { + return mtbdd_double(-INFINITY); + } + return b; + } else { MTBDD result; - if (vval_a == 0.0 || vval_b == 1.0) result = a; + if (vval_b == 1.0) result = a; result = mtbdd_double(vval_a / vval_b); return result; } diff --git a/resources/3rdparty/sylvan/src/sylvan_storm_rational_function.c b/resources/3rdparty/sylvan/src/sylvan_storm_rational_function.c index a890e28a9..dc9e97aa2 100644 --- a/resources/3rdparty/sylvan/src/sylvan_storm_rational_function.c +++ b/resources/3rdparty/sylvan/src/sylvan_storm_rational_function.c @@ -194,9 +194,12 @@ TASK_IMPL_2(MTBDD, sylvan_storm_rational_function_op_divide, MTBDD*, pa, MTBDD*, /* If both leaves, compute division */ if (mtbdd_isleaf(a) && mtbdd_isleaf(b)) { storm_rational_function_ptr ma = mtbdd_getstorm_rational_function_ptr(a); + storm_rational_function_ptr mb = mtbdd_getstorm_rational_function_ptr(b); storm_rational_function_ptr mres; if (storm_rational_function_is_zero(ma)) { mres = storm_rational_function_get_zero(); + } else if (storm_rational_function_is_zero(mb)) { + mres = storm_rational_function_get_infinity(); } else { storm_rational_function_ptr mb = mtbdd_getstorm_rational_function_ptr(b); mres = storm_rational_function_divide(ma, mb); diff --git a/resources/3rdparty/sylvan/src/sylvan_storm_rational_number.c b/resources/3rdparty/sylvan/src/sylvan_storm_rational_number.c index 076e75442..d2f59450c 100644 --- a/resources/3rdparty/sylvan/src/sylvan_storm_rational_number.c +++ b/resources/3rdparty/sylvan/src/sylvan_storm_rational_number.c @@ -194,9 +194,12 @@ TASK_IMPL_2(MTBDD, sylvan_storm_rational_number_op_divide, MTBDD*, pa, MTBDD*, p /* If both leaves, compute division */ if (mtbdd_isleaf(a) && mtbdd_isleaf(b)) { storm_rational_number_ptr ma = mtbdd_getstorm_rational_number_ptr(a); + storm_rational_number_ptr mb = mtbdd_getstorm_rational_number_ptr(b); storm_rational_number_ptr mres; if (storm_rational_number_is_zero(ma)) { mres = storm_rational_number_get_zero(); + } else if (storm_rational_number_is_zero(mb)) { + mres = storm_rational_number_get_infinity(); } else { storm_rational_number_ptr mb = mtbdd_getstorm_rational_number_ptr(b); mres = storm_rational_number_divide(ma, mb);