Skip to content
Snippets Groups Projects
Commit c6fcb4a7 authored by Lennart Eichhorn's avatar Lennart Eichhorn
Browse files

Simplified Selector Interface

Refactored simulateGenerations method in GeneticAlgorithm
parent 8e9366c0
No related branches found
No related tags found
No related merge requests found
......@@ -4,5 +4,5 @@ import MainClasses.Candidate;
public interface Selector {
Candidate[] selectNewPopulation(Candidate[] population, double[] fitness, double totalFitness);
Candidate[] selectNewPopulation(Candidate[] generation);
}
......@@ -134,28 +134,41 @@ public class GeneticAlgorithm {
for (int gen = 0; gen < config.getTotalGenerations()-1; gen++) {
//TODO Remove with the new Generation class
generation = gen;
this.evaluateGeneration(gen);
this.population = this.selector.selectNewPopulation(this.population, this.fitness, this.totalFitness);
for (Mutator m : mutators) { // SinglePoint and Crossover at the moment
this.population = m.generateMutatedPopulation(this.population);
}
evaluateGeneration();
visualizeGeneration();
System.out.println();
filterGeneration();
mutateGeneration();
}
evaluateGeneration(config.getTotalGenerations()-1);
evaluateGeneration();
visualizeGeneration();
}
private void evaluateGeneration(int gen) {
//TODO These should all be in the new Generation class with definitions like
// mutateGeneration(Mutator e);
private void evaluateGeneration() {
for (int i = 0; i < population.length; i++) {
this.population[i] = this.evaluator.evaluateFitness(this.population[i]);
}
}
private void visualizeGeneration(){
for (Visualizer v : this.visualizers) {
v.drawProtein(this.population, this);
}
}
private void mutateGeneration(){
for (Mutator m : mutators) { // SinglePoint and Crossover at the moment
this.population = m.generateMutatedPopulation(this.population);
}
}
private void filterGeneration(){
this.population = this.selector.selectNewPopulation(this.population);
}
public int getMaxH() {
for (Visualizer v : visualizers) {
if(v instanceof BestFoldingToImage){
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment