dehnert
7 years ago
16 changed files with 248 additions and 55 deletions
-
20resources/3rdparty/sylvan/src/storm_wrapper.cpp
-
5resources/3rdparty/sylvan/src/storm_wrapper.h
-
31resources/3rdparty/sylvan/src/sylvan_mtbdd_storm.c
-
9resources/3rdparty/sylvan/src/sylvan_mtbdd_storm.h
-
2resources/3rdparty/sylvan/src/sylvan_obj_mtbdd_storm.hpp
-
6resources/3rdparty/sylvan/src/sylvan_obj_storm.cpp
-
1src/storm/solver/IterativeMinMaxLinearEquationSolver.cpp
-
18src/storm/storage/dd/Add.cpp
-
7src/storm/storage/dd/Add.h
-
6src/storm/storage/dd/cudd/InternalCuddAdd.cpp
-
9src/storm/storage/dd/cudd/InternalCuddAdd.h
-
13src/storm/storage/dd/sylvan/InternalSylvanAdd.cpp
-
17src/storm/storage/dd/sylvan/InternalSylvanAdd.h
-
79src/storm/utility/KwekMehlhorn.cpp
-
60src/storm/utility/KwekMehlhorn.h
-
20src/test/storm/storage/SylvanDdTest.cpp
@ -0,0 +1,79 @@ |
|||
#include "storm/utility/KwekMehlhorn.h"
|
|||
|
|||
#include "storm/adapters/RationalNumberAdapter.h"
|
|||
|
|||
#include "storm/utility/constants.h"
|
|||
#include "storm/utility/macros.h"
|
|||
|
|||
#include "storm/exceptions/PrecisionExceededException.h"
|
|||
|
|||
namespace storm { |
|||
namespace utility{ |
|||
namespace kwek_mehlhorn { |
|||
|
|||
template<typename IntegerType> |
|||
std::pair<IntegerType, IntegerType> findRational(IntegerType const& alpha, IntegerType const& beta, IntegerType const& gamma, IntegerType const& delta) { |
|||
std::pair<IntegerType, IntegerType> alphaDivBetaPair = storm::utility::divide(alpha, beta); |
|||
std::pair<IntegerType, IntegerType> gammaDivDeltaPair = storm::utility::divide(gamma, delta); |
|||
|
|||
if (alphaDivBetaPair.first == gammaDivDeltaPair.first && !storm::utility::isZero(alphaDivBetaPair.second)) { |
|||
std::pair<IntegerType, IntegerType> subresult = findRational(delta, gammaDivDeltaPair.second, beta, alphaDivBetaPair.second); |
|||
auto result = std::make_pair(alphaDivBetaPair.first * subresult.first + subresult.second, subresult.first); |
|||
|
|||
return result; |
|||
} else { |
|||
auto result = std::make_pair(storm::utility::isZero(alphaDivBetaPair.second) ? alphaDivBetaPair.first : alphaDivBetaPair.first + storm::utility::one<IntegerType>(), storm::utility::one<IntegerType>()); |
|||
return result; |
|||
} |
|||
} |
|||
|
|||
template<typename RationalType, typename ImpreciseType> |
|||
std::pair<typename NumberTraits<RationalType>::IntegerType, typename NumberTraits<RationalType>::IntegerType> truncateToRational(ImpreciseType const& value, uint64_t precision) { |
|||
typedef typename NumberTraits<RationalType>::IntegerType IntegerType; |
|||
|
|||
IntegerType powerOfTen = storm::utility::pow(storm::utility::convertNumber<IntegerType>(10ull), precision); |
|||
IntegerType truncated = storm::utility::trunc<RationalType>(value * powerOfTen); |
|||
return std::make_pair(truncated, powerOfTen); |
|||
} |
|||
|
|||
template<typename RationalType> |
|||
std::pair<typename NumberTraits<RationalType>::IntegerType, typename NumberTraits<RationalType>::IntegerType> truncateToRational(double const& value, uint64_t precision) { |
|||
STORM_LOG_THROW(precision < 17, storm::exceptions::PrecisionExceededException, "Exceeded precision of double, consider switching to rational numbers."); |
|||
|
|||
double powerOfTen = std::pow(10, precision); |
|||
double truncated = storm::utility::trunc<double>(value * powerOfTen); |
|||
return std::make_pair(truncated, powerOfTen); |
|||
} |
|||
|
|||
template<typename RationalType, typename ImpreciseType> |
|||
RationalType findRational(uint64_t precision, ImpreciseType const& value) { |
|||
typedef typename NumberTraits<RationalType>::IntegerType IntegerType; |
|||
|
|||
std::pair<IntegerType, IntegerType> truncatedFraction = truncateToRational<RationalType>(value, precision); |
|||
std::pair<IntegerType, IntegerType> result = findRational<IntegerType>(truncatedFraction.first, truncatedFraction.second, truncatedFraction.first + storm::utility::one<IntegerType>(), truncatedFraction.second); |
|||
|
|||
// Convert one of the arguments to a rational type to not get integer division.
|
|||
return storm::utility::convertNumber<RationalType>(result.first) / result.second; |
|||
} |
|||
|
|||
template<typename RationalType, typename ImpreciseType> |
|||
RationalType sharpen(uint64_t precision, ImpreciseType const& value) { |
|||
ImpreciseType integer = storm::utility::floor(value); |
|||
ImpreciseType fraction = value - integer; |
|||
auto rational = findRational<RationalType>(precision, fraction); |
|||
return storm::utility::convertNumber<RationalType>(integer) + rational; |
|||
} |
|||
|
|||
template<typename RationalType, typename ImpreciseType> |
|||
void sharpen(uint64_t precision, std::vector<ImpreciseType> const& input, std::vector<RationalType>& output) { |
|||
for (uint64_t index = 0; index < input.size(); ++index) { |
|||
output[index] = sharpen<RationalType, ImpreciseType>(precision, input[index]); |
|||
} |
|||
} |
|||
|
|||
template void sharpen(uint64_t precision, std::vector<double> const& input, std::vector<storm::RationalNumber>& output); |
|||
template void sharpen(uint64_t precision, std::vector<storm::RationalNumber> const& input, std::vector<storm::RationalNumber>& output); |
|||
|
|||
} |
|||
} |
|||
} |
@ -1,68 +1,32 @@ |
|||
#pragma once |
|||
|
|||
#include "storm/utility/constants.h" |
|||
#include "storm/utility/macros.h" |
|||
#include <utility> |
|||
#include <cstdint> |
|||
#include <vector> |
|||
|
|||
#include "storm/exceptions/PrecisionExceededException.h" |
|||
#include "storm/utility/NumberTraits.h" |
|||
|
|||
namespace storm { |
|||
namespace utility{ |
|||
namespace kwek_mehlhorn { |
|||
|
|||
template<typename IntegerType> |
|||
std::pair<IntegerType, IntegerType> findRational(IntegerType const& alpha, IntegerType const& beta, IntegerType const& gamma, IntegerType const& delta) { |
|||
std::pair<IntegerType, IntegerType> alphaDivBetaPair = storm::utility::divide(alpha, beta); |
|||
std::pair<IntegerType, IntegerType> gammaDivDeltaPair = storm::utility::divide(gamma, delta); |
|||
|
|||
if (alphaDivBetaPair.first == gammaDivDeltaPair.first && !storm::utility::isZero(alphaDivBetaPair.second)) { |
|||
std::pair<IntegerType, IntegerType> subresult = findRational(delta, gammaDivDeltaPair.second, beta, alphaDivBetaPair.second); |
|||
auto result = std::make_pair(alphaDivBetaPair.first * subresult.first + subresult.second, subresult.first); |
|||
|
|||
return result; |
|||
} else { |
|||
auto result = std::make_pair(storm::utility::isZero(alphaDivBetaPair.second) ? alphaDivBetaPair.first : alphaDivBetaPair.first + storm::utility::one<IntegerType>(), storm::utility::one<IntegerType>()); |
|||
return result; |
|||
} |
|||
} |
|||
std::pair<IntegerType, IntegerType> findRational(IntegerType const& alpha, IntegerType const& beta, IntegerType const& gamma, IntegerType const& delta); |
|||
|
|||
template<typename RationalType, typename ImpreciseType> |
|||
std::pair<typename NumberTraits<RationalType>::IntegerType, typename NumberTraits<RationalType>::IntegerType> truncateToRational(ImpreciseType const& value, uint64_t precision) { |
|||
typedef typename NumberTraits<RationalType>::IntegerType IntegerType; |
|||
|
|||
IntegerType powerOfTen = storm::utility::pow(storm::utility::convertNumber<IntegerType>(10ull), precision); |
|||
IntegerType truncated = storm::utility::trunc<RationalType>(value * powerOfTen); |
|||
return std::make_pair(truncated, powerOfTen); |
|||
} |
|||
std::pair<typename NumberTraits<RationalType>::IntegerType, typename NumberTraits<RationalType>::IntegerType> truncateToRational(ImpreciseType const& value, uint64_t precision); |
|||
|
|||
template<typename RationalType> |
|||
std::pair<typename NumberTraits<RationalType>::IntegerType, typename NumberTraits<RationalType>::IntegerType> truncateToRational(double const& value, uint64_t precision) { |
|||
STORM_LOG_THROW(precision < 17, storm::exceptions::PrecisionExceededException, "Exceeded precision of double, consider switching to rational numbers."); |
|||
|
|||
double powerOfTen = std::pow(10, precision); |
|||
double truncated = storm::utility::trunc<double>(value * powerOfTen); |
|||
return std::make_pair(truncated, powerOfTen); |
|||
} |
|||
std::pair<typename NumberTraits<RationalType>::IntegerType, typename NumberTraits<RationalType>::IntegerType> truncateToRational(double const& value, uint64_t precision); |
|||
|
|||
template<typename RationalType, typename ImpreciseType> |
|||
RationalType findRational(uint64_t precision, ImpreciseType const& value) { |
|||
typedef typename NumberTraits<RationalType>::IntegerType IntegerType; |
|||
|
|||
std::pair<IntegerType, IntegerType> truncatedFraction = truncateToRational<RationalType>(value, precision); |
|||
std::pair<IntegerType, IntegerType> result = findRational<IntegerType>(truncatedFraction.first, truncatedFraction.second, truncatedFraction.first + storm::utility::one<IntegerType>(), truncatedFraction.second); |
|||
|
|||
// Convert one of the arguments to a rational type to not get integer division. |
|||
return storm::utility::convertNumber<RationalType>(result.first) / result.second; |
|||
} |
|||
RationalType findRational(uint64_t precision, ImpreciseType const& value); |
|||
|
|||
template<typename RationalType, typename ImpreciseType> |
|||
RationalType sharpen(uint64_t precision, ImpreciseType const& value); |
|||
|
|||
template<typename RationalType, typename ImpreciseType> |
|||
void sharpen(uint64_t precision, std::vector<ImpreciseType> const& input, std::vector<RationalType>& output) { |
|||
for (uint64_t index = 0; index < input.size(); ++index) { |
|||
ImpreciseType integer = storm::utility::floor(input[index]); |
|||
ImpreciseType fraction = input[index] - integer; |
|||
auto rational = findRational<RationalType>(precision, fraction); |
|||
output[index] = storm::utility::convertNumber<RationalType>(integer) + rational; |
|||
} |
|||
} |
|||
void sharpen(uint64_t precision, std::vector<ImpreciseType> const& input, std::vector<RationalType>& output); |
|||
|
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue