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

Fixed bug in GeneticAlgorithm.

Crossover got initialized with the wrong value.
parent 1fe13dbe
No related branches found
No related tags found
No related merge requests found
...@@ -18,6 +18,8 @@ import java.io.IOException; ...@@ -18,6 +18,8 @@ import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.nio.file.StandardOpenOption; import java.nio.file.StandardOpenOption;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random; import java.util.Random;
public class GeneticAlgorithm { public class GeneticAlgorithm {
...@@ -40,6 +42,8 @@ public class GeneticAlgorithm { ...@@ -40,6 +42,8 @@ public class GeneticAlgorithm {
Evaluator evaluator; Evaluator evaluator;
Visualizer[] visualizers; Visualizer[] visualizers;
String jobName;
// Initialize with protein // Initialize with protein
public GeneticAlgorithm (int[] protein, Config config) { public GeneticAlgorithm (int[] protein, Config config) {
this.isHydrophobic = protein; this.isHydrophobic = protein;
...@@ -52,6 +56,11 @@ public class GeneticAlgorithm { ...@@ -52,6 +56,11 @@ public class GeneticAlgorithm {
this.totalFitness = 0; this.totalFitness = 0;
this.fitness = new double[config.getPopulationSize()]; this.fitness = new double[config.getPopulationSize()];
this.overallBestFitness = 0; this.overallBestFitness = 0;
//TODO Maybe specify jobName in config
SimpleDateFormat formatter = new SimpleDateFormat("ddMMyyyyHHmmss");
Date date = new Date();
jobName = formatter.format(date);
} }
private void initializeSettings() { private void initializeSettings() {
...@@ -98,7 +107,7 @@ public class GeneticAlgorithm { ...@@ -98,7 +107,7 @@ public class GeneticAlgorithm {
} else if (config.getMutatorMethods()[i].equals(MutatorMethods.Crossover)) { } else if (config.getMutatorMethods()[i].equals(MutatorMethods.Crossover)) {
this.mutators[i] = new Crossover<>(DirectionNESW.class, this.rand, this.mutators[i] = new Crossover<>(DirectionNESW.class, this.rand,
config.getCrossoverAttemptsPerCandidate(), config.getCrossoverChance(), config.getMutationMinimalChance(), config.getCrossoverMultiplier()); config.getCrossoverAttemptsPerCandidate(), config.getCrossoverChance(), config.getCrossoverMinimalChance(), config.getCrossoverMultiplier());
} }
} }
...@@ -159,7 +168,7 @@ public class GeneticAlgorithm { ...@@ -159,7 +168,7 @@ public class GeneticAlgorithm {
} }
for (Visualizer v : this.visualizers) { for (Visualizer v : this.visualizers) {
v.setFilename(String.format("gen_%d.png", gen)); v.setFilename(String.format("%s_gen_%d.png", jobName, gen));
//TODO Print real bond and overlap amount //TODO Print real bond and overlap amount
v.drawProtein(this.population[bestIndex].getVertices(), bestFitness, -1, -1, gen); v.drawProtein(this.population[bestIndex].getVertices(), bestFitness, -1, -1, gen);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment