|
@ -40,17 +40,9 @@ namespace expressions { |
|
|
{ |
|
|
{ |
|
|
typedef std::map<std::string, carl::Variable> type; |
|
|
typedef std::map<std::string, carl::Variable> type; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
struct ExpressionEvaluationSettings { |
|
|
|
|
|
static const bool useFactorizedPolynomials = false; |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
struct FactorizedPolynomialsEvaluationSettings : ExpressionEvaluationSettings { |
|
|
|
|
|
static const bool useFactorizedPolynomials = true; |
|
|
|
|
|
}; |
|
|
|
|
|
#endif |
|
|
#endif |
|
|
|
|
|
|
|
|
template<typename T, typename S, typename X = FactorizedPolynomialsEvaluationSettings> |
|
|
|
|
|
|
|
|
template<typename T, typename S> |
|
|
class ExpressionEvaluationVisitor : public ExpressionVisitor |
|
|
class ExpressionEvaluationVisitor : public ExpressionVisitor |
|
|
{ |
|
|
{ |
|
|
public: |
|
|
public: |
|
@ -60,6 +52,13 @@ namespace expressions { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ExpressionEvaluationVisitor(S* sharedState, std::shared_ptr<carl::Cache<carl::PolynomialFactorizationPair<RawPolynomial>>> cache) |
|
|
|
|
|
: mSharedState(sharedState), cache(cache) |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
virtual ~ExpressionEvaluationVisitor() { |
|
|
virtual ~ExpressionEvaluationVisitor() { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
@ -76,7 +75,7 @@ namespace expressions { |
|
|
} |
|
|
} |
|
|
virtual void visit(BinaryNumericalFunctionExpression const* expression) |
|
|
virtual void visit(BinaryNumericalFunctionExpression const* expression) |
|
|
{ |
|
|
{ |
|
|
ExpressionEvaluationVisitor* visitor = new ExpressionEvaluationVisitor(mSharedState); |
|
|
|
|
|
|
|
|
ExpressionEvaluationVisitor* visitor = new ExpressionEvaluationVisitor(mSharedState, this->cache); |
|
|
expression->getFirstOperand()->accept(visitor); |
|
|
expression->getFirstOperand()->accept(visitor); |
|
|
mValue = visitor->value(); |
|
|
mValue = visitor->value(); |
|
|
expression->getSecondOperand()->accept(visitor); |
|
|
expression->getSecondOperand()->accept(visitor); |
|
@ -86,7 +85,9 @@ namespace expressions { |
|
|
mValue += visitor->value(); |
|
|
mValue += visitor->value(); |
|
|
break; |
|
|
break; |
|
|
case BinaryNumericalFunctionExpression::OperatorType::Minus: |
|
|
case BinaryNumericalFunctionExpression::OperatorType::Minus: |
|
|
|
|
|
std::cout << "mValue: " << mValue << " - " << visitor->value() << std::endl; |
|
|
mValue -= visitor->value(); |
|
|
mValue -= visitor->value(); |
|
|
|
|
|
std::cout << mValue << std::endl; |
|
|
break; |
|
|
break; |
|
|
case BinaryNumericalFunctionExpression::OperatorType::Times: |
|
|
case BinaryNumericalFunctionExpression::OperatorType::Times: |
|
|
mValue *= visitor->value(); |
|
|
mValue *= visitor->value(); |
|
@ -161,22 +162,22 @@ namespace expressions { |
|
|
private: |
|
|
private: |
|
|
S* mSharedState; |
|
|
S* mSharedState; |
|
|
T mValue; |
|
|
T mValue; |
|
|
carl::Cache<carl::PolynomialFactorizationPair<RawPolynomial>>* cache; |
|
|
|
|
|
|
|
|
std::shared_ptr<carl::Cache<carl::PolynomialFactorizationPair<RawPolynomial>>> cache; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
template<typename T> |
|
|
template<typename T> |
|
|
class ExpressionEvaluation |
|
|
class ExpressionEvaluation |
|
|
{ |
|
|
{ |
|
|
public: |
|
|
public: |
|
|
ExpressionEvaluation() : mState() |
|
|
|
|
|
|
|
|
ExpressionEvaluation() : mState(), cache(new carl::Cache<carl::PolynomialFactorizationPair<RawPolynomial>>()) |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
// Intentionally left empty. |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
T evaluate(Expression const& expr, storm::expressions::SimpleValuation const* val) |
|
|
T evaluate(Expression const& expr, storm::expressions::SimpleValuation const* val) |
|
|
{ |
|
|
{ |
|
|
ExpressionEvaluationVisitor<T, typename StateType<T>::type>* visitor = new ExpressionEvaluationVisitor<T, typename StateType<T>::type>(&mState); |
|
|
|
|
|
|
|
|
ExpressionEvaluationVisitor<T, typename StateType<T>::type>* visitor = new ExpressionEvaluationVisitor<T, typename StateType<T>::type>(&mState, cache); |
|
|
Expression expressionToTranslate = expr.substitute(*val); |
|
|
Expression expressionToTranslate = expr.substitute(*val); |
|
|
expressionToTranslate.getBaseExpression().accept(visitor); |
|
|
expressionToTranslate.getBaseExpression().accept(visitor); |
|
|
T result = visitor->value(); |
|
|
T result = visitor->value(); |
|
@ -187,6 +188,7 @@ namespace expressions { |
|
|
|
|
|
|
|
|
protected: |
|
|
protected: |
|
|
typename StateType<T>::type mState; |
|
|
typename StateType<T>::type mState; |
|
|
|
|
|
std::shared_ptr<carl::Cache<carl::PolynomialFactorizationPair<RawPolynomial>>> cache; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|