blob: 7a37fb222a9c488fd69395f24325c6f42092abac (
about) (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
#ifndef MAX_STRATEGY_HPP
#define MAX_STRATEGY_HPP
#include "Expression.hpp"
#include "VariableAssignment.hpp"
template<typename T>
struct MaxStrategy {
MaxStrategy(unsigned int length)
: _length(length), _assignment(new unsigned int[length]) { }
virtual ~MaxStrategy() {
delete[] _assignment;
}
const unsigned int& operator[] (const MaxExpression<T> x) const {
if (x.id() < 0 || x.id() >= _length) {
throw "Array out of bounds";
}
return _assignment[x.id()];
}
unsigned int& operator[] (const MaxExpression<T>& x) {
if (x.id() < 0 || x.id() >= _length) {
throw "Array out of bounds";
}
return _assignment[x.id()];
}
T operator() (const EquationSystem<T>& eqns, const VariableAssignment<T>& rho) const {
return eqns.foreach((*this), rho);
}
T operator() (const Expression<T>& expr, const VariableAssignment<T>& rho) const {
const MaxExpression<T>* max = dynamic_cast<const MaxExpression<T>*>(&expr);
if (max == NULL) {
return expr(rho);
} else {
return (*expr.arguments()[_assignment[max->id()]])(rho);
}
}
MaxStrategy<T> improve() {
}
private:
unsigned int _length;
unsigned int* _assignment;
};
#endif
|