#ifndef OPERATOR_HPP #define OPERATOR_HPP template T infinity() { } template<> float infinity() { return INFINITY; } #include #include "IdSet.hpp" template struct Variable; template struct VariableAssignment; template struct Expression; template struct Operator { virtual ~Operator() { } virtual T operator() (const std::vector< Expression* >& args, const VariableAssignment& rho) 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 ? temporary : value); //if (value == infinity()) break; } return value; } }; template struct Minimum : 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 ? temporary : value); //if (value == -infinity()) break; } return value; } }; template struct Constant : public Operator { Constant(const T& val) : _value(val) { } T operator() (const std::vector< Expression* >& args, const VariableAssignment& ass) const { return _value; } private: const T _value; }; template struct Addition: public Operator { T operator() (const std::vector< Expression* >& args, const VariableAssignment& ass) const { T sum = (*args[0])(ass); for (unsigned int i = 1, size = args.size(); i < size; ++i) { sum += (*args[i])(ass); } return sum; } }; template struct Subtraction: public Operator { T operator() (const std::vector< Expression* >& args, const VariableAssignment& ass) const { T sum = (*args[0])(ass); for (unsigned int i = 1, size = args.size(); i < size; ++i) { sum -= (*args[i])(ass); } return sum; } }; template struct Comma: public Operator { T operator() (const std::vector< Expression* >& args, const VariableAssignment& ass) const { if ((*args[0])(ass) == -infinity()) { std::cout << "Comma - neg inf" << std::endl; return -infinity(); } else { std::cout << "Comma - finite" << std::endl; return (*args[1])(ass); } } }; template struct Guard: public Operator { T operator() (const std::vector< Expression* >& args, const VariableAssignment& ass) const { if ((*args[0])(ass) < (*args[1])(ass)) { return -infinity(); } else { return (*args[2])(ass); } } }; #include "VariableAssignment.hpp" #include "Expression.hpp" #endif