Browse Source

ToRationalNumberVisitor: make evaluator optional

tempestpy_adaptions
JK 8 years ago
parent
commit
e37d0bd552
  1. 13
      src/storm/storage/expressions/ToRationalNumberVisitor.cpp
  2. 7
      src/storm/storage/expressions/ToRationalNumberVisitor.h

13
src/storm/storage/expressions/ToRationalNumberVisitor.cpp

@ -7,6 +7,11 @@
namespace storm {
namespace expressions {
template<typename RationalNumberType>
ToRationalNumberVisitor<RationalNumberType>::ToRationalNumberVisitor() : ExpressionVisitor() {
// Intentionally left empty.
}
template<typename RationalNumberType>
ToRationalNumberVisitor<RationalNumberType>::ToRationalNumberVisitor(ExpressionEvaluatorBase<RationalNumberType> const& evaluator) : ExpressionVisitor(), evaluator(evaluator) {
// Intentionally left empty.
@ -19,7 +24,13 @@ namespace storm {
template<typename RationalNumberType>
boost::any ToRationalNumberVisitor<RationalNumberType>::visit(IfThenElseExpression const& expression, boost::any const& data) {
bool conditionValue = evaluator.asBool(expression.getCondition());
bool conditionValue;
if (evaluator) {
conditionValue = evaluator->asBool(expression.getCondition());
} else {
// no evaluator, fall back to evaluateBool
conditionValue = expression.getCondition()->evaluateAsBool();
}
if (conditionValue) {
return expression.getThenExpression()->accept(*this, data);
} else {

7
src/storm/storage/expressions/ToRationalNumberVisitor.h

@ -16,7 +16,8 @@ namespace storm {
template<typename RationalNumberType>
class ToRationalNumberVisitor : public ExpressionVisitor {
public:
ToRationalNumberVisitor(ExpressionEvaluatorBase<RationalNumberType> const& evaluator);
ToRationalNumberVisitor();
ToRationalNumberVisitor(ExpressionEvaluatorBase<RationalNumberType> const& evaluator);
RationalNumberType toRationalNumber(Expression const& expression);
@ -36,8 +37,8 @@ namespace storm {
private:
std::unordered_map<storm::expressions::Variable, RationalNumberType> valueMapping;
// A reference to an expression evaluator (mainly for resolving the boolean condition in IfThenElse expressions)
ExpressionEvaluatorBase<RationalNumberType> const& evaluator;
// An optional reference to an expression evaluator (mainly for resolving the boolean condition in IfThenElse expressions)
boost::optional<ExpressionEvaluatorBase<RationalNumberType> const&> evaluator;
};
}
}
Loading…
Cancel
Save