-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGeneticAlgorithm.pde
More file actions
49 lines (39 loc) · 1015 Bytes
/
GeneticAlgorithm.pde
File metadata and controls
49 lines (39 loc) · 1015 Bytes
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
Population test;
Goal goal;
ArrayList<Barrier> barriers;
int numOnTarget;
float peakFitness;
int populationSize;
float mutationRate;
void setup() {
size(800,800);
populationSize = 1000;
mutationRate = 0.01;
test = new Population(populationSize, mutationRate);
goal = new Goal();
barriers = new ArrayList<Barrier>();
barriers.add(new Barrier(600, 0, 200));
barriers.add(new Barrier(600, width - 600, 400));
}
void draw() {
background(255);
text("Generation: " + test.generation, 10, 20);
text("Population size: " + populationSize, 10, 40);
text("Mutation rate: " + (mutationRate * 100) + "%", 10, 60);
text("Number on target: " + numOnTarget, 10, 80);
text("Peak fitness: " + peakFitness, 10, 100);
goal.show();
for (Barrier barrier : barriers) {
barrier.show();
}
if (test.allDotsDead()) {
// genetic algorithm
test.calculateFitness();
test.naturalSelection();
test.mutateChildren();
}
else {
test.update();
test.show();
}
}