diff --git a/src/storm/storage/expressions/ExpressionEvaluator.cpp b/src/storm/storage/expressions/ExpressionEvaluator.cpp index b167c6034..0436a8ef2 100644 --- a/src/storm/storage/expressions/ExpressionEvaluator.cpp +++ b/src/storm/storage/expressions/ExpressionEvaluator.cpp @@ -53,6 +53,11 @@ namespace storm { rationalNumberVisitor.setMapping(variable, storm::utility::convertNumber(value)); } + void ExpressionEvaluator::setRationalValue(storm::expressions::Variable const& variable, RationalNumber const& value) { + ExprtkExpressionEvaluatorBase::setRationalValue(variable, storm::utility::convertNumber(value)); + rationalNumberVisitor.setMapping(variable, value); + } + RationalNumber ExpressionEvaluator::asRational(Expression const& expression) const { RationalNumber result = this->rationalNumberVisitor.toRationalNumber(expression); return result; @@ -78,6 +83,12 @@ namespace storm { rationalFunctionVisitor.setMapping(variable, storm::utility::convertNumber(value)); } + void ExpressionEvaluator::setRationalValue(storm::expressions::Variable const& variable, RationalFunction const& value) { + STORM_LOG_ASSERT(storm::utility::isConstant(value), "Value for rational variable is not a constant."); + ExprtkExpressionEvaluatorBase::setRationalValue(variable, storm::utility::convertNumber(value)); + rationalFunctionVisitor.setMapping(variable, value); + } + RationalFunction ExpressionEvaluator::asRational(Expression const& expression) const { return this->rationalFunctionVisitor.toRationalFunction(expression); } diff --git a/src/storm/storage/expressions/ExpressionEvaluator.h b/src/storm/storage/expressions/ExpressionEvaluator.h index 5d867e8be..5461f9c4f 100644 --- a/src/storm/storage/expressions/ExpressionEvaluator.h +++ b/src/storm/storage/expressions/ExpressionEvaluator.h @@ -45,6 +45,11 @@ namespace storm { void setIntegerValue(storm::expressions::Variable const& variable, int_fast64_t value) override; void setRationalValue(storm::expressions::Variable const& variable, double value) override; + // Sets a rational value from a RationalNumber. + // Note: If an expression contains the given variable and is evaluated to int or bool, the value is internally considered as a double. + void setRationalValue(storm::expressions::Variable const& variable, storm::RationalNumber const& value); + + RationalNumber asRational(Expression const& expression) const override; private: @@ -60,6 +65,10 @@ namespace storm { void setBooleanValue(storm::expressions::Variable const& variable, bool value) override; void setIntegerValue(storm::expressions::Variable const& variable, int_fast64_t value) override; void setRationalValue(storm::expressions::Variable const& variable, double value) override; + + // Sets a rational value from a RationalFunction. The function needs to be constant. + // Note: If an expression contains the given variable and is evaluated to int or bool, the value is internally considered as a double. + void setRationalValue(storm::expressions::Variable const& variable, storm::RationalFunction const& value); RationalFunction asRational(Expression const& expression) const override;