#ifndef EXPRESSION_HPP #define EXPRESSION_HPP //#include #include "VariableAssignment.hpp" #include "Operator.hpp" int ExpressionCount; template struct Expression { Expression(Operator* op, const std::vector< Expression* >& args) : _operator(op), _arguments(args) { } virtual ~Expression() { delete _operator; } virtual T operator() (const VariableAssignment& assignment) const { return (*_operator)(_arguments, assignment); } protected: Operator* _operator; std::vector< Expression* > _arguments; }; template struct MaxExpression : public Expression { MaxExpression(const std::vector< Expression* >& args) : Expression(new Maximum, args) { } unsigned int id() const { return _id; } 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; }; #endif