This algorithm uses genetic evolution to optimize any object that extends the GeneticSubject abstract class.
The algorithm is intended to optimize a descendant of the GeneticSubject abstract class through the use of genetics. A valid configuration file and an instance of the implemented GeneticSubject subclass (defined as the witness variable in the main method of the Main class are first provided for algorithm initialization. An implementation-specific configuration file's path can also be feeded to the program as a second parameter, which will then be deriven to the witness loadConfigurationFromFile method. configuration.generationSize random objects will then be produced through the witness's getRandom method. They will constitute the first generation. The algorithm's flow is then as follows:
- Select configuration.cantChildren parents from the current population through the potentially two parent Selector implementations specified in the configuration file.
- Breed configuration.cantChildren children through the chosen Crossover implementation.
- Apply each of the mutate methods from each of the defined Mutation implementations.
- Select configuration.generationSize parents through the potentially two parent Selector implementations specified in the configuration file. Once chosen, they will substitute the current generation.
- If configuration.fillAll is set to true, then add the generated children to the current generation and choose from all of them.
- If configuration.fillAll is set to false, attemp to select configuration.generationSize subjects from the generated children with no repetitions. If configuration.generationSize > configuration.cantChildren, finish up by selecting an additional (configuration.generationSize - configuration.cantChildren) subjects from the current generation.
- Check every FinishCriteria implementation provided.
- If any of them is met, end the program's executions and potentially print results.
- Else, go back to the first step.
From the project's root folder, run:
$> mvn clean install
Locate the diretory that contains the executable and run:
$> java -jar executable-name algorithm-config-file [custom-implementation-config-file]
The algorithm accepts up to two json configuration files through parameters. The first has a defined structure and is used to configure algorithm specific settings. It can be shared across different GeneticSubject implementations. The second one is passed to the custom GeneticSubject implementation's loadConfigurationFromFile method, and should be defined and interpreted by the implementation itself.
generationSize (Integer > 0): defines the size of every generation across the algorithm's execution.
cantChildren (Integer > 0): defines the number of parents selected to bred and the children they'll produce.
printBestOnEachGeneration (Boolean): defines wheter each generation's best subject must be printed.
printEndingInformation (Boolean): defines wheter the most optimized subject should be printed at the end of the algorithm's execution.
printBestFitnessEvolution (Boolean): defines wheter an array containing each generation's best fitness should be printed at the end of the algorithm's execution.
crossoverMethod (Object): defines the crossover method to be used and it's parameters.
name (String, ["uniform", | "singlePoint" | "twoPoints" | "anular"]): name of the method as defined by the crossovers map in the Main class method loadGeneticAlgorithmDependencies. When name equals uniform, an object named parameters, containing the following properties, is also required:
exchangeProbability (1 >= Float > 0): Defines the likeness of a gene being swapped by the uniform crossover method.
mutationMethods (Array of Objects): defines the mutation method's to be applied to each new subject upon creation. Each child object is defined as follows.
name (String, [singleGene", "uniformMultiGene", "complete", "limitedMultiGene"]): name of the method as defined by the mutations map in the Main class method loadGeneticAlgorithmDependencies.
probability (1 >= Float > 0): Defines the likeness of the mutation method executing when called upon.
parentSelectionMethods (Object): defines up to two selection methods that will be used to select parents before breeding.
method1 (Object): defines the first of the potentially two methods to be used.
name (String, ["elite", "roulette", "ranking", "boltzmann", "universal", "deterministicTournaments", "probabilisticTournaments"]): name of the method as defined by the selectors map in the Main class method loadGeneticAlgorithmDependencies. When name equals boltzmann, an object named parameters, containing the following properties, is also required:
T0 (Double > 0): Value used for the decreasing temperature function defined inside the BoltzmannSelector class.
Tc (Double > 0): Value used for the decreasing temperature function defined inside the BoltzmannSelector class.
When name equals deterministicTournaments, an object named parameters, containing the following properties, is also required:
randomSubsetSize (Integer > 0): Defines the size of the population's subset to be selected by each iteration of the selection method.
When name equals probabilisticTournaments, an object named parameters, containing the following properties, is also required:
threshold (1 >= Float >= 0.5): Defines the odds of the method selecting the best-fit subject on each iteration.
method2 (Object, optional, same definition as method1): defines the second of the potentially two methods to be used. When method2 is defined, the following property is also required:
method1Proportion (1 >= Float >= 0): Defines the proportion of subjects to be chosen by the first method. The rest will be selected by the second one.
nextGenerationSelectionMethods (Object, same definition as parentSelectionMethods with extra fillMethod property): defines up to two selection methods that will be used to select the next generation's composition.
fillMethod (String, ["parent", "all"]): name of the fill method to be used.
finishCriteria (Array of Objects): defines one or more algorithm's finish criteria. Each child object is defined as follows.
name (String, ["generationsCount", "time", "acceptableSolution", "content", "structure"]): name of the method as defined by the finishCriteria map in the Main class method loadGeneticAlgorithmDependencies. When name equals structure, an object named parameters, containing the following properties, is also required:
numberOfSubjectsToCompare (Integer > 0): Defines how many of the population's top performers will be analized to determine similarity across generations.
comparableGenerationsBeforeFinish (Integer > 0): Defines how many generations will analized subject's similarity have to persist the criteria is met.
Note: The algorithm's default tolerance is 0, which mean that, by default, two properties will only be considered similar when they are equal. Custom property-specific tolerance must be difined either in the implementation-specific configuration file (as in the Character example implementation provided) or in the implementation itself, through the isPropertySimilarWith method.
When name equals acceptableSolution, an object named parameters, containing the following properties, is also required:
acceptableFitness (Double): Defines the minimum fitness that has to be archived for the criteria to be met.
When name equals content, an object named parameters, containing the following properties, is also required:
generationsWithoutImprovementToFinish (Integer >= 0): Defines the number of generations in which the best fitness can persist unchallenged before the criteria is met.
When name equals generationsCount, an object named parameters, containing the following properties, is also required:
maxGenerations (Integer >= 0): Defines the number of generations to process before the criteria is met.
When name equals time, an object named parameters, containing the following properties, is also required:
durationSeconds (Integer >= 0): Defines the number of seconds from the start of the algorithm's evolving state until the criteria is met.
This is an implementation-specific second configuration file structure, written to work with the Character example GeneticSubject implementation.
implementationParameters (Object): defines Character class implementation parameters.
itemsPath (String, A valid path from the program's working directory): Path to the folder that contains items's tsb files. Each file will account from an item type, and consequently, a new Character property.
fixedProperties (Array of Objects, up to one per custom-implementation GeneticSubject property): Allows for Character properties to be fixed to a value through the program's execution.
propertyIndex (#Properties > Integer > 0): defines the property that the tolerance is defined for.
delta (Double > 0): defines the tolerance value.
propertiesComparatorDeltas (Array of Objects, up to one per custom-implementation GeneticSubject property): defines the tolerance, or delta, that is used to decide if two non-equal values of the same property are similar. Each object in the array is defined as follows.
propertyIndex (#Properties > Integer > 0): defines the property that the tolerance is defined for.
value (Implemented property's type, String for charClass): defines fixed property's value.