Browse Source

Expression evaluator can now set rational values from a RationalNumber/RationalFunction

tempestpy_adaptions
TimQu 6 years ago
parent
commit
5a36fa0075
  1. 11
      src/storm/storage/expressions/ExpressionEvaluator.cpp
  2. 9
      src/storm/storage/expressions/ExpressionEvaluator.h

11
src/storm/storage/expressions/ExpressionEvaluator.cpp

@ -53,6 +53,11 @@ namespace storm {
rationalNumberVisitor.setMapping(variable, storm::utility::convertNumber<RationalNumber>(value));
}
void ExpressionEvaluator<RationalNumber>::setRationalValue(storm::expressions::Variable const& variable, RationalNumber const& value) {
ExprtkExpressionEvaluatorBase<RationalNumber>::setRationalValue(variable, storm::utility::convertNumber<double>(value));
rationalNumberVisitor.setMapping(variable, value);
}
RationalNumber ExpressionEvaluator<RationalNumber>::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<RationalFunction>(value));
}
void ExpressionEvaluator<RationalFunction>::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<RationalFunction>::setRationalValue(variable, storm::utility::convertNumber<double>(value));
rationalFunctionVisitor.setMapping(variable, value);
}
RationalFunction ExpressionEvaluator<RationalFunction>::asRational(Expression const& expression) const {
return this->rationalFunctionVisitor.toRationalFunction(expression);
}

9
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:
@ -61,6 +66,10 @@ 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 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;
private:

Loading…
Cancel
Save