UNPKG

@zfunction/genetics-js

Version:

Genetic and evolutionary algorithms framework for the web

59 lines (58 loc) 2.15 kB
import { BaseIndividual, Mutable } from './index'; /** * ## Mutable Individual * Provides a basic implementation of the mutable interface. * Also extends BaseIndividual class. */ export declare abstract class MutableIndividual<T> extends BaseIndividual<T> implements Mutable<MutableIndividual<T>, T> { /** * Copy other individual into the current. * Creates a shallow copy, with the references * only. * @param other individual to copy */ copy(other: MutableIndividual<T>): void; /** * Abstract method for creating a deep * copy of the other individual * in the current. * @param other individual to copy. */ abstract deepCopy(other: MutableIndividual<T>): void; /** * Transfers a copy of a section of the genotype * between different parts of it. * @param target position where to start the copy. * @param start position of the desired section. By default is `0`. * @param end position of the desired section, * by default is the length of the individual. */ copyWithin(target: number, start?: number, end?: number): void; /** * Fill the genotype with the specified gene. * @param gene we want to fill the genotype with. * @param start position of the fill, by default is `0`. * @param end position of the fill, by default is * the length of the genotype. */ fill(gene: T, start?: number, end?: number): void; /** * Creates a new genotype with the result of * the execution of the specified callback for each * element. * @param callback called for each gene. */ map(callback: (gene: T, geneIndex?: number, genotype?: T[]) => T): void; /** * Reverses the genotype. */ reverse(): void; /** * Sets the gene at specified index to * the specified value. * @param geneIndex index of the gene to be set. * @param gene new value of the gene. * @throws RangeError if index is not in range [0-length) */ set(geneIndex: number, gene: T): void; }