-
Notifications
You must be signed in to change notification settings - Fork 0
/
adjustedEvalFunc.h
61 lines (52 loc) · 1.66 KB
/
adjustedEvalFunc.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
* File: adjustedEvalFunc.h
* Author: MAN
*
* Created on June 18, 2014, 5:53 PM
*/
#ifndef ADJUSTEDEVALFUNC_H
#define ADJUSTEDEVALFUNC_H
template <class EOT>
class AdjustedEvalFunc : public eoEvalFunc<EOT>
{
public:
/// Ctor - no requirement
// START eventually add or modify the anyVariable argument
AdjustedEvalFunc(RouteSetEvalFunc<RouteSet<double > > eval)
{
// START Code of Ctor of an AdjustedEvalFunc object
_actualEval = eval;
// END Code of Ctor of an AdjustedEvalFunc object
}
/** Actually compute the fitness
*
* @param EOT & _eo the EO object to evaluate
* it should stay templatized to be usable
* with any fitness type
*/
void operator()(EOT & _eo)
{
if (_eo.invalid())
{
_actualEval(_eo);
vector< Route<double> > & routeSet = _eo.mutableRs();
double pSum = 0;
for (int r = 0; r < routeSet.size(); r++)
{
list<int>::const_iterator next = routeSet[r].R().begin();
list<int>::const_iterator it = next++;
for (; next != routeSet[r].R().end(); it++, next++)
{
int i = *it;
int j = *next;
pSum = pSum + p[i][j];
}
}
double adjustedFitness = _eo.actualFitness - parameters["beta"] * pSum;
_eo.fitness(adjustedFitness); //minimize
}
}
private:
RouteSetEvalFunc<RouteSet<double > > _actualEval;
};
#endif /* ADJUSTEDEVALFUNC_H */