Browse Source

backported a bugfix

Former-commit-id: 219e8e0e3b
tempestpy_adaptions
dehnert 9 years ago
parent
commit
1d56cf0430
  1. 24
      src/storage/expressions/ExprtkExpressionEvaluator.cpp
  2. 5
      src/storage/expressions/ExprtkExpressionEvaluator.h

24
src/storage/expressions/ExprtkExpressionEvaluator.cpp

@ -23,10 +23,10 @@ namespace storm {
template<typename RationalType>
bool ExprtkExpressionEvaluatorBase<RationalType>::asBool(Expression const& expression) const {
BaseExpression const* expressionPtr = expression.getBaseExpressionPointer().get();
auto const& expressionPair = this->compiledExpressions.find(expression.getBaseExpressionPointer().get());
std::shared_ptr<BaseExpression const> expressionPtr = expression.getBaseExpressionPointer();
auto const& expressionPair = this->compiledExpressions.find(expression.getBaseExpressionPointer());
if (expressionPair == this->compiledExpressions.end()) {
CompiledExpressionType const& compiledExpression = this->getCompiledExpression(expressionPtr);
CompiledExpressionType const& compiledExpression = this->getCompiledExpression(expression);
return compiledExpression.value() == ValueType(1);
}
return expressionPair->second.value() == ValueType(1);
@ -34,22 +34,22 @@ namespace storm {
template<typename RationalType>
int_fast64_t ExprtkExpressionEvaluatorBase<RationalType>::asInt(Expression const& expression) const {
BaseExpression const* expressionPtr = expression.getBaseExpressionPointer().get();
auto const& expressionPair = this->compiledExpressions.find(expression.getBaseExpressionPointer().get());
std::shared_ptr<BaseExpression const> expressionPtr = expression.getBaseExpressionPointer();
auto const& expressionPair = this->compiledExpressions.find(expression.getBaseExpressionPointer());
if (expressionPair == this->compiledExpressions.end()) {
CompiledExpressionType const& compiledExpression = this->getCompiledExpression(expressionPtr);
CompiledExpressionType const& compiledExpression = this->getCompiledExpression(expression);
return static_cast<int_fast64_t>(compiledExpression.value());
}
return static_cast<int_fast64_t>(expressionPair->second.value());
}
template<typename RationalType>
typename ExprtkExpressionEvaluatorBase<RationalType>::CompiledExpressionType& ExprtkExpressionEvaluatorBase<RationalType>::getCompiledExpression(BaseExpression const* expression) const {
std::pair<CacheType::iterator, bool> result = this->compiledExpressions.emplace(expression, CompiledExpressionType());
typename ExprtkExpressionEvaluatorBase<RationalType>::CompiledExpressionType& ExprtkExpressionEvaluatorBase<RationalType>::getCompiledExpression(storm::expressions::Expression const& expression) const {
std::pair<CacheType::iterator, bool> result = this->compiledExpressions.emplace(expression.getBaseExpressionPointer(), CompiledExpressionType());
CompiledExpressionType& compiledExpression = result.first->second;
compiledExpression.register_symbol_table(symbolTable);
bool parsingOk = parser.compile(ToExprtkStringVisitor().toString(expression), compiledExpression);
STORM_LOG_ASSERT(parsingOk, "Expression was not properly parsed by ExprTk: " << *expression);
STORM_LOG_ASSERT(parsingOk, "Expression was not properly parsed by ExprTk: " << expression);
return compiledExpression;
}
@ -73,10 +73,10 @@ namespace storm {
}
double ExprtkExpressionEvaluator::asRational(Expression const& expression) const {
BaseExpression const* expressionPtr = expression.getBaseExpressionPointer().get();
auto const& expressionPair = this->compiledExpressions.find(expression.getBaseExpressionPointer().get());
std::shared_ptr<BaseExpression const> expressionPtr = expression.getBaseExpressionPointer();
auto const& expressionPair = this->compiledExpressions.find(expression.getBaseExpressionPointer());
if (expressionPair == this->compiledExpressions.end()) {
CompiledExpressionType const& compiledExpression = this->getCompiledExpression(expressionPtr);
CompiledExpressionType const& compiledExpression = this->getCompiledExpression(expression);
return static_cast<double>(compiledExpression.value());
}
return static_cast<double>(expressionPair->second.value());

5
src/storage/expressions/ExprtkExpressionEvaluator.h

@ -1,6 +1,7 @@
#ifndef STORM_STORAGE_EXPRESSIONS_EXPRTKEXPRESSIONEVALUATOR_H_
#define STORM_STORAGE_EXPRESSIONS_EXPRTKEXPRESSIONEVALUATOR_H_
#include <memory>
#include <unordered_map>
#include <vector>
@ -26,14 +27,14 @@ namespace storm {
protected:
typedef double ValueType;
typedef exprtk::expression<ValueType> CompiledExpressionType;
typedef std::unordered_map<BaseExpression const*, CompiledExpressionType> CacheType;
typedef std::unordered_map<std::shared_ptr<BaseExpression const>, CompiledExpressionType> CacheType;
/*!
* Adds a compiled version of the given expression to the internal storage.
*
* @param expression The expression that is to be compiled.
*/
CompiledExpressionType& getCompiledExpression(BaseExpression const* expression) const;
CompiledExpressionType& getCompiledExpression(storm::expressions::Expression const& expression) const;
// The parser used.
mutable exprtk::parser<ValueType> parser;

Loading…
Cancel
Save