export type Options = { /** * The output should be updated in-place. * This design can reduce GC pressure with object pooling. * */ mutate: (input: G, output: G) => void; /** * default 0.5 * chance of doing mutation, otherwise will do crossover * */ mutationRate?: number; /** * The child should be updated in-place. * This design can reduce GC pressure with object pooling. * */ crossover: (aParent: G, bParent: G, child: G) => void; /** * higher is better * */ fitness: (gene: G) => number; /** * default only compare the fitness * custom function should consider both distance and fitness * */ doesABeatB?: (a: G, b: G) => boolean; population?: G[]; /** * default 100 * should be even number * */ populationSize?: number; /** * default randomly pick a gene from the population than mutate * */ randomIndividual?: () => G; /** * return floating number from 0 to 1 inclusively * default Math.random() * */ random?: () => number; }; export type AsyncOptions = Omit, 'fitness' | 'doesABeatB'> & { fitness: (gene: G) => Promise; doesABeatB?: (a: G, b: G) => Promise; }; type PopulationOptions = { population: G[]; } | { randomIndividual: () => G; }; export type RequiredOptions = Options & PopulationOptions; export type RequiredAsyncOptions = AsyncOptions & PopulationOptions; export type FullOptions = Required>; export type FullAsyncOptions = Required>; /** * in-place populate the options.population gene pool * */ export declare function populate(options: FullOptions | FullAsyncOptions): void; /** * Apply default options and populate when needed * */ export declare function populateOptions(_options: RequiredOptions): FullOptions; /** * Apply default options and populate when needed * */ export declare function populateOptionsAsync(_options: RequiredAsyncOptions): FullAsyncOptions; export declare class GaIsland { options: FullOptions; constructor(options: RequiredOptions); randomizePopulationOrder(): void; /** * should run populate() before invoking this function, * therefore assume options.population size is aligned with options.populationSize * */ compete(): void; /** * internally calls `this.randomizePopulationOrder()` and `this.compete()` */ evolve(): void; } export declare class GaIslandAsync { options: FullAsyncOptions; constructor(options: RequiredAsyncOptions); randomizePopulationOrder(): void; /** * should run populate() before invoking this function, * therefore assume options.population size is aligned with options.populationSize * */ compete(): Promise; /** * internally calls `this.randomizePopulationOrder()` and `this.competeAsync()` */ evolve(): Promise; } export {};