summaryrefslogtreecommitdiff
path: root/impl/Expression.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'impl/Expression.hpp')
-rw-r--r--impl/Expression.hpp22
1 files changed, 18 insertions, 4 deletions
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 <pair>
#include "VariableAssignment.hpp"
#include "Operator.hpp"
@@ -16,13 +17,10 @@ struct Expression {
delete *it;
}*/
}
- const std::vector<Expression<T>*>& arguments() const {
- return _arguments;
- }
virtual T operator() (const VariableAssignment<T>& assignment) const {
return (*_operator)(_arguments, assignment);
}
- private:
+ protected:
Operator<T>* _operator;
std::vector< Expression<T>* > _arguments;
};
@@ -37,6 +35,22 @@ struct MaxExpression : public Expression<T> {
unsigned int id(unsigned int id) {
return (_id = id);
}
+ Expression<T>* argument(unsigned int i) const {
+ if (i >= Expression<T>::_arguments.size()) {
+ throw "Error";
+ }
+ return Expression<T>::_arguments[i];
+ }
+ std::pair<T, unsigned int> bestStrategy(const VariableAssignment<T>& rho) const {
+ std::pair<T, unsigned int> best = std::pair<T, unsigned int>(-infinity<T>(), 0);
+ for (unsigned int i = 0, size = Expression<T>::_arguments.size(); i < size; ++i) {
+ T value = (*Expression<T>::_arguments[i])(rho);
+ if (value > best.first)
+ best = std::pair<T, unsigned int>(value, i);
+ }
+ std::cout << "Best strategy: (" << best.first << ", " << best.second << ")" << std::endl;
+ return best;
+ }
private:
unsigned int _id;
};