00001 #ifndef OPTFRAME_MULTIOBJECTIVEEVALUATOR_HPP_
00002 #define OPTFRAME_MULTIOBJECTIVEEVALUATOR_HPP_
00003
00004 #include "Evaluator.hpp"
00005 #include "Evaluation.hpp"
00006 #include "Move.hpp"
00007
00008 #include <iostream>
00009
00010 using namespace std;
00011
00012 template<class R, class M = OPTFRAME_DEFAULT_MEMORY>
00013 class MultiObjectiveEvaluator: public Evaluator<R, M>
00014 {
00015 protected:
00016 vector<Evaluator<R, M>*> partialEvaluators;
00017 public:
00018
00019 using Evaluator<R, M>::evaluate;
00020
00021 MultiObjectiveEvaluator(Evaluator<R, M>& e)
00022 {
00023 partialEvaluators.push_back(&e);
00024 }
00025
00026 virtual ~MultiObjectiveEvaluator()
00027 {
00028 }
00029
00030 void add(Evaluator<R, M>& e)
00031 {
00032 partialEvaluators.push_back(&e);
00033 }
00034
00035 virtual Evaluation<M>& evaluate(const R& r)
00036 {
00037 double objFunction = 0;
00038 double infMeasure = 0;
00039
00040 Evaluation<M>& e = partialEvaluators.at(0)->evaluate(r);
00041
00042 objFunction += e.getObjFunction();
00043 infMeasure += e.getInfMeasure();
00044
00045 for (unsigned i = 1; i < partialEvaluators.size(); i++)
00046 {
00047 partialEvaluators.at(i)->evaluate(e, r);
00048 objFunction += e.getObjFunction();
00049 infMeasure += e.getInfMeasure();
00050 }
00051
00052 e.setObjFunction(objFunction);
00053 e.setInfMeasure(infMeasure);
00054
00055 return e;
00056 }
00057
00058 virtual void evaluate(Evaluation<M>& e, const R& r)
00059 {
00060 double objFunction = 0;
00061 double infMeasure = 0;
00062
00063 for (unsigned i = 0; i < partialEvaluators.size(); i++)
00064 {
00065 partialEvaluators[i]->evaluate(e, r);
00066 objFunction += e.getObjFunction();
00067 infMeasure += e.getInfMeasure();
00068 }
00069
00070 e.setObjFunction(objFunction);
00071 e.setInfMeasure(infMeasure);
00072 }
00073
00074 virtual bool betterThan(double a, double b)
00075 {
00076 return partialEvaluators[0]->betterThan(a, b);
00077 }
00078 };
00079
00080 #endif