-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMagicHexagon.java
32 lines (24 loc) · 1.09 KB
/
MagicHexagon.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
public class MagicHexagon {
public static void main(String[] args) {
GeneticAlgorithm ga = new GeneticAlgorithm(100, 0.5, 0.95, 13);
Population population = ga.initPopulation();
ga.evalPopulation(population);
int generation = 1;
while (!ga.isTerminationConditionMet(population)) {
// Crossover
population = ga.crossOverPopulation(population);
// Mutation
population = ga.mutatePopulation(population);
// eval population
ga.evalPopulation(population);
System.out.println(
"Best Solution" + population.getFittest(0) + "Fittnes " + population.getFittest(0).getFitness());
generation++;
System.out.println("new genaration ---------------------------" + generation);
}
Hexagon hexfit = population.getFittest(0);
System.out.println("Found solution in " + generation + "generations");
System.out.println("Best solution: " + hexfit);
System.out.println("With fitness:" + hexfit.getFitness());
}
}