Browse Source
Merge pull request #117 from tquatmann/revised-constants-comparator
Merge pull request #117 from tquatmann/revised-constants-comparator
Revised ConstantsComparatortempestpy_adaptions
Sebastian Junges
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 100 additions and 246 deletions
-
3src/storm/builder/ExplicitModelBuilder.h
-
6src/storm/storage/Distribution.h
-
5src/storm/storage/DistributionWithReward.h
-
4src/storm/storage/bisimulation/BisimulationDecomposition.h
-
4src/storm/storage/bisimulation/DeterministicModelBisimulationDecomposition.h
-
4src/storm/storage/bisimulation/NondeterministicModelBisimulationDecomposition.h
-
173src/storm/utility/ConstantsComparator.cpp
-
113src/storm/utility/ConstantsComparator.h
@ -1,108 +1,43 @@ |
|||||
#ifndef STORM_UTILITY_CONSTANTSCOMPARATOR_H_ |
|
||||
#define STORM_UTILITY_CONSTANTSCOMPARATOR_H_ |
|
||||
|
#pragma once |
||||
|
|
||||
#include "storm/adapters/RationalFunctionAdapter.h" |
|
||||
|
#include <type_traits> |
||||
|
#include "storm/adapters/RationalNumberAdapter.h" |
||||
|
|
||||
namespace storm { |
namespace storm { |
||||
namespace utility { |
namespace utility { |
||||
|
|
||||
// A class that can be used for comparing constants. |
// A class that can be used for comparing constants. |
||||
template<typename ValueType> |
|
||||
|
template<typename ValueType, typename Enable = void> |
||||
class ConstantsComparator { |
class ConstantsComparator { |
||||
public: |
|
||||
// This needs to be in here, otherwise the template specializations are not used properly. |
|
||||
|
public: |
||||
ConstantsComparator() = default; |
ConstantsComparator() = default; |
||||
|
|
||||
bool isOne(ValueType const& value) const; |
bool isOne(ValueType const& value) const; |
||||
|
|
||||
bool isZero(ValueType const& value) const; |
bool isZero(ValueType const& value) const; |
||||
|
|
||||
bool isEqual(ValueType const& value1, ValueType const& value2) const; |
bool isEqual(ValueType const& value1, ValueType const& value2) const; |
||||
|
|
||||
bool isConstant(ValueType const& value) const; |
bool isConstant(ValueType const& value) const; |
||||
|
|
||||
bool isInfinity(ValueType const& value) const; |
|
||||
|
|
||||
bool isLess(ValueType const& value1, ValueType const& value2) const; |
bool isLess(ValueType const& value1, ValueType const& value2) const; |
||||
}; |
}; |
||||
|
|
||||
// For floats we specialize this class and consider the comparison modulo some predefined precision. |
|
||||
template<> |
|
||||
class ConstantsComparator<float> { |
|
||||
public: |
|
||||
ConstantsComparator(); |
|
||||
|
|
||||
ConstantsComparator(float precision); |
|
||||
|
|
||||
bool isOne(float const& value) const; |
|
||||
|
|
||||
bool isZero(float const& value) const; |
|
||||
|
|
||||
bool isEqual(float const& value1, float const& value2) const; |
|
||||
|
|
||||
bool isConstant(float const& value) const; |
|
||||
|
|
||||
bool isInfinity(float const& value) const; |
|
||||
|
|
||||
bool isLess(float const& value1, float const& value2) const; |
|
||||
|
|
||||
private: |
|
||||
// The precision used for comparisons. |
|
||||
float precision; |
|
||||
}; |
|
||||
|
|
||||
// For doubles we specialize this class and consider the comparison modulo some predefined precision. |
|
||||
template<> |
|
||||
class ConstantsComparator<double> { |
|
||||
public: |
|
||||
ConstantsComparator(); |
|
||||
|
|
||||
ConstantsComparator(double precision, bool relative = false); |
|
||||
|
|
||||
bool isOne(double const& value) const; |
|
||||
|
|
||||
bool isZero(double const& value) const; |
|
||||
|
|
||||
bool isInfinity(double const& value) const; |
|
||||
|
|
||||
bool isEqual(double const& value1, double const& value2) const; |
|
||||
|
|
||||
bool isConstant(double const& value) const; |
|
||||
|
|
||||
bool isLess(double const& value1, double const& value2) const; |
|
||||
|
|
||||
private: |
|
||||
// The precision used for comparisons. |
|
||||
double precision; |
|
||||
|
|
||||
// Whether to use relative comparison for equality. |
|
||||
bool relative; |
|
||||
}; |
|
||||
|
// Specialization for numbers where there can be a precision |
||||
|
template<typename ValueType> |
||||
|
using ConstantsComparatorEnablePrecision = |
||||
|
typename std::enable_if_t<std::is_same<ValueType, double>::value || std::is_same<ValueType, storm::RationalNumber>::value>; |
||||
|
|
||||
// For rational numbers we specialize this class and consider the comparison modulo some predefined precision. |
|
||||
template<> |
|
||||
class ConstantsComparator<storm::RationalNumber> { |
|
||||
public: |
|
||||
|
template<typename ValueType> |
||||
|
class ConstantsComparator<ValueType, ConstantsComparatorEnablePrecision<ValueType>> { |
||||
|
public: |
||||
ConstantsComparator(); |
ConstantsComparator(); |
||||
|
ConstantsComparator(ValueType const& precision, bool const& relative = false); |
||||
|
bool isOne(ValueType const& value) const; |
||||
|
bool isZero(ValueType const& value) const; |
||||
|
bool isEqual(ValueType const& value1, ValueType const& value2) const; |
||||
|
bool isConstant(ValueType const& value) const; |
||||
|
bool isInfinity(ValueType const& value) const; |
||||
|
bool isLess(ValueType const& value1, ValueType const& value2) const; |
||||
|
|
||||
ConstantsComparator(storm::RationalNumber precision, bool relative); |
|
||||
|
|
||||
bool isOne(storm::RationalNumber const& value) const; |
|
||||
|
|
||||
bool isZero(storm::RationalNumber const& value) const; |
|
||||
|
|
||||
bool isEqual(storm::RationalNumber const& value1, storm::RationalNumber const& value2) const; |
|
||||
|
|
||||
bool isConstant(storm::RationalNumber const& value) const; |
|
||||
|
|
||||
bool isInfinity(storm::RationalNumber const& value) const; |
|
||||
|
|
||||
bool isLess(storm::RationalNumber const& value1, storm::RationalNumber const& value2) const; |
|
||||
|
|
||||
private: |
|
||||
storm::RationalNumber precision; |
|
||||
|
private: |
||||
|
ValueType precision; |
||||
bool relative; |
bool relative; |
||||
}; |
}; |
||||
} |
|
||||
} |
|
||||
|
|
||||
#endif /* STORM_UTILITY_CONSTANTSCOMPARATOR_H_ */ |
|
||||
|
} // namespace utility |
||||
|
} // namespace storm |
Write
Preview
Loading…
Cancel
Save
Reference in new issue