@evolite/core
    Preparing search index...

    Class GeneticAlgorithm<Entity>

    Main class for running an asynchronous Genetic Algorithm. Allows optimizing (maximizing or minimizing) a population of entities based on custom fitness, selection, crossover, and mutation functions. *

    Type Parameters

    Index
    fitnessFunction?: fitnessFunction<Entity>

    Fitness evaluation function.

    generation: number = 1

    The current generation number in the evolutionary process. Starts at 1 and increments with each successful evolution step.

    population: Entity[]

    The current population of individuals in their current evolutionary state.

    • Starts or continues the evolution process for a given number of generations. The process will stop early if the fitnessObjective is met or if stop() is manually invoked. *

      Parameters

      • generations: number

        The maximum number of generations/cycles to run.

      • Optionalcallback: (
            generation: number,
            population: Entity[],
            fittest: Entity,
        ) => void | Promise<void>

        Optional lifecycle callback triggered after each generation completes.

      Returns Promise<Entity>

      A promise that resolves with the fittest individual found in the final population.

      If the population becomes empty or corrupted at any point during evolution.

    • Stops any active execution and fully resets the state of the algorithm (generation back to 1 and population reset to the original initial population).

      Returns void

    • Immediately stops the ongoing asynchronous evolution process (evolve) upon completing the current step.

      Returns void