From 76a4f0fcf3a9bf54ef910cdb2c0bebea37182391 Mon Sep 17 00:00:00 2001 From: Carlo Zancanaro Date: Thu, 26 Apr 2012 22:32:35 +1000 Subject: A new attempt. Better strategies implementation. Still lacking: - Factories (to set the ids) - Solver - Systems of equations --- impl/Operator.hpp | 50 +++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 43 insertions(+), 7 deletions(-) (limited to 'impl/Operator.hpp') diff --git a/impl/Operator.hpp b/impl/Operator.hpp index 9f17cbf..d6b92f2 100644 --- a/impl/Operator.hpp +++ b/impl/Operator.hpp @@ -1,17 +1,53 @@ -#ifndef OPERATOR_H -#define OPERATOR_H +#ifndef OPERATOR_HPP +#define OPERATOR_HPP + +template +T infinity() { } + +template<> +float infinity() { + return INFINITY; +} -#include -#include #include -#include "Expression.hpp" + +template +struct VariableAssignment; +template +struct Expression; template struct Operator { - virtual const T eval(const std::vector< Expression >&, const std::map&) const = 0; - virtual std::string output() const = 0; + virtual T operator() (const std::vector< Expression* >&, const VariableAssignment&) const = 0; +}; +template +struct Maximum : public Operator { + virtual T operator() (const std::vector< Expression* >& args, const VariableAssignment& assignment) const { + T value = -infinity(); + for (typename std::vector< Expression* >::const_iterator it = args.begin(); + it != args.end(); + ++it) { + T temporary = (**it)(assignment); + value = (temporary < value ? value : temporary); + } + return value; + } +}; +template +struct Minimumm : public Operator { + virtual T operator() (const std::vector< Expression* >& args, const VariableAssignment& assignment) const { + T value = -infinity(); + for (typename std::vector< Expression* >::const_iterator it = args.begin(); + it != args.end(); + ++it) { + T temporary = (**it)(assignment); + value = (temporary > value ? value : temporary); + } + return value; + } }; +#include "VariableAssignment.hpp" #include "Expression.hpp" #endif -- cgit v1.2.3