import type { SimEvent } from '../types/events.ts'; import type { SimComponent } from '../types/components.ts'; import type { ConnectionDefinition, SimulationConfig } from '../types/models.ts'; import { MetricCollector } from './metric-collector.ts'; import { SeededRNG } from './prng.ts'; import type { FailureInjector } from './failure-injector.ts'; /** Simulation execution status */ export declare enum SimulationStatus { IDLE = "idle", RUNNING = "running", PAUSED = "paused", COMPLETED = "completed" } /** * Core discrete-event simulation engine. * * Processes events in timestamp order from a priority queue, dispatches them * to target components, and collects metrics. The simulation clock advances * monotonically to each event's timestamp. * * Validates: Requirements 1.1, 1.2, 1.3, 1.4, 1.5, 12.1–12.5 */ export declare class SimulationEngine { /** Event priority queue ordered by (timestamp, insertionOrder) */ private eventQueue; /** Registered simulation components keyed by id */ private components; /** Downstream connection map: componentId → downstream componentIds[] */ private downstreamMap; /** Connection definitions by ID, for network partition lookups */ private connectionById; /** Metric collector instance */ private metrics; /** Seeded PRNG for deterministic randomness */ private rng; /** Current simulation clock (monotonically non-decreasing) */ private _currentTime; /** Current engine status */ private _status; /** Speed multiplier (used by the worker for pacing) */ private _speedMultiplier; /** Configured simulation end time */ private endTime; /** Seed for PRNG (stored for reset) */ private seed; /** Flag set by pause() to interrupt the run loop */ private pauseRequested; /** Monotonic counter for deterministic ID generation */ private _nextIdCounter; /** ID of the component currently being dispatched to (for partition checks) */ private currentDispatchId; /** Initial components for reset */ private initialComponents; /** Initial connections for reset */ private initialConnections; /** Optional failure injector for handling failure-inject/failure-recover events */ private failureInjector; constructor(components: SimComponent[], connections: ConnectionDefinition[], config: SimulationConfig); get currentTime(): number; get status(): SimulationStatus; get speedMultiplier(): number; get queueSize(): number; getMetrics(): MetricCollector; getRng(): SeededRNG; /** Generate a deterministic unique ID */ nextId(): string; /** Set the failure injector for handling failure events during simulation */ setFailureInjector(injector: FailureInjector): void; /** Insert an initial event into the queue (e.g., first client arrivals, failure injections) */ scheduleEvent(event: SimEvent): void; /** * Run the simulation continuously until paused, queue empty, or endTime reached. * Req 12.1: "play" command runs simulation continuously. */ run(): void; /** * Pause the simulation, preserving state. * Req 12.2: "pause" halts event processing while preserving state. */ pause(): void; /** * Process exactly one event and then pause. * Req 12.3: "step" processes exactly one event. */ step(): boolean; /** * Restore the simulation to its initial state. * Req 12.5: "reset" restores initial state. */ reset(): void; /** * Set the speed multiplier. Actual pacing is done by the worker. * Req 12.4: configurable simulation speed multiplier. */ setSpeed(multiplier: number): void; /** * Process the next event from the queue. * Returns true if the simulation is done (queue empty or endTime reached). * * Req 1.1: Events processed in non-decreasing timestamp order (priority queue). * Req 1.2: New events from components are inserted into the queue. * Req 1.3: Terminates when queue is empty. * Req 1.4: Clock is monotonically non-decreasing. * Req 1.5: Terminates when endTime is reached. */ private processNextEvent; /** * Check whether an event is blocked by a network partition. * Only checks events between different components that are connected. */ private isEventBlocked; /** Peek at the next event without removing it (for debugging) */ peekNextEvent(): { timestamp: number; kind: string; targetComponentId: string; workUnitId: string; } | null; /** * Create a SimContext for component event handling. * Provides currentTime, scheduleEvent, getComponent, getDownstream, random, recordMetric. */ private createContext; } //# sourceMappingURL=simulation-engine.d.ts.map