Class Simulation<ChromosomeType, FitnessType>

Description

Simulates a genetic algorithm.

Type Parameters

Hierarchy

  • Simulation

Constructors

  • new Simulation<ChromosomeType, FitnessType>(properties: SimulationOptions<ChromosomeType, FitnessType>): Simulation<ChromosomeType, FitnessType>

Properties

currentGeneration: number = 0

Defines the current generation of the simulation

population: Agent<ChromosomeType, FitnessType>[] = []

Population of the simulation

properties: SimulationOptions<ChromosomeType, FitnessType>

Methods

  • computeScores(): Promise<FitnessType[]>
  • Description

    Computes the stores of the agents in parallel and awaits for the finish of the computation of all the stores.

    Returns

    The scores of the agents.

    Returns Promise<FitnessType[]>

  • Description

    the stats of the obtained scores.

    Returns

    The stats of the obtained scores.

    Parameters

    • scores: AgentWithScore<ChromosomeType, FitnessType>[]

      The scores of the agents.

    Returns SimulationStats<ChromosomeType, FitnessType>

  • generateChildren(parents: AgentParents<ChromosomeType, FitnessType>): Agent<ChromosomeType, FitnessType>[]
  • Description

    Generates the children of the selected agents.

    Returns

    The children of the selected agents.

    Parameters

    • parents: AgentParents<ChromosomeType, FitnessType>

      The generator of the selected agents.

    Returns Agent<ChromosomeType, FitnessType>[]

  • getParents(agents: Agent<ChromosomeType, FitnessType>[]): AgentParents<ChromosomeType, FitnessType>
  • Description

    Gets the parents of the selected agents.

    Returns

    A generator of pairs of parents.

    Parameters

    • agents: Agent<ChromosomeType, FitnessType>[]

      The selected agents.

    Returns AgentParents<ChromosomeType, FitnessType>

  • run(stopCondition?: StopCondition<ChromosomeType, FitnessType>, fromStart?: boolean): Promise<SimulationStats<ChromosomeType, FitnessType>>
  • Description

    Runs the simulation.

    Returns

    The final population of agents.

    Parameters

    • stopCondition: StopCondition<ChromosomeType, FitnessType> = ...

      Defines when the simulation must stop. If not specified, the simulation will run indefinitely.

    • fromStart: boolean = true

      If true, the simulation will generate the initial population and start from the first generation.

    Returns Promise<SimulationStats<ChromosomeType, FitnessType>>

  • sortByScore(scores: FitnessType[]): AgentWithScore<ChromosomeType, FitnessType>[]
  • Description

    Sorts the agents by score.

    Returns

    The sorted agents with an appended score field.

    Parameters

    • scores: FitnessType[]

      The scores of the agents.

    Returns AgentWithScore<ChromosomeType, FitnessType>[]

Generated using TypeDoc