import Cell from '../entities/Cell'; import Agent from '../entities/Agent'; import RandomGenerator from '../numbers/RandomGenerator'; import CellGrid from './CellGrid'; export default class AgentSet { private agents; /** * Generates an AgentSet from an array of agents. */ static fromArray(agents: T[]): AgentSet; /** * Generates an AgentSet from a Set of agents. */ static fromSet(agents: Set): AgentSet; /** * Generates an AgentSet from a factory function. * The factory function is called `count` times with an sequential index * and a non-sequential random seed. The function should return an Agent. */ static fromFactory(count: number, agentFactory: (index: number, randomSeed: number) => T, options?: { randomSeed?: number; }): AgentSet; constructor(); [Symbol.iterator](): Generator; toArray(): T[]; /** * Runs the 'act' method on all agents in the set. */ step(world: CellGrid, agentSets: { [key: string]: AgentSet; }, tick: number): void; /** * Inserts an agent into the set. * Optionally inserts the agent into the grid. */ add(agent: T, world?: CellGrid): void; /** * Removes an agent from the set. */ remove(agent: T): void; /** * Iterates over all agents in the set. */ forEach(callback: (agent: T, i: number) => void): void; /** * Maps a callback function over all agents in the set. */ map(callback: (agent: T, i: number) => U): U[]; /** * Gets the ith agent in the set. */ get(index: number): T | undefined; reduce(callback: (accumulator: U, agent: T) => U, initialValue: U): U; /** * Finds the Agent with the minimum value in the set of agents. * * Returns undefined if the set is empty. */ minimizeBy(fn: (agent: T) => number): T; /** * Finds the Agent with the maximum value in the set of agents. * * Returns undefined if the set is empty. * * @since 1.0.0 */ maximizeBy(fn: (agent: T) => number): T; /** * Returns the number of agents in the set. */ get size(): number; /** * Removes all dead agents from the set. * Note: This is handled automatically by the model. */ cullDeadAgents(): void; /** * Gets the agent at a location on a grid. */ getAgentAt(location: [number, number]): T | undefined; /** * Gets the nearest agent to a location. Returns undefined if the set is empty. */ getNearestAgentAt(world: CellGrid, location: [number, number], options?: { metric?: 'manhattan' | 'euclidean'; }): T | undefined; filter(predicate: (agent: T) => boolean): AgentSet; findFirst(predicate: (agent: T) => boolean): T | undefined; sortBy(compareFn: (a: T, b: T) => number): AgentSet; slice(start: number, end: number): AgentSet; /** * Gets all agents within a certain range of a location. */ getWithinRange(world: CellGrid, location: [number, number], range: number, options?: { metric?: 'manhattan' | 'euclidean'; }): AgentSet; /** * Gets the mean position of all agents in the set. */ getCentroid(): [number, number]; /** * Picks a single agent at random from the set. * Optionally provide a list of agents to exclude from the selection. * * Returns undefined if the set is empty. */ random(rng: RandomGenerator, options?: { exclude?: T[]; }): T | undefined; /** * Picks a random sample (without replacement) of agents from the set. * Optionally provide a list of agents to exclude from the sample. */ randomSample(rng: RandomGenerator, count: number, options?: { exclude?: T[]; }): AgentSet; private distance; }