@zfunction/genetics-js
Version:
Genetic and evolutionary algorithms framework for the web
96 lines (95 loc) • 3.25 kB
TypeScript
import { MutableIndividual } from './../../base/';
import { NumericRange } from './NumericRange';
/**
* ## Numeric individual
* Numeric individual represents an individual
* with a numeric genotype, situated in a range.
*/
export declare abstract class NumericIndividual extends MutableIndividual<number> {
/**
* range of the individual.
*/
private _range;
/**
* Constructor of the class.
* Creates an individual given a numeric
* genotype.
* @param genotype of the individual.
* @param range of the individual, if not provided
* or undefined it is set to default range.
*/
protected constructor(genotype: number[], range?: NumericRange);
/**
* Setter of the range.
* @return the range of the individual.
*/
get range(): NumericRange;
/**
* Copy other individual into the current.
* Creates a shallow copy, with the references
* only.
* @param other individual to copy
*/
copy(other: NumericIndividual): void;
/**
* Creates a deep copy of the other individual
* in the current.
* @param other individual to copy.
*/
deepCopy(other: NumericIndividual): 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 gene is not in range.
*/
set(geneIndex: number, gene: number): void;
/**
* Fill the genotype with the specified gene.
* @param gene we want to fill the genotype with.
* @param start position. By default is `0`.
* @param end position. By default is the length of
* the individual.
* @throws RangeError if gene is not in range.
*/
fill(gene: number, 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.
* @throws RangeError if callback result is not in range.
*/
map(callback: (gene: number, geneIndex?: number, genotype?: number[]) => number): void;
/**
* Sets the individual range.
*
* @param range that we want to set,
* if it is `undefined` it is set with
* the default range.
* @throws Error if range is invalid.
* @throws RangeError if any gene of the genotype
* is not in range.
*/
protected setRange(range: NumericRange): void;
/**
* Checks if gene is in range.
* @param gene that we want to check.
* @throws RangeError if gene is not in range.
*/
protected checkGeneRange(gene: number): void;
/**
* Checks if all genes in genotype
* are in range. If it is not in
* range it throws a RangeError.
* @param genotype to be checked.
*/
protected checkGenotype(genotype: number[]): void;
/**
* Converts a gene to string, useful for method
* `toString`.
* @param gene that we are converting.
*/
protected geneToString(gene: number): string;
}