-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAbstractSelection.h
51 lines (46 loc) · 1.16 KB
/
AbstractSelection.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
#pragma once
#include <vector>
#include <map>
#include <algorithm>
#include "ByteVector.h"
#include "Roulette.h"
#include "IndexedBackpackObject.h"
class FitnessCalculator {
private:
ObjectVector objectVector;
public:
FitnessCalculator(ObjectVector objectVector) :objectVector(objectVector) {}
costvalue calculateFitness(ByteVector vector) {
costvalue currentCost = 0;
for (IndexedBackpackObject object : objectVector) {
if (vector.getByte(object.index)) {
currentCost += object.object.cost;
}
}
return currentCost;
}
weightvalue calculateWeight(ByteVector vector) {
costvalue currentWeight = 0;
for (IndexedBackpackObject object : objectVector) {
if (vector.getByte(object.index)) {
currentWeight += object.object.weight;
}
}
return currentWeight;
}
};
typedef float funcvalue;
typedef FitnessCalculator function;
class AbstractSelection
{
private:
function func;
protected:
funcvalue CalculateFitness(ByteVector vector) {
return func.calculateFitness(vector);
}
public:
AbstractSelection(function func) :func(func) {};
virtual vector<ByteVector> getGoodChilds(vector<ByteVector> allChilds, int size) = 0;
~AbstractSelection();
};