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

Moved constant from Mutator to Config.

parent b2fe5c7e
No related branches found
No related tags found
No related merge requests found
...@@ -5,10 +5,9 @@ import MainClasses.Candidate; ...@@ -5,10 +5,9 @@ import MainClasses.Candidate;
public interface Mutator { public interface Mutator {
double MINIMUM_CHANCE = 0.0001; // -> 0.01% is not worth mutating for
Candidate[] mutatePopulation(Candidate[] population); Candidate[] mutatePopulation(Candidate[] population);
//TODO Remove, when decided on FRL vs NESW
static <T extends Enum<?>> boolean isFRLEncoding(Class<T> possibleDirections) { static <T extends Enum<?>> boolean isFRLEncoding(Class<T> possibleDirections) {
T[] possibleDirectionsEnum = possibleDirections.getEnumConstants(); T[] possibleDirectionsEnum = possibleDirections.getEnumConstants();
for (int i = 0; i < possibleDirectionsEnum.length; i++) { for (int i = 0; i < possibleDirectionsEnum.length; i++) {
......
...@@ -31,8 +31,10 @@ public class Config { ...@@ -31,8 +31,10 @@ public class Config {
static int MUTATION_ATTEMPTS_PER_CANDIDATE; static int MUTATION_ATTEMPTS_PER_CANDIDATE;
static double MUTATION_CHANCE; static double MUTATION_CHANCE;
static double MUTATION_MULTIPLIER; static double MUTATION_MULTIPLIER;
static double MUTATION_MINIMAL_CHANCE; // -> 0.01% is not worth mutating for
static int CROSSOVER_ATTEMPTS_PER_CANDIDATE; static int CROSSOVER_ATTEMPTS_PER_CANDIDATE;
static double CROSSOVER_CHANCE; static double CROSSOVER_CHANCE;
static double CROSSOVER_MINIMAL_CHANCE; // -> 0.01% is not worth mutating for
static double CROSSOVER_MULTIPLIER; static double CROSSOVER_MULTIPLIER;
static String LOGFILE; static String LOGFILE;
...@@ -137,9 +139,11 @@ public class Config { ...@@ -137,9 +139,11 @@ public class Config {
// Mutation settings // Mutation settings
MUTATION_ATTEMPTS_PER_CANDIDATE = Integer.parseInt(this.properties.getProperty("mutationAttemptsPerCandidate")); MUTATION_ATTEMPTS_PER_CANDIDATE = Integer.parseInt(this.properties.getProperty("mutationAttemptsPerCandidate"));
MUTATION_CHANCE = Double.parseDouble(this.properties.getProperty("mutationChance")); MUTATION_CHANCE = Double.parseDouble(this.properties.getProperty("mutationChance"));
MUTATION_MINIMAL_CHANCE = Double.parseDouble(this.properties.getProperty("mutationMinimalChance"));
MUTATION_MULTIPLIER = Double.parseDouble(this.properties.getProperty("mutationMultiplier")); MUTATION_MULTIPLIER = Double.parseDouble(this.properties.getProperty("mutationMultiplier"));
CROSSOVER_ATTEMPTS_PER_CANDIDATE = Integer.parseInt(this.properties.getProperty("crossoverAttemptsPerCandidate")); CROSSOVER_ATTEMPTS_PER_CANDIDATE = Integer.parseInt(this.properties.getProperty("crossoverAttemptsPerCandidate"));
CROSSOVER_CHANCE = Double.parseDouble(this.properties.getProperty("crossoverChance")); CROSSOVER_CHANCE = Double.parseDouble(this.properties.getProperty("crossoverChance"));
CROSSOVER_MINIMAL_CHANCE = Double.parseDouble(this.properties.getProperty("crossoverMinimalChance"));
CROSSOVER_MULTIPLIER = Double.parseDouble(this.properties.getProperty("crossoverMultiplier")); CROSSOVER_MULTIPLIER = Double.parseDouble(this.properties.getProperty("crossoverMultiplier"));
......
...@@ -91,11 +91,11 @@ public class GeneticAlgorithm { ...@@ -91,11 +91,11 @@ public class GeneticAlgorithm {
for (int i = 0; i < Config.MUTATOR_METHODS.length; i++) { for (int i = 0; i < Config.MUTATOR_METHODS.length; i++) {
if (Config.MUTATOR_METHODS[i].equals(MutatorMethods.SinglePoint)) { if (Config.MUTATOR_METHODS[i].equals(MutatorMethods.SinglePoint)) {
this.mutators[i] = new SinglePoint<>(DirectionNESW.class, this.rand, this.mutators[i] = new SinglePoint<>(DirectionNESW.class, this.rand,
Config.MUTATION_ATTEMPTS_PER_CANDIDATE, Config.MUTATION_CHANCE, Config.MUTATION_MULTIPLIER); Config.MUTATION_ATTEMPTS_PER_CANDIDATE, Config.MUTATION_CHANCE, Config.MUTATION_MINIMAL_CHANCE, Config.MUTATION_MULTIPLIER);
} else if (Config.MUTATOR_METHODS[i].equals(MutatorMethods.Crossover)) { } else if (Config.MUTATOR_METHODS[i].equals(MutatorMethods.Crossover)) {
this.mutators[i] = new Crossover<>(DirectionNESW.class, this.rand, this.mutators[i] = new Crossover<>(DirectionNESW.class, this.rand,
Config.CROSSOVER_ATTEMPTS_PER_CANDIDATE, Config.CROSSOVER_CHANCE, Config.CROSSOVER_MULTIPLIER); Config.CROSSOVER_ATTEMPTS_PER_CANDIDATE, Config.CROSSOVER_CHANCE, Config.MUTATION_MINIMAL_CHANCE, Config.CROSSOVER_MULTIPLIER);
} }
} }
......
...@@ -12,22 +12,24 @@ public class Crossover<T extends Enum<?>> implements Mutator { ...@@ -12,22 +12,24 @@ public class Crossover<T extends Enum<?>> implements Mutator {
Random rand; Random rand;
int crossoverAttemptsPerCandidate; int crossoverAttemptsPerCandidate;
double crossoverChance; double crossoverChance;
double crossoverMinimalChance;
double crossoverMultiplier; double crossoverMultiplier;
public Crossover(Class<T> possibleDirections, Random rand, int crossoverAttemptsPerCandidate, public Crossover(Class<T> possibleDirections, Random rand, int crossoverAttemptsPerCandidate,
double crossoverChance, double crossoverMultiplier) { double crossoverChance, double crossoverMinimalChance, double crossoverMultiplier) {
this.possibleDirections = possibleDirections; this.possibleDirections = possibleDirections;
this.isFRL = Mutator.isFRLEncoding(possibleDirections); this.isFRL = Mutator.isFRLEncoding(possibleDirections);
this.rand = rand; this.rand = rand;
this.crossoverAttemptsPerCandidate = crossoverAttemptsPerCandidate; this.crossoverAttemptsPerCandidate = crossoverAttemptsPerCandidate;
this.crossoverChance = crossoverChance; this.crossoverChance = crossoverChance;
this.crossoverMinimalChance = crossoverMinimalChance;
this.crossoverMultiplier = crossoverMultiplier; this.crossoverMultiplier = crossoverMultiplier;
} }
@Override @Override
public Candidate[] mutatePopulation(Candidate[] population) { public Candidate[] mutatePopulation(Candidate[] population) {
Candidate[] mutatedPopulation = new Candidate[population.length]; Candidate[] mutatedPopulation = new Candidate[population.length];
if (this.crossoverChance > MINIMUM_CHANCE) { if (this.crossoverChance > crossoverMinimalChance) {
int populationSize = population.length; int populationSize = population.length;
int proteinLength = population[0].getFolding().length; int proteinLength = population[0].getFolding().length;
......
...@@ -12,22 +12,24 @@ public class SinglePoint<T extends Enum<?>> implements Mutator { ...@@ -12,22 +12,24 @@ public class SinglePoint<T extends Enum<?>> implements Mutator {
Random rand; Random rand;
int mutationAttemptsPerCandidate; int mutationAttemptsPerCandidate;
double mutationChance; double mutationChance;
double mutationMinimalChance;
double mutationMultiplier; double mutationMultiplier;
public SinglePoint(Class<T> possibleDirections, Random rand, int mutationAttemptsPerCandidate, public SinglePoint(Class<T> possibleDirections, Random rand, int mutationAttemptsPerCandidate,
double mutationChance, double mutationMultiplier) { double mutationChance, double mutationMinimalChance, double mutationMultiplier) {
this.possibleDirections = possibleDirections; this.possibleDirections = possibleDirections;
this.isFRL = Mutator.isFRLEncoding(possibleDirections); this.isFRL = Mutator.isFRLEncoding(possibleDirections);
this.rand = rand; this.rand = rand;
this.mutationAttemptsPerCandidate = mutationAttemptsPerCandidate; this.mutationAttemptsPerCandidate = mutationAttemptsPerCandidate;
this.mutationChance = mutationChance; this.mutationChance = mutationChance;
this.mutationMinimalChance = mutationMinimalChance;
this.mutationMultiplier = mutationMultiplier; this.mutationMultiplier = mutationMultiplier;
} }
@Override @Override
public Candidate[] mutatePopulation(Candidate[] population) { public Candidate[] mutatePopulation(Candidate[] population) {
Candidate[] mutatedPopulation = new Candidate[population.length]; Candidate[] mutatedPopulation = new Candidate[population.length];
if (this.mutationChance > MINIMUM_CHANCE) { if (this.mutationChance > mutationMinimalChance) {
int proteinLength = population[0].getFolding().length; int proteinLength = population[0].getFolding().length;
......
...@@ -27,12 +27,16 @@ ...@@ -27,12 +27,16 @@
mutationAttemptsPerCandidate = 1 mutationAttemptsPerCandidate = 1
# Chance for a successful single point mutation [1.0 = 100%] # Chance for a successful single point mutation [1.0 = 100%]
mutationChance = 1.0 mutationChance = 1.0
# The mutation chance cannot drop below this value [1.0 = 100%]
mutationMinimalChance = 0.001
# Multiplicand for mutation probability with each generation -> ex with 0.05: 1st 1.0, 2nd 0.95, 3rd 0.9025, 4th 0.857 # Multiplicand for mutation probability with each generation -> ex with 0.05: 1st 1.0, 2nd 0.95, 3rd 0.9025, 4th 0.857
mutationMultiplier = 0.001 mutationMultiplier = 0.001
# How often a crossover should be attempted per candidate # How often a crossover should be attempted per candidate
crossoverAttemptsPerCandidate = 1 crossoverAttemptsPerCandidate = 1
# Chance for a successful crossover [1.0 = 100%] # Chance for a successful crossover [1.0 = 100%]
crossoverChance = 0.6 crossoverChance = 0.6
# The crossover chance cannot drop below this value [1.0 = 100%]
crossoverMinimalChance = 0.001
# Multiplicand for mutation probability with each generation -> ex with -0.05: 1st 1.0, 2nd 1.05, 3rd 1,1025, 4th 1,157 # Multiplicand for mutation probability with each generation -> ex with -0.05: 1st 1.0, 2nd 1.05, 3rd 1,1025, 4th 1,157
crossoverMultiplier = 0.005 crossoverMultiplier = 0.005
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment