diff --git a/src/main/java/InitialGenerationCreators/RandomDirection.java b/src/main/java/InitialGenerationCreators/RandomDirection.java index ecdc7756f8ff1ed738a33d0b0cf378cc3ad4ba13..552c6ce214f297b5d88fe576c043e4f63c1ca071 100644 --- a/src/main/java/InitialGenerationCreators/RandomDirection.java +++ b/src/main/java/InitialGenerationCreators/RandomDirection.java @@ -1,6 +1,5 @@ package InitialGenerationCreators; -import Enums.DirectionNESW; import Interfaces.InitialGenerationCreator; import MainClasses.Candidate; @@ -22,16 +21,14 @@ public class RandomDirection<T extends Enum<?>> implements InitialGenerationCre for (int i = 0; i < populationSize; i++) { int[] candidateDirections = new int[sequenceLength]; - for (int j = 0; j < sequenceLength; j++) { - candidateDirections[j] = this.randomDirection(this.possibleDirections); + candidateDirections[0] = this.rand.nextInt(4); // Can start in any direction + 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); } return population; } - - private int randomDirection(Class<T> dirEnum) { - return rand.nextInt(dirEnum.getEnumConstants().length); - } } diff --git a/src/main/java/Mutators/SinglePoint.java b/src/main/java/Mutators/SinglePoint.java index 47e24c02ec1eb70112012ec5d73d37316c913d3f..0cdf65fc4e4af6ba34470e876465994044db14f9 100644 --- a/src/main/java/Mutators/SinglePoint.java +++ b/src/main/java/Mutators/SinglePoint.java @@ -43,7 +43,14 @@ public class SinglePoint<T extends Enum<?>> implements Mutator { if (this.isFRL) { mutatedFolding[mutationPlace] = this.rand.nextInt(3); } 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; + } } } } diff --git a/src/main/resources/genetic.properties b/src/main/resources/genetic.properties index e79358a644d123158ac82bb99a0b06bc317973b5..6a23d74e99be8ad62eb46385ef8ac8f0e03fe945 100644 --- a/src/main/resources/genetic.properties +++ b/src/main/resources/genetic.properties @@ -11,7 +11,7 @@ # Number of generations to run the algorithm for noGenerations = 600 # Type of population initialization [curl | straight | random] - initializationMethod = straight + initializationMethod = random # Type of selection that should be used [proportional | tournament | onlybest] selectionMethod = proportional # Number of tournament participants, only relevant when selection is set to tournament @@ -49,8 +49,8 @@ # log = Generate tab seperated file with a bit of information about each generation # generation = print a short overview about each generation to stdout visualizerType = log,generation,image,video - # Name of the job, filenames will be based on this name. If left empty a timestamp is used - jobName = example1 + # 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 = # Directory for the image sequence imageSequenceDirectory = visualization/series # Directory for the resulting video file