Documentation ¶
Overview ¶
Package genetic provides functions to work with strings using genetic algorithm. https://en.wikipedia.org/wiki/Genetic_algorithm
Author: D4rkia
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Conf ¶
type Conf struct { // Maximum size of the population. // Bigger could be faster but more memory expensive. PopulationNum int // Number of elements selected in every generation for evolution // the selection takes. Place from the best to the worst of that // generation must be smaller than PopulationNum. SelectionNum int // Probability that an element of a generation can mutate changing one of // its genes this guarantees that all genes will be used during evolution. MutationProb float64 // Enables debugging output to the console. Debug bool }
Conf stands for configurations set provided to GeneticString function.
type PopulationItem ¶
Population item represent a single step in the evolution process. One can think of population item as a single species. Key stands for the actual data entity of the species, which is a string in current implementation. Key can be interpreted as species DNA. Value shows how close this species to the desired target, where 1 means, that species DNA equals to the targeted one, 0 for no matchings in the DNA.
**Note** In the current implementation species DNA length is suppose to be equal to the target length for algorithm to work.
type Result ¶
type Result struct { // Number of generations steps performed. Generation int // Number of generated population items. Analyzed int // Result of generation with the best Value. Best PopulationItem }
Result structure contains generation process statistics, as well as the best resulted population item.
func GeneticString ¶
GeneticString generates PopulationItem based on the imputed target string, and a set of possible runes to build a string with. In order to optimise string generation additional configurations can be provided with Conf instance. Empty instance of Conf (&Conf{}) can be provided, then default values would be set.
Link to the same algorithm implemented in python: https://github.com/TheAlgorithms/Python/blob/master/genetic_algorithm/basic_string.py