|  | @ -20,39 +20,31 @@ | 
		
	
		
			
				|  |  | #include "src/storage/parameters.h" |  |  | #include "src/storage/parameters.h" | 
		
	
		
			
				|  |  | 
 |  |  | 
 | 
		
	
		
			
				|  |  | namespace storm { |  |  | namespace storm { | 
		
	
		
			
				|  |  | namespace expressions { |  |  |  | 
		
	
		
			
				|  |  |  |  |  |     namespace expressions { | 
		
	
		
			
				|  |  |          |  |  |          | 
		
	
		
			
				|  |  | 	template<typename T> |  |  |  | 
		
	
		
			
				|  |  | 	struct StateType |  |  |  | 
		
	
		
			
				|  |  | 	{ |  |  |  | 
		
	
		
			
				|  |  | 		typedef int type; |  |  |  | 
		
	
		
			
				|  |  | 	}; |  |  |  | 
		
	
		
			
				|  |  |  |  |  |         template<typename T> | 
		
	
		
			
				|  |  |  |  |  |         struct StateType | 
		
	
		
			
				|  |  |  |  |  |         { | 
		
	
		
			
				|  |  |  |  |  |             typedef int type; | 
		
	
		
			
				|  |  |  |  |  |         }; | 
		
	
		
			
				|  |  |          |  |  |          | 
		
	
		
			
				|  |  | #ifdef PARAMETRIC_SYSTEMS |  |  | #ifdef PARAMETRIC_SYSTEMS | 
		
	
		
			
				|  |  | 	template<> |  |  |  | 
		
	
		
			
				|  |  | 	struct StateType<Polynomial> |  |  |  | 
		
	
		
			
				|  |  | 	{ |  |  |  | 
		
	
		
			
				|  |  | 		typedef std::map<std::string, carl::Variable> type; |  |  |  | 
		
	
		
			
				|  |  | 	}; |  |  |  | 
		
	
		
			
				|  |  | 	 |  |  |  | 
		
	
		
			
				|  |  | 	template<> |  |  |  | 
		
	
		
			
				|  |  | 	struct StateType<RationalFunction> |  |  |  | 
		
	
		
			
				|  |  | 	{ |  |  |  | 
		
	
		
			
				|  |  | 		typedef std::map<std::string, carl::Variable> type; |  |  |  | 
		
	
		
			
				|  |  | 	}; |  |  |  | 
		
	
		
			
				|  |  |      |  |  |  | 
		
	
		
			
				|  |  |     struct ExpressionEvaluationSettings { |  |  |  | 
		
	
		
			
				|  |  |         static const bool useFactorizedPolynomials = false; |  |  |  | 
		
	
		
			
				|  |  |     }; |  |  |  | 
		
	
		
			
				|  |  |      |  |  |  | 
		
	
		
			
				|  |  |     struct FactorizedPolynomialsEvaluationSettings : ExpressionEvaluationSettings { |  |  |  | 
		
	
		
			
				|  |  |         static const bool useFactorizedPolynomials = true; |  |  |  | 
		
	
		
			
				|  |  |     }; |  |  |  | 
		
	
		
			
				|  |  |  |  |  |         template<> | 
		
	
		
			
				|  |  |  |  |  |         struct StateType<Polynomial> | 
		
	
		
			
				|  |  |  |  |  |         { | 
		
	
		
			
				|  |  |  |  |  |             typedef std::map<std::string, carl::Variable> type; | 
		
	
		
			
				|  |  |  |  |  |         }; | 
		
	
		
			
				|  |  |  |  |  |          | 
		
	
		
			
				|  |  |  |  |  |         template<> | 
		
	
		
			
				|  |  |  |  |  |         struct StateType<RationalFunction> | 
		
	
		
			
				|  |  |  |  |  |         { | 
		
	
		
			
				|  |  |  |  |  |             typedef std::map<std::string, carl::Variable> type; | 
		
	
		
			
				|  |  |  |  |  |         }; | 
		
	
		
			
				|  |  | #endif |  |  | #endif | 
		
	
		
			
				|  |  | 		 |  |  | 		 | 
		
	
		
			
				|  |  | 	template<typename T, typename S, typename X = FactorizedPolynomialsEvaluationSettings> |  |  |  | 
		
	
		
			
				|  |  | 	class ExpressionEvaluationVisitor : public ExpressionVisitor |  |  |  | 
		
	
		
			
				|  |  | 	{ |  |  |  | 
		
	
		
			
				|  |  |  |  |  |         template<typename T, typename S> | 
		
	
		
			
				|  |  |  |  |  |         class ExpressionEvaluationVisitor : public ExpressionVisitor | 
		
	
		
			
				|  |  |  |  |  |         { | 
		
	
		
			
				|  |  | 		public: |  |  | 		public: | 
		
	
		
			
				|  |  | 			ExpressionEvaluationVisitor(S* sharedState) |  |  | 			ExpressionEvaluationVisitor(S* sharedState) | 
		
	
		
			
				|  |  | 			: mSharedState(sharedState), cache(new carl::Cache<carl::PolynomialFactorizationPair<RawPolynomial>>()) |  |  | 			: mSharedState(sharedState), cache(new carl::Cache<carl::PolynomialFactorizationPair<RawPolynomial>>()) | 
		
	
	
		
			
				|  | @ -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(); | 
		
	
	
		
			
				|  | @ -105,9 +106,9 @@ namespace expressions { | 
		
	
		
			
				|  |  | 			{ |  |  | 			{ | 
		
	
		
			
				|  |  | 				std::cout << "br" << std::endl; |  |  | 				std::cout << "br" << std::endl; | 
		
	
		
			
				|  |  | 			} |  |  | 			} | 
		
	
		
			
				|  |  |            virtual void visit(VariableExpression const* expression)  |  |  |  | 
		
	
		
			
				|  |  |  |  |  |             virtual void visit(VariableExpression const* expression) | 
		
	
		
			
				|  |  | 			{ |  |  | 			{ | 
		
	
		
			
				|  |  | 			   std::string const& varName= expression->getVariableName(); |  |  |  | 
		
	
		
			
				|  |  |  |  |  |                 std::string const& varName= expression->getVariableName(); | 
		
	
		
			
				|  |  | 				auto it =  mSharedState->find(varName); |  |  | 				auto it =  mSharedState->find(varName); | 
		
	
		
			
				|  |  | 				if(it != mSharedState->end()) |  |  | 				if(it != mSharedState->end()) | 
		
	
		
			
				|  |  | 				{ |  |  | 				{ | 
		
	
	
		
			
				|  | @ -143,66 +144,67 @@ namespace expressions { | 
		
	
		
			
				|  |  |                 mValue = T(carl::rationalize<cln::cl_RA>(str.str())); |  |  |                 mValue = T(carl::rationalize<cln::cl_RA>(str.str())); | 
		
	
		
			
				|  |  | 			} |  |  | 			} | 
		
	
		
			
				|  |  |              |  |  |              | 
		
	
		
			
				|  |  |         template<typename TP = typename T::PolyType, carl::EnableIf<carl::needs_cache<TP>> = carl::dummy> |  |  |  | 
		
	
		
			
				|  |  |         T convertVariableToPolynomial(carl::Variable const& nVar) { |  |  |  | 
		
	
		
			
				|  |  |             return T(typename T::PolyType(typename T::PolyType::PolyType(nVar), cache)); |  |  |  | 
		
	
		
			
				|  |  |         } |  |  |  | 
		
	
		
			
				|  |  |  |  |  |             template<typename TP = typename T::PolyType, carl::EnableIf<carl::needs_cache<TP>> = carl::dummy> | 
		
	
		
			
				|  |  |  |  |  |             T convertVariableToPolynomial(carl::Variable const& nVar) { | 
		
	
		
			
				|  |  |  |  |  |                 return T(typename T::PolyType(typename T::PolyType::PolyType(nVar), cache)); | 
		
	
		
			
				|  |  |  |  |  |             } | 
		
	
		
			
				|  |  |              |  |  |              | 
		
	
		
			
				|  |  |         template<typename TP = typename T::PolyType, carl::DisableIf<carl::needs_cache<TP>> = carl::dummy> |  |  |  | 
		
	
		
			
				|  |  |         T convertVariableToPolynomial(carl::Variable const& nVar) { |  |  |  | 
		
	
		
			
				|  |  |             return T(nVar); |  |  |  | 
		
	
		
			
				|  |  |         } |  |  |  | 
		
	
		
			
				|  |  |  |  |  |             template<typename TP = typename T::PolyType, carl::DisableIf<carl::needs_cache<TP>> = carl::dummy> | 
		
	
		
			
				|  |  |  |  |  |             T convertVariableToPolynomial(carl::Variable const& nVar) { | 
		
	
		
			
				|  |  |  |  |  |                 return T(nVar); | 
		
	
		
			
				|  |  |  |  |  |             } | 
		
	
		
			
				|  |  |              |  |  |              | 
		
	
		
			
				|  |  | 		const T& value() const |  |  |  | 
		
	
		
			
				|  |  | 		{ |  |  |  | 
		
	
		
			
				|  |  | 			return mValue; |  |  |  | 
		
	
		
			
				|  |  | 		} |  |  |  | 
		
	
		
			
				|  |  |  |  |  |             const T& value() const | 
		
	
		
			
				|  |  |  |  |  |             { | 
		
	
		
			
				|  |  |  |  |  |                 return mValue; | 
		
	
		
			
				|  |  |  |  |  |             } | 
		
	
		
			
				|  |  |              |  |  |              | 
		
	
		
			
				|  |  | 		private: |  |  | 		private: | 
		
	
		
			
				|  |  | 		S* mSharedState; |  |  |  | 
		
	
		
			
				|  |  | 		T mValue; |  |  |  | 
		
	
		
			
				|  |  |         carl::Cache<carl::PolynomialFactorizationPair<RawPolynomial>>* cache; |  |  |  | 
		
	
		
			
				|  |  | 	}; |  |  |  | 
		
	
		
			
				|  |  | 	 |  |  |  | 
		
	
		
			
				|  |  | 	template<typename T> |  |  |  | 
		
	
		
			
				|  |  | 	class ExpressionEvaluation |  |  |  | 
		
	
		
			
				|  |  | 	{ |  |  |  | 
		
	
		
			
				|  |  |  |  |  |             S* mSharedState; | 
		
	
		
			
				|  |  |  |  |  |             T mValue; | 
		
	
		
			
				|  |  |  |  |  |             std::shared_ptr<carl::Cache<carl::PolynomialFactorizationPair<RawPolynomial>>> cache; | 
		
	
		
			
				|  |  |  |  |  |         }; | 
		
	
		
			
				|  |  |  |  |  |          | 
		
	
		
			
				|  |  |  |  |  |         template<typename T> | 
		
	
		
			
				|  |  |  |  |  |         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) |  |  |  | 
		
	
		
			
				|  |  | 		{ |  |  |  | 
		
	
		
			
				|  |  | 			ExpressionEvaluationVisitor<T, typename StateType<T>::type>* visitor = new ExpressionEvaluationVisitor<T, typename StateType<T>::type>(&mState); |  |  |  | 
		
	
		
			
				|  |  |             Expression expressionToTranslate = expr.substitute(*val); |  |  |  | 
		
	
		
			
				|  |  | 			expressionToTranslate.getBaseExpression().accept(visitor); |  |  |  | 
		
	
		
			
				|  |  | 			T result = visitor->value(); |  |  |  | 
		
	
		
			
				|  |  | //			result.simplify(); |  |  |  | 
		
	
		
			
				|  |  | 			delete visitor; |  |  |  | 
		
	
		
			
				|  |  | 			return result; |  |  |  | 
		
	
		
			
				|  |  | 		} |  |  |  | 
		
	
		
			
				|  |  |  |  |  |             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, cache); | 
		
	
		
			
				|  |  |  |  |  |                 Expression expressionToTranslate = expr.substitute(*val); | 
		
	
		
			
				|  |  |  |  |  |                 expressionToTranslate.getBaseExpression().accept(visitor); | 
		
	
		
			
				|  |  |  |  |  |                 T result = visitor->value(); | 
		
	
		
			
				|  |  |  |  |  |                 //			result.simplify(); | 
		
	
		
			
				|  |  |  |  |  |                 delete visitor; | 
		
	
		
			
				|  |  |  |  |  |                 return result; | 
		
	
		
			
				|  |  |  |  |  |             } | 
		
	
		
			
				|  |  |              |  |  |              | 
		
	
		
			
				|  |  | 		protected: |  |  | 		protected: | 
		
	
		
			
				|  |  | 			typename StateType<T>::type mState; |  |  | 			typename StateType<T>::type mState; | 
		
	
		
			
				|  |  | 	}; |  |  |  | 
		
	
		
			
				|  |  | 	 |  |  |  | 
		
	
		
			
				|  |  | 	/** |  |  |  | 
		
	
		
			
				|  |  | 	 * For doubles, we keep using the getValueAs from the expressions, as this should be more efficient. |  |  |  | 
		
	
		
			
				|  |  | 	 */ |  |  |  | 
		
	
		
			
				|  |  | 	template<> |  |  |  | 
		
	
		
			
				|  |  | 	class ExpressionEvaluation<double> |  |  |  | 
		
	
		
			
				|  |  | 	{ |  |  |  | 
		
	
		
			
				|  |  |  |  |  |             std::shared_ptr<carl::Cache<carl::PolynomialFactorizationPair<RawPolynomial>>> cache; | 
		
	
		
			
				|  |  |  |  |  |         }; | 
		
	
		
			
				|  |  |  |  |  |          | 
		
	
		
			
				|  |  |  |  |  |         /** | 
		
	
		
			
				|  |  |  |  |  |          * For doubles, we keep using the getValueAs from the expressions, as this should be more efficient. | 
		
	
		
			
				|  |  |  |  |  |          */ | 
		
	
		
			
				|  |  |  |  |  |         template<> | 
		
	
		
			
				|  |  |  |  |  |         class ExpressionEvaluation<double> | 
		
	
		
			
				|  |  |  |  |  |         { | 
		
	
		
			
				|  |  | 		public: |  |  | 		public: | 
		
	
		
			
				|  |  | 		double evaluate(Expression const& expr, storm::expressions::SimpleValuation const* val) const |  |  |  | 
		
	
		
			
				|  |  | 		{ |  |  |  | 
		
	
		
			
				|  |  | 			return expr.evaluateAsDouble(val); |  |  |  | 
		
	
		
			
				|  |  | 		} |  |  |  | 
		
	
		
			
				|  |  | 	}; |  |  |  | 
		
	
		
			
				|  |  |  |  |  |             double evaluate(Expression const& expr, storm::expressions::SimpleValuation const* val) const | 
		
	
		
			
				|  |  |  |  |  |             { | 
		
	
		
			
				|  |  |  |  |  |                 return expr.evaluateAsDouble(val); | 
		
	
		
			
				|  |  |  |  |  |             } | 
		
	
		
			
				|  |  |  |  |  |         }; | 
		
	
		
			
				|  |  |          |  |  |          | 
		
	
		
			
				|  |  | } |  |  |  | 
		
	
		
			
				|  |  |  |  |  |     } | 
		
	
		
			
				|  |  | } |  |  | } | 
		
	
		
			
				|  |  | 
 |  |  | 
 | 
		
	
		
			
				|  |  | #endif |  |  | #endif |