summaryrefslogtreecommitdiff
path: root/impl/Operator.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'impl/Operator.hpp')
-rw-r--r--impl/Operator.hpp56
1 files changed, 45 insertions, 11 deletions
diff --git a/impl/Operator.hpp b/impl/Operator.hpp
index c9b4a06..dee7f47 100644
--- a/impl/Operator.hpp
+++ b/impl/Operator.hpp
@@ -9,6 +9,12 @@ float infinity() {
}
#include <vector>
+#include "IdSet.hpp"
+
+template<typename T>
+struct Variable;
+template<typename T>
+struct VariableSet : public IdSet<const Variable<T> > {};
template<typename T>
struct VariableAssignment;
@@ -17,16 +23,20 @@ struct Expression;
template<typename T>
struct Operator {
- virtual T operator() (const std::vector< Expression<T>* >&, const VariableAssignment<T>&) const = 0;
+ virtual ~Operator() { }
+ T operator() (const std::vector< Expression<T>* >& args, const VariableAssignment<T>& rho) const {
+ return (*this)(args, rho, (VariableSet<T>*) NULL);
+ }
+ virtual T operator() (const std::vector< Expression<T>* >&, const VariableAssignment<T>&, VariableSet<T>*) const = 0;
};
template<typename T>
struct Maximum : public Operator<T> {
- virtual T operator() (const std::vector< Expression<T>* >& args, const VariableAssignment<T>& assignment) const {
+ virtual T operator() (const std::vector< Expression<T>* >& args, const VariableAssignment<T>& assignment, VariableSet<T>* visited) const {
T value = -infinity<T>();
for (typename std::vector< Expression<T>* >::const_iterator it = args.begin();
it != args.end();
++it) {
- T temporary = (**it)(assignment);
+ T temporary = (**it)(assignment, visited);
value = (temporary < value ? value : temporary);
}
return value;
@@ -34,13 +44,13 @@ struct Maximum : public Operator<T> {
};
template<typename T>
struct Minimum : public Operator<T> {
- virtual T operator() (const std::vector< Expression<T>* >& args, const VariableAssignment<T>& assignment) const {
+ virtual T operator() (const std::vector< Expression<T>* >& args, const VariableAssignment<T>& assignment, VariableSet<T>* visited) const {
T value = infinity<T>();
for (typename std::vector< Expression<T>* >::const_iterator it = args.begin();
it != args.end();
++it) {
- T temporary = (**it)(assignment);
- value = (temporary > value ? value : temporary);
+ T temporary = (**it)(assignment, visited);
+ value = (temporary < value ? temporary : value);
}
return value;
}
@@ -50,7 +60,7 @@ template<typename T>
struct Constant : public Operator<T> {
Constant(const T& val)
: _value(val) { }
- T operator() (const std::vector< Expression<T>* >& args, const VariableAssignment<T>& ass) const {
+ T operator() (const std::vector< Expression<T>* >& args, const VariableAssignment<T>& ass, VariableSet<T>*) const {
return _value;
}
private:
@@ -59,10 +69,10 @@ struct Constant : public Operator<T> {
template<typename T>
struct Addition: public Operator<T> {
- T operator() (const std::vector< Expression<T>* >& args, const VariableAssignment<T>& ass) const {
+ T operator() (const std::vector< Expression<T>* >& args, const VariableAssignment<T>& ass, VariableSet<T>* visited) const {
T sum = (*args[0])(ass);
for (unsigned int i = 1, size = args.size(); i < size; ++i) {
- sum += (*args[i])(ass);
+ sum += (*args[i])(ass, visited);
}
return sum;
}
@@ -70,15 +80,39 @@ struct Addition: public Operator<T> {
template<typename T>
struct Subtraction: public Operator<T> {
- T operator() (const std::vector< Expression<T>* >& args, const VariableAssignment<T>& ass) const {
+ T operator() (const std::vector< Expression<T>* >& args, const VariableAssignment<T>& ass, VariableSet<T>* visited) const {
T sum = (*args[0])(ass);
for (unsigned int i = 1, size = args.size(); i < size; ++i) {
- sum -= (*args[i])(ass);
+ sum -= (*args[i])(ass, visited);
}
return sum;
}
};
+template<typename T>
+struct Comma: public Operator<T> {
+ T operator() (const std::vector< Expression<T>* >& args, const VariableAssignment<T>& ass, VariableSet<T>* visited) const {
+ if ((*args[0])(ass, visited) == -infinity<T>()) {
+ std::cout << "Comma - neg inf" << std::endl;
+ return -infinity<T>();
+ } else {
+ std::cout << "Comma - finite" << std::endl;
+ return (*args[1])(ass, visited);
+ }
+ }
+};
+
+template<typename T>
+struct Guard: public Operator<T> {
+ T operator() (const std::vector< Expression<T>* >& args, const VariableAssignment<T>& ass, VariableSet<T>* visited) const {
+ if ((*args[0])(ass, visited) < (*args[1])(ass, visited)) {
+ return -infinity<T>();
+ } else {
+ return (*args[2])(ass, visited);
+ }
+ }
+};
+
#include "VariableAssignment.hpp"
#include "Expression.hpp"