Skip to content
Snippets Groups Projects
Commit f1c7ac08 authored by istkabra's avatar istkabra
Browse files

* Backtracking overlaps are now impossible while initializing and single point...

* Backtracking overlaps are now impossible while initializing and single point mutations (still rarely happens because of crossovers)
* Closes #1
parent 3952a880
Branches
No related tags found
No related merge requests found
package InitialGenerationCreators; package InitialGenerationCreators;
import Enums.DirectionNESW;
import Interfaces.InitialGenerationCreator; import Interfaces.InitialGenerationCreator;
import MainClasses.Candidate; import MainClasses.Candidate;
...@@ -22,16 +21,14 @@ public class RandomDirection<T extends Enum<?>> implements InitialGenerationCre ...@@ -22,16 +21,14 @@ public class RandomDirection<T extends Enum<?>> implements InitialGenerationCre
for (int i = 0; i < populationSize; i++) { for (int i = 0; i < populationSize; i++) {
int[] candidateDirections = new int[sequenceLength]; int[] candidateDirections = new int[sequenceLength];
for (int j = 0; j < sequenceLength; j++) { candidateDirections[0] = this.rand.nextInt(4); // Can start in any direction
candidateDirections[j] = this.randomDirection(this.possibleDirections); for (int j = 1; j < sequenceLength; j++) {
// Make sure there can never be a backtracking overlap while initializing
candidateDirections[j] = ((candidateDirections[j-1] - 1 + this.rand.nextInt(3)) + 4 ) % 4;
} }
population[i] = new Candidate(candidateDirections); population[i] = new Candidate(candidateDirections);
} }
return population; return population;
} }
private int randomDirection(Class<T> dirEnum) {
return rand.nextInt(dirEnum.getEnumConstants().length);
}
} }
...@@ -43,7 +43,14 @@ public class SinglePoint<T extends Enum<?>> implements Mutator { ...@@ -43,7 +43,14 @@ public class SinglePoint<T extends Enum<?>> implements Mutator {
if (this.isFRL) { if (this.isFRL) {
mutatedFolding[mutationPlace] = this.rand.nextInt(3); mutatedFolding[mutationPlace] = this.rand.nextInt(3);
} else { } else {
mutatedFolding[mutationPlace] = this.rand.nextInt(4); if (mutationPlace == 0) {
// Allow any direction in the first position
mutatedFolding[mutationPlace] = this.rand.nextInt(4);
} else {
// Make sure there can never be a backtracking overlap while mutating
mutatedFolding[mutationPlace] =
((mutatedFolding[mutationPlace-1] - 1 + this.rand.nextInt(3)) + 4 ) % 4;
}
} }
} }
} }
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
# Number of generations to run the algorithm for # Number of generations to run the algorithm for
noGenerations = 600 noGenerations = 600
# Type of population initialization [curl | straight | random] # Type of population initialization [curl | straight | random]
initializationMethod = straight initializationMethod = random
# Type of selection that should be used [proportional | tournament | onlybest] # Type of selection that should be used [proportional | tournament | onlybest]
selectionMethod = proportional selectionMethod = proportional
# Number of tournament participants, only relevant when selection is set to tournament # Number of tournament participants, only relevant when selection is set to tournament
...@@ -49,8 +49,8 @@ ...@@ -49,8 +49,8 @@
# log = Generate tab seperated file with a bit of information about each generation # log = Generate tab seperated file with a bit of information about each generation
# generation = print a short overview about each generation to stdout # generation = print a short overview about each generation to stdout
visualizerType = log,generation,image,video visualizerType = log,generation,image,video
# Name of the job, filenames will be based on this name. If left empty a timestamp is used # Name of the job, filenames will be based on this name. If left empty a timestamp is used TODO: leaving it empty should use timestamp
jobName = example1 jobName =
# Directory for the image sequence # Directory for the image sequence
imageSequenceDirectory = visualization/series imageSequenceDirectory = visualization/series
# Directory for the resulting video file # Directory for the resulting video file
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment