The AlterResult struct is used to represent the result of an
alteration operation. It contains the number of operations
performed and a vector of metrics that were collected
during the alteration process.
Arithmetic Mutator. Mutates genes by performing arithmetic operations on them.
The ArithmeticMutator takes a rate parameter that determines the likelihood that
a gene will be mutated. The ArithmeticMutator can perform addition, subtraction,
multiplication, and division on genes.
A Codex for a Genotype of BitGenes. The encode function creates a Genotype with num_chromosomes chromosomes
and num_genes genes per chromosome. The decode function creates a Vec<Vec<bool>> from the Genotype where the inner Vec
contains the alleles of the BitGenes in the chromosome - the bool values.
A gene that represents a single bit. The allele is a bool that is randomly assigned.
The allele is either true or false. This is the simplest form of a gene and
in traditional genetic algorithms is the gene that is used to represent the individuals.
A Codex for a Genotype of CharGenes. The encode function creates a Genotype with num_chromosomes chromosomes
and num_genes genes per chromosome. The decode function creates a String from the Genotype where the String
contains the alleles of the CharGenes in the chromosome.
Replacement strategy that replaces the individual with a new one generated by the encoder.
This is the default replacement strategy used in genetic algorithms.
A Codex for a Genotype of FloatGenes. The encode function creates a Genotype with num_chromosomes chromosomes
and num_genes genes per chromosome. The decode function creates a Vec<Vec<f32>> from the Genotype where the inner Vec
contains the alleles of the FloatGenes in the chromosome - the f32 values.
A Gene that represents a floating point number.
The allele is the in the case of the FloatGene a f32. The min and max values
default to f32::MIN and f32::MAX respectively. The min and max values are used to
generate a random number between the min and max values, which is the allele of the FloatGene.
The upper_bound and lower_bound are used to set the bounds of the FloatGene when it is used
in a BoundGene context (crossover or mutation). The upper_bound and lower_bound
default to f32::MAX and f32::MIN respectively.
A Codex that uses functions to encode and decode a Genotype to and from a type T.
Most of the other codexes in this module are more specialized and are used to create Genotypes of specific types of Chromosomes.
This one, however, is more general and can be used to create Genotypes of any type of Chromosome.
A front is a collection of scores that are non-dominated with respect to each other.
This is useful for multi-objective optimization problems where the goal is to find
the best solutions that are not dominated by any other solution.
This results in what is called the Pareto front.
The Genotype struct represents the genetic makeup of an individual. It is a collection of Chromosome instances, it is
essentially a light wrapper around a Vec of Chromosomes. The Genotype struct, however, has some additional functionality
and terminology that aligns with the biological concept of a genotype.
In traditional biological terms, a Genotype is the set of genes in our DNA that determine a specific trait or set of traits.
The Genotype is the ‘genetic’ part of the individual that is being evolved by the genetic algorithm.
A Codex for a Genotype of IntGenes. The encode function creates a Genotype with num_chromosomes chromosomes
and num_genes genes per chromosome. The decode function creates a Vec<Vec<T>> from the Genotype where the inner Vec
contains the alleles of the IntGenes in the chromosome. T must implement the Integer trait, meaning it must be one of
i8, i16, i32, i64, i128, u8, u16, u32, u64, or u128.
A Gene that represents an integer value. This gene just wraps an integer value and provides
functionality for it to be used in a genetic algorithm. In this Gene implementation, the
allele is the integer value itself, the min and max values are the minimum and maximum values
that the integer can be generated from, and the upper and lower bounds are the upper and lower bounds the gene will
be subject to during crossover and mutation. If the allele exceedes the bounds, the Gene will be considered invalid.
Intermediate Crossover. This crossover method takes two chromosomes and crosses them
by taking a weighted average of the two alleles. The weight is determined by the alpha
parameter. The new allele is calculated as:
The MeanCrossover is a simple crossover method that replaces the genes of the first chromosome
with the mean of the two genes. The mean is calculated by adding the two genes together and dividing
by two.
Adds various metrics to the output context, including the age of individuals, the score of individuals,
and the number of unique scores in the population. These metrics can be used to monitor the progress of
the genetic algorithm and to identify potential issues or areas for improvement.
The MultiPointCrossover is a crossover method that takes two chromosomes and crosses them
by selecting multiple points in the chromosome and swapping the genes between the two chromosomes.
The number of points to swap is determined by the num_points parameter and must be between 1 and the
length of the chromosome. Note, in most cases having more than 2 points is not useful and actually
reduces the effectiveness of the crossover. However, it can be useful in some cases so it is allowed.
NSGA2 Selector. Selects individuals based on the NSGA2 algorithm.
This algorithm ranks individuals based on their dominance relationships
with other individuals in the population. The result is a vector of ranks,
where the rank of the individual at index i is ranks[i].
Individuals are then selected based on their rank and crowding distance.
The crowding distance is a measure of how close an individual is to its
neighbors in the objective space. Individuals with a higher crowding distance
are more desirable because they are more spread out. This is useful for selecting
diverse solutions in a multi-objective optimization problem. It uses ‘fast non-dominated sorting’
The PermutationGene is a gene that represents a permutation of a set of alleles. The gene has an index
that represents the position of the allele in the alleles vector. The alleles vector is a set of unique
values. The gene is valid if the index is less than the length of the alleles vector. This gene is useful
for representing permutations of values, such as the order of cities in a TSP problem.
A Population is a collection of Phenotype instances. This struct is the core collection of individuals
being evolved by the GeneticEngine. It can be thought of as a Vec of Phenotypes and
is essentially a light wrapper around such a Vec. The Population struct, however, has some
additional functionality that allows for sorting and iteration over the individuals in the population.
Replacement strategy that replaces the individual with a random member of the population.
This can be useful in cases where the population is large and diverse or when the
chromosome grows or changes in size, thus encoding a new individual can result
in a member that that lacks significant diversity.
An iterator that generates random indices based on probabilities.
This iterator is used in the RouletteWheel selection algorithm, and
Boltzmann selection algorithm. This is essentially the ‘roulette wheel’
that is spun to select individuals from the population. The probability
of selecting an individual is based on the fitness (probability) of the individual.
The higher the fitness, the higher the probability of the individual being selected.
A score is a value that can be used to compare the fitness of two individuals and represents
the ‘fitness’ of an individual within the genetic algorithm.
The score can be a single value or multiple values, depending on the problem being solved.
For ease of use the Score struct provides methods
to convert the score to a single value, an integer, a string, or a vector of f32 values.
A Codex for a subset of items. This is useful for problems where the goal is to find the best subset of items
from a larger set of items. The encode function creates a Genotype with a single chromosome of BitGenes
where each gene represents an item in the items vector. The decode function creates a Vec<&T> from the
Genotype where the Vec contains the items that are selected by the BitGenes - the true genes.
The AlterAction enum is used to represent the different
types of alterations that can be performed on a
population - It can be either a mutation or a crossover operation.
This is the main trait that is used to define the different types of alterations that can be
performed on a population. The Alter trait is used to define the alter method that is used
to perform the alteration on the population. The alter method takes a mutable reference to
the population and a generation number as parameters. The alter method returns a vector of
Metric objects that represent the metrics that were collected during the alteration process.
A Gene that represents a number. This gene can be used to represent any type of number,
including integers, floats, etc. Essentially, any gene that can Add, Sub, Mul, and Div
can be used as a ArithmeticGene.
The Chromosome struct represents a collection of Gene instances. The Chromosome is part of the
genetic makeup of an individual. It is a collection of Gene instances, it is essentially a
light wrapper around a Vec of Genes. The Chromosome struct, however, has some additional
functionality and terminology that aligns with the biological concept of achromosome
The Codex is a core concept in Radiate, as it allows for the encoding and decoding from
a Genotype to the type T (commonly called Phenotype in biology) that is being optimized.
A trait for selection algorithms. Selection algorithms are used to select
individuals from a population to be used in the next generation. The
selection process is (most of the time) based on the fitness of the individuals in the
population. The selection process can be based on the fitness of the individuals
in the population, or it can be based on the individuals themselves.
A Valid type is a type that can be checked for validity. This is used for checking if a gene
or a chromosome is valid. For example, a gene that represents a number between 0 and 1 can be checked
for validity by ensuring that the allele is between 0 and 1.