UNPKG

genetic-search

Version:

Multiprocessing genetic algorithm implementation library

100 lines (99 loc) 3.31 kB
import { BaseGenome, GeneticSearchInterface, PopulationSummary, SchedulerConfig, SchedulerInterface, SchedulerAction, SchedulerActionInput, EvaluatedGenome } from "./types"; /** * A scheduler for a genetic search algorithm. * * The scheduler is responsible for executing scheduled tasks or operations * in the genetic search algorithm. * * @template TGenome The type of genome objects in the population. * @template TConfig The type of configuration object of macro parameters, * which the scheduler will be able to manipulate. * * @category Scheduler */ export declare class Scheduler<TGenome extends BaseGenome, TConfig> implements SchedulerInterface<TGenome> { /** * An array of log messages generated by the scheduler. */ readonly logs: string[]; /** * A function to log messages. * * @param message - The message to log. */ protected readonly logger: (message: string) => void; /** * The genetic search runner. */ protected readonly runner: GeneticSearchInterface<TGenome>; /** * The configuration object of macro parameters, which the scheduler will be able to manipulate. */ protected readonly config: TConfig; /** * The maximum length of the history array. */ protected readonly maxHistoryLength: number; /** * The rules applied by the scheduler. */ protected readonly actions: SchedulerAction<TGenome, TConfig>[]; /** * The history of population summaries. */ protected history: PopulationSummary[]; /** * Constructor of the Scheduler class. * * @param params - The parameters to initialize the scheduler. */ constructor(params: SchedulerConfig<TGenome, TConfig>); /** * Executes a single step or iteration in the scheduler. */ step(evaluatedPopulation: EvaluatedGenome<TGenome>[]): void; /** * Handles the history of population summaries. * * Adds the current population summary to the history. If the history * exceeds the maximum allowed length, it trims the oldest entries. */ protected handleHistory(): void; /** * Constructs the input data for a scheduler rule. * * This input is used by both the `condition` and `action` functions * of a scheduler rule. * * @returns An object containing the runner, history, config, and logger. */ protected getRuleInput(evaluatedPopulation: EvaluatedGenome<TGenome>[]): SchedulerActionInput<TGenome, TConfig>; /** * Clears all the logs stored in the scheduler. */ protected clearLogs(): void; } /** * An exception thrown when a scheduler condition is not satisfied. * * This exception is thrown when a scheduler rule's condition function * returns false. * * @category Exceptions * @category Scheduler */ export declare class SchedulerConditionException extends Error { constructor(); } /** * Checks if a scheduler condition is satisfied. * * If the condition is not satisfied, this function throws a {@link SchedulerConditionException}`. * * @see SchedulerConditionException * * @param condition - The result of the scheduler condition check. * * @category Scheduler */ export declare function checkSchedulerCondition(condition: boolean): void;