From e00c1e3f71bb1840e10a85af53469a81c73c7ef1 Mon Sep 17 00:00:00 2001 From: Carlo Zancanaro Date: Mon, 30 Apr 2012 21:17:07 +1000 Subject: Functional algorithm. Unoptimised. --- impl/Expression.hpp | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'impl/Expression.hpp') diff --git a/impl/Expression.hpp b/impl/Expression.hpp index 46ccf23..7b157c2 100644 --- a/impl/Expression.hpp +++ b/impl/Expression.hpp @@ -1,6 +1,7 @@ #ifndef EXPRESSION_HPP #define EXPRESSION_HPP +//#include #include "VariableAssignment.hpp" #include "Operator.hpp" @@ -16,13 +17,10 @@ struct Expression { delete *it; }*/ } - const std::vector*>& arguments() const { - return _arguments; - } virtual T operator() (const VariableAssignment& assignment) const { return (*_operator)(_arguments, assignment); } - private: + protected: Operator* _operator; std::vector< Expression* > _arguments; }; @@ -37,6 +35,22 @@ struct MaxExpression : public Expression { unsigned int id(unsigned int id) { return (_id = id); } + Expression* argument(unsigned int i) const { + if (i >= Expression::_arguments.size()) { + throw "Error"; + } + return Expression::_arguments[i]; + } + std::pair bestStrategy(const VariableAssignment& rho) const { + std::pair best = std::pair(-infinity(), 0); + for (unsigned int i = 0, size = Expression::_arguments.size(); i < size; ++i) { + T value = (*Expression::_arguments[i])(rho); + if (value > best.first) + best = std::pair(value, i); + } + std::cout << "Best strategy: (" << best.first << ", " << best.second << ")" << std::endl; + return best; + } private: unsigned int _id; }; -- cgit v1.2.3