Browse Source

fixed issues in division operations of sylvan for rational numbers and rational functions (division by zero not correctly handled)

tempestpy_adaptions
dehnert 8 years ago
parent
commit
e8fab0718c
  1. 19
      resources/3rdparty/sylvan/src/storm_wrapper.cpp
  2. 2
      resources/3rdparty/sylvan/src/storm_wrapper.h
  3. 12
      resources/3rdparty/sylvan/src/sylvan_mtbdd_storm.c
  4. 3
      resources/3rdparty/sylvan/src/sylvan_storm_rational_function.c
  5. 3
      resources/3rdparty/sylvan/src/sylvan_storm_rational_number.c

19
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<std::mutex> lock(rationalNumberMutex);
#endif
storm::RationalNumber* result_srn = new storm::RationalNumber(storm::utility::infinity<storm::RationalNumber>());
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<std::mutex> 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<std::mutex> lock(rationalFunctionMutex);
#endif
storm::RationalFunction* result_srf = new storm::RationalFunction(storm::utility::infinity<storm::RationalFunction>());
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<std::mutex> lock(rationalFunctionMutex);

2
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);

12
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;
}

3
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);

3
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);

Loading…
Cancel
Save