summaryrefslogtreecommitdiff
path: root/impl/Expression.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'impl/Expression.hpp')
-rw-r--r--impl/Expression.hpp25
1 files changed, 23 insertions, 2 deletions
diff --git a/impl/Expression.hpp b/impl/Expression.hpp
index d3dfcf3..3c84d30 100644
--- a/impl/Expression.hpp
+++ b/impl/Expression.hpp
@@ -24,6 +24,10 @@ struct Expression {
virtual T operator() (const VariableAssignment<T>& assignment) const {
return (*_operator)(_arguments, assignment);
}
+
+ template<typename Z>
+ friend std::ostream& operator<<(std::ostream&, const Expression<Z>&);
+
protected:
Operator<T>* _operator;
std::vector< Expression<T>* > _arguments;
@@ -52,16 +56,33 @@ struct MaxExpression : public Expression<T> {
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 = strat(*Expression<T>::_arguments[i], rho);
- if (value > best.first)
+ if (best.first < value)
best = std::pair<T, unsigned int>(value, i);
}
- std::cerr << "Best strategy: (" << best.first << ", " << best.second << ")" << std::endl << std::endl;
+ std::cerr << "Best strategy: (" << best.first << ", " << best.second << ")" << std::endl;
return best;
}
private:
unsigned int _id;
};
+template<typename T>
+std::ostream& operator<<(std::ostream& cout, const Expression<T>& expr) {
+ if (expr._arguments.size() == 0) {
+ cout << expr._operator->op_name;
+ } else {
+ cout << expr._operator->op_name << "(";
+ for (typename std::vector<Expression<T>*>::const_iterator it = expr._arguments.begin();
+ it != expr._arguments.end();
+ ++it) {
+ cout << (it == expr._arguments.begin() ? "" : ", ");
+ cout << **it;
+ }
+ cout << ")";
+ }
+ return cout;
+}
+
#include "Variable.hpp"
#include "MaxStrategy.hpp"