Struct gas::gas::Gas

source · []
pub struct Gas<const N: usize, const NSYMS: usize> {
    pub fitness: FitnessConfig<N, NSYMS>,
    pub constraints: ConstraintConfig<N, NSYMS>,
    pub crossovers: CrossoverConfig<N, NSYMS>,
    pub mutations: MutationConfig<N, NSYMS>,
    pub cycle_tournament: Box<dyn Tournament<N, NSYMS> + Send + Sync>,
    pub final_tournament: Box<dyn Tournament<N, NSYMS> + Send + Sync>,
    pub taboo_distance: usize,
    pub population_size: usize,
}
Expand description

see module documentation

Fields

fitness: FitnessConfig<N, NSYMS>

the set of fitness functions that turn a chromosone into a set of fitness scores

constraints: ConstraintConfig<N, NSYMS>

constraints determine whether chromosones are valid or invalid

crossovers: CrossoverConfig<N, NSYMS>

crossovers and constraints are the heart of a genetic algorithm.

mutations: MutationConfig<N, NSYMS>

crossovers and constraints are the heart of a genetic algorithm.

cycle_tournament: Box<dyn Tournament<N, NSYMS> + Send + Sync>

this is the tournament used in the algorithm, so is typically called millions of times. faster, less accurate tournaments may therefore provide better results due to their speedup.

final_tournament: Box<dyn Tournament<N, NSYMS> + Send + Sync>

used at the end of a cycle, a comprehensive tournament is best

taboo_distance: usize

to ensure genetic diversity, the hamming distance between any two chromosones in the population must be at least this value

population_size: usize

Implementations

  • Given a population, run multiple [Gas.generation]’s of the algorithm until it stagnates and then return the winner.
  • This function is designed to be run in a thread, it keeps the CycleProgress
  • structure updated which allows the function to be monitored on the fly.
  • There are four phases to the algorithm.
    1. Seeding: Starting with a set of random candidates, iterate [Gas.generation] until the top
  • candidate either has zero constraint violations or the number of constraint
  • violations has stabilized. Add the candidate to the seed and then restart
  • with another set of random candidates. Repeat until you’ve accumulated
  • population_size number of seeds.
    1. Running: Iterate [Gas.generation] until both the score and number of violations has stagnated.
    1. Stagnated: Keep running the GA, doing a biased sampling of the winners
  • until we’ve got enough samples or we’ve been doing this step for too long.
    1. Do a final tournament of the winners do get the grand winner, which we return.

Given one generation of candidates, create the next generation. The heart of the GA.

Each generation consists of the following steps:

  1. Run a Tournament to order the candidates.
  2. Loop for each new child: a. Select two parents. Parent selection is biased by Tournament score and prefers selecting dissimilar parents. b. Choose a Crossover algorithm to run on the two parents to create a child. c. Choose a Mutation algorithm to run on the child

These arguments could be calculated inside this function rather than outside, but are taken as parameters so they don’t have to be recalculated every generation:

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.