Browse Source

BaseExpression: evaluateAsRational

tempestpy_adaptions
JK 8 years ago
parent
commit
edee041b16
  1. 8
      src/storm/storage/expressions/BaseExpression.cpp
  2. 10
      src/storm/storage/expressions/BaseExpression.h

8
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<storm::RationalNumber> v;
return v.toRationalNumber(this->toExpression());
}
uint_fast64_t BaseExpression::getArity() const {
return 0;
}

10
src/storm/storage/expressions/BaseExpression.h

@ -7,6 +7,7 @@
#include <map>
#include <iostream>
#include "storm/adapters/NumberAdapter.h"
#include "storm/storage/expressions/Type.h"
#include "storm/utility/OsDetection.h"
#include <boost/any.hpp>
@ -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.
*

Loading…
Cancel
Save