summaryrefslogtreecommitdiff
path: root/impl/Expression.hpp
diff options
context:
space:
mode:
authorCarlo Zancanaro <carlo@pc-4w14-0.cs.usyd.edu.au>2012-04-30 21:17:07 +1000
committerCarlo Zancanaro <carlo@pc-4w14-0.cs.usyd.edu.au>2012-04-30 21:17:07 +1000
commite00c1e3f71bb1840e10a85af53469a81c73c7ef1 (patch)
tree8b24e7be29b364a5a17bdbaabeb3115261bba783 /impl/Expression.hpp
parent2c22cee1f8fa87c527449a8bdc668ea311fdaf64 (diff)
Functional algorithm. Unoptimised.
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;
};