1 #ifndef GRAIL_EVALUATOR_H
2 #define GRAIL_EVALUATOR_H
4 #include "Consideration.hh"
5 #include "Curves/Curve.hh"
6 #include "IEvaluator.hh"
17 template <
typename ContextType>
24 using CurveDataPair = std::pair<std::shared_ptr<Consideration<ContextType>>, std::shared_ptr<curves::Curve>>;
30 Evaluator(WeightEvaluationMethod evaluationMethod,
const std::vector<CurveDataPair>& curveData)
31 : curveData{ curveData }, method{ evaluationMethod }
52 case WeightEvaluationMethod::MULTIPLY:
53 return EvaluateByMultiplication(
object);
55 case WeightEvaluationMethod::AVERAGE:
56 return EvaluateByAverage(
object);
58 case WeightEvaluationMethod::MAX:
59 return EvaluateByMax(
object);
61 case WeightEvaluationMethod::MIN:
62 return EvaluateByMin(
object);
64 case WeightEvaluationMethod::ADD:
65 return EvaluateByAddition(
object);
77 int rank = std::numeric_limits<int>::min();
78 for (
const CurveDataPair& data : curveData)
80 if (data.first->GetRank() > rank)
81 rank = data.first->GetRank();
86 const std::vector<CurveDataPair>& GetCurveData()
const
91 WeightEvaluationMethod GetEvaluationMethod()
const override
97 float EvaluateConsiderations(
const std::shared_ptr<Consideration<ContextType>>& consideration,
const ContextType&
object)
const
99 return consideration->Evaluate(
object);
103 std::vector<CurveDataPair> curveData = {};
104 WeightEvaluationMethod method{};
106 float EvaluateByMultiplication(
const ContextType&
object)
const
109 for (
const CurveDataPair& data : curveData)
111 weight *= data.second->Sample(EvaluateConsiderations(data.first,
object));
116 float EvaluateByAverage(
const ContextType&
object)
const
119 for (
const CurveDataPair& data : curveData)
121 weight += data.second->Sample(EvaluateConsiderations(data.first,
object));
123 return curveData.size() > 0 ? weight / curveData.size() : 0;
126 float EvaluateByAddition(
const ContextType&
object)
const
129 for (
const CurveDataPair& data : curveData)
131 weight += data.second->Sample(EvaluateConsiderations(data.first,
object));
136 float EvaluateByMax(
const ContextType&
object)
const
138 float weight = std::numeric_limits<float>::min();
139 for (
const CurveDataPair& data : curveData)
141 float current = data.second->Sample(EvaluateConsiderations(data.first,
object));
142 if (current > weight)
148 float EvaluateByMin(
const ContextType&
object)
const
150 float weight = std::numeric_limits<float>::max();
151 for (
const CurveDataPair& data : curveData)
153 float current = data.second->Sample(EvaluateConsiderations(data.first,
object));
154 if (current < weight)
The UtilityEvaluator class - Standard evaluator calculating scores based on considerations and curves...
Definition: Evaluator.hh:22
Evaluator(WeightEvaluationMethod evaluationMethod, const std::vector< CurveDataPair > &curveData)
UtilityEvaluator.
Definition: Evaluator.hh:30
int EvaluateRank() const override
EvaluateRank - Evaluates rank by choosing highest rank from all of it's owned considerations.
Definition: Evaluator.hh:75
float EvaluateWeight(const ContextType &object) const override
EvaluateWeight - Evaluates weight using provided evaluation method.
Definition: Evaluator.hh:48
The Evaluator class - Evaluates object in terms of provided Context.
Definition: IEvaluator.hh:15