diff options
author | Carlo Zancanaro <carlo@carlo-laptop> | 2012-04-26 22:32:35 +1000 |
---|---|---|
committer | Carlo Zancanaro <carlo@carlo-laptop> | 2012-04-26 22:32:35 +1000 |
commit | 76a4f0fcf3a9bf54ef910cdb2c0bebea37182391 (patch) | |
tree | 86ebaa6f86b53557d92e09ea1a74d2812da01df4 /impl/Operator.hpp | |
parent | 63a10756032fa5c677787fba209706b8bf1e4bef (diff) |
A new attempt. Better strategies implementation.
Still lacking:
- Factories (to set the ids)
- Solver
- Systems of equations
Diffstat (limited to 'impl/Operator.hpp')
-rw-r--r-- | impl/Operator.hpp | 50 |
1 files changed, 43 insertions, 7 deletions
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<typename T> +T infinity() { } + +template<> +float infinity() { + return INFINITY; +} -#include <map> -#include <string> #include <vector> -#include "Expression.hpp" + +template<typename T> +struct VariableAssignment; +template<typename T> +struct Expression; template<typename T> struct Operator { - virtual const T eval(const std::vector< Expression<T> >&, const std::map<std::string, T>&) const = 0; - virtual std::string output() const = 0; + virtual T operator() (const std::vector< Expression<T>* >&, const VariableAssignment<T>&) const = 0; +}; +template<typename T> +struct Maximum : public Operator<T> { + virtual T operator() (const std::vector< Expression<T>* >& args, const VariableAssignment<T>& assignment) const { + T value = -infinity<T>(); + for (typename std::vector< Expression<T>* >::const_iterator it = args.begin(); + it != args.end(); + ++it) { + T temporary = (**it)(assignment); + value = (temporary < value ? value : temporary); + } + return value; + } +}; +template<typename T> +struct Minimumm : public Operator<T> { + virtual T operator() (const std::vector< Expression<T>* >& args, const VariableAssignment<T>& assignment) const { + T value = -infinity<T>(); + for (typename std::vector< Expression<T>* >::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 |