- Main Page
- Classes
- Files

- File List

# OptFrame/Examples/TSP/Evaluator.hpp

    00001 #ifndef TSP_EVALUATOR_HPP_
    00002 #define TSP_EVALUATOR_HPP_
    00003
    00004 //#include <cmath>
    00005 #include <stdlib.h>
    00006 #include <math.h>
    00007
    00008 #include "../../../OptFrame/Evaluation.hpp"
    00009 #include "../../../OptFrame/Evaluator.hpp"
    00010
    00011 #include "Representation.h"
    00012 #include "Memory.h"
    00013 #include "Solution.h"
    00014 #include "Evaluation.h"
    00015
    00016 #include "ProblemInstance.hpp"
    00017
    00018 #define TSP_EPSILON 0.0001
    00019
    00020 class TSPEvaluator: public Evaluator<RepTSP, MemTSP>
    00021 {
    00022 private:
    00023         TSPProblemInstance* pI;
    00024
    00025 public:
    00026
    00027         using Evaluator<RepTSP, MemTSP>::evaluate; // prevents name hiding
    00028
    00029         TSPEvaluator(TSPProblemInstance* pI) // If necessary, add more parameters
    00030         {
    00031                 this->pI = pI;
    00032         }
    00033
    00034         EvaluationTSP& evaluate(const RepTSP& r)
    00035         {
    00036                 double fo = 0; // Evaluation Function Value
    00037
    00038                 for (int i = 0; i < pI->n - 1; i++)
    00039                 {
    00040                         int j = r.at(i);
    00041                         int z = r.at(i + 1);
    00042
    00043                         double val = (*pI->dist)(j, z);
    00044                         fo += val;
    00045                 }
    00046
    00047                 int k = r.at(pI->n - 1);
    00048                 int l = r.at(0);
    00049
    00050                 double val = (*pI->dist)(k, l);
    00051                 fo += val;
    00052
    00053                 double mem = 0;
    00054
    00055                 return *new Evaluation<MemTSP> (fo, mem);
    00056         }
    00057
    00058         void evaluate(Evaluation<MemTSP>& e, const RepTSP& r)
    00059         {
    00060                 e.setObjFunction(e.getObjFunction() + e.getM());
    00061                 e.setM(0);
    00062         }
    00063
    00064         virtual bool betterThan(double a, double b)
    00065         {
    00066                 return (a < (b - TSP_EPSILON));
    00067         }
    00068
    00069 };
    00070
    00071 #endif /*TSP_EVALUATOR_HPP_*/

All Classes Functions