DISPLACE  1.0
A spatial model of fisheries to help sustainable fishing and maritime spatial planning
commonstateevaluators.h
Go to the documentation of this file.
1 #ifndef COMMONSTATEEVALUATORS_H
2 #define COMMONSTATEEVALUATORS_H
3 
4 #include <dtree/stateevaluator.h>
5 
6 #include <memory>
7 
8 namespace dtree {
9 
14 template <typename T>
16 private:
17  T& mVariable;
18 public:
19 
21  : StateEvaluator(), mVariable(var) {
22  }
23 
24  double evaluate(int, Vessel *) const {
25  return static_cast<double>(mVariable);
26  }
27 
28 
29 };
30 
34 template <typename T>
36 private:
37  const T mConst;
38 public:
39  ConstStateEvaluator(const T &var)
40  : StateEvaluator(), mConst(var) {
41  }
42 
43  double evaluate(int, Vessel *) const {
44  return static_cast<double>(mConst);
45  }
46 
47 
48 };
49 
50 
51 
52 
69 template <typename Operator>
71 private:
72  std::shared_ptr<StateEvaluator> mOp1, mOp2;
73  Operator mOperator;
74 
75 public:
76  TwoArgumentsComparatorStateEvaluator (std::shared_ptr<StateEvaluator> op1, std::shared_ptr<StateEvaluator> op2, Operator oper)
77  : StateEvaluator(), mOp1(op1), mOp2(op2), mOperator(oper) {
78  }
79 
82  double evaluate(int tstep, Vessel *v) const {
83  if (mOperator(mOp1->evaluate(tstep, v), mOp2->evaluate(tstep, v))) {
84  return 1.0;
85  } else {
86  return 0.0;
87  }
88  }
89 };
90 
91 } // ns
92 
93 #endif // COMMONSTATEEVALUATORS_H
94 
A decorator class that evaluates the relation between the values of two other evaluators.
Definition: commonstateevaluators.h:70
double evaluate(int, Vessel *) const
evaluate the state/variable, and returns the selected output, as double. Client can decide what to do...
Definition: commonstateevaluators.h:43
TwoArgumentsComparatorStateEvaluator(std::shared_ptr< StateEvaluator > op1, std::shared_ptr< StateEvaluator > op2, Operator oper)
Definition: commonstateevaluators.h:76
int tstep
Definition: main.cpp:205
An abstract class to allow internal/External states to be evaluated.
Definition: stateevaluator.h:14
double evaluate(int tstep, Vessel *v) const
Overridden method. Apply an operator (passed as template parameter) to two other evaluators.
Definition: commonstateevaluators.h:82
Definition: commonstateevaluators.h:8
VariableReferenceStateEvaluator(T &var)
Definition: commonstateevaluators.h:20
A templated class to evaluate a static variable.
Definition: commonstateevaluators.h:15
ConstStateEvaluator(const T &var)
Definition: commonstateevaluators.h:39
A templated class that evaluates constant-valued variable.
Definition: commonstateevaluators.h:35
double evaluate(int, Vessel *) const
evaluate the state/variable, and returns the selected output, as double. Client can decide what to do...
Definition: commonstateevaluators.h:24