diff --git a/src/storm/storage/expressions/BaseExpression.cpp b/src/storm/storage/expressions/BaseExpression.cpp index 7780351eb..4e07fd089 100644 --- a/src/storm/storage/expressions/BaseExpression.cpp +++ b/src/storm/storage/expressions/BaseExpression.cpp @@ -5,6 +5,7 @@ #include "storm/exceptions/InvalidAccessException.h" #include "storm/storage/expressions/Expressions.h" +#include "storm/storage/expressions/ToRationalNumberVisitor.h" namespace storm { namespace expressions { @@ -51,7 +52,12 @@ namespace storm { double BaseExpression::evaluateAsDouble(Valuation const*) const { STORM_LOG_THROW(false, storm::exceptions::InvalidTypeException, "Unable to evaluate expression as double."); } - + + storm::RationalNumber BaseExpression::evaluateAsRational() const { + ToRationalNumberVisitor v; + return v.toRationalNumber(this->toExpression()); + } + uint_fast64_t BaseExpression::getArity() const { return 0; } diff --git a/src/storm/storage/expressions/BaseExpression.h b/src/storm/storage/expressions/BaseExpression.h index 325aa33d4..83c76f7ae 100644 --- a/src/storm/storage/expressions/BaseExpression.h +++ b/src/storm/storage/expressions/BaseExpression.h @@ -7,6 +7,7 @@ #include #include +#include "storm/adapters/NumberAdapter.h" #include "storm/storage/expressions/Type.h" #include "storm/utility/OsDetection.h" #include @@ -90,6 +91,15 @@ namespace storm { */ virtual double evaluateAsDouble(Valuation const* valuation = nullptr) const; + /*! + * Evaluates the expression and returns the resulting rational number. + * If the return type of the expression is not a rational number + * or the expression could not be evaluated, an exception is thrown. + * + * @return The rational number value of the expression. + */ + virtual storm::RationalNumber evaluateAsRational() const; + /*! * Returns the arity of the expression. *