-
Notifications
You must be signed in to change notification settings - Fork 1
/
IslandModel.java
96 lines (83 loc) · 2.99 KB
/
IslandModel.java
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import java.util.Random;
import org.vu.contest.ContestEvaluation;
public class IslandModel implements EAPopulation
{
private Population[] populations;
private final int NUM_POPULATIONS;
public IslandModel(int populationSize, Options opt, Random rnd)
{
NUM_POPULATIONS = opt.subPopulations;
populations = new Population[NUM_POPULATIONS];
int subPopulationSize = populationSize / NUM_POPULATIONS;
Options islandOptions = new Options(opt);
for (int i = 0; i < NUM_POPULATIONS; i++) {
//if (i % 2 == 0) {
//islandOptions.parentSelection = Options.ParentSelection.LINEAR_RANKING;
//islandOptions.recombination = Options.Recombination.WHOLE_ARITHMETIC;
//islandOptions.mutation = Options.Mutation.UNCORRELATED_N;
//islandOptions.survivorSelection = Options.SurvivorSelection.MU_PLUS_LAMBDA;
//} else {
//islandOptions.parentSelection = Options.ParentSelection.EXPONENTIAL_RANKING;
//islandOptions.recombination = Options.Recombination.BLEND_RECOMBINATION;
//islandOptions.mutation = Options.Mutation.UNCORRELATED_N;
//islandOptions.survivorSelection = Options.SurvivorSelection.GENERATIONAL;
//}
populations[i] = new Population(subPopulationSize, new Options(islandOptions), rnd);
}
}
public int evaluateInitialPopulation(ContestEvaluation evaluation)
{
int evals = 0;
for (int i = 0; i < NUM_POPULATIONS; i++) {
evals += populations[i].evaluateInitialPopulation(evaluation);
}
return evals;
}
public void selectParents()
{
for (int i = 0; i < NUM_POPULATIONS; i++) {
populations[i].selectParents();
}
}
public void crossover()
{
for (int i = 0; i < NUM_POPULATIONS; i++) {
populations[i].crossover();
}
}
public void mutate(double epsilon)
{
for (int i = 0; i < NUM_POPULATIONS; i++) {
populations[i].mutate(epsilon);
}
}
public int evaluateOffspring(ContestEvaluation evaluation)
{
int evals = 0;
for (int i = 0; i < NUM_POPULATIONS; i++) {
evals += populations[i].evaluateOffspring(evaluation);
}
return evals;
}
public void selectSurvivors()
{
for (int i = 0; i < NUM_POPULATIONS; i++) {
populations[i].selectSurvivors();
}
}
public void exchangeIndividuals()
{
int n = Options.NUM_EXCHANGES;
for (int i = 0; i < NUM_POPULATIONS; i++) {
populations[i].selectBest(n);
populations[i].removeWorst(n);
}
for (int i = 1; i <= NUM_POPULATIONS; i++) {
int neighbour = i;
if (i == NUM_POPULATIONS) {
neighbour = 0;
}
populations[i-1].addExchange(populations[neighbour].getSelectedForExchange());
}
}
}