Skip to Content
DocumentationConfiguration

Configuration

The SimulationEngine accepts an options object to configure its behavior.

const sim = new SimulationEngine<Events, Store>({ seed: 42, // PRNG seed (default: Date.now()) maxTime: 1000, // stop at this simulation time (default: Infinity) maxEvents: 5000, // stop after N events (default: Infinity) logLevel: 'info', // 'debug' | 'info' | 'warn' | 'error' | 'silent' name: 'MySim', // log prefix (default: 'Simulation') realTimeDelay: 100, // ms delay between events in runAsync (default: 0) warmUpTime: 500, // reset stats after this sim-time (default: undefined) stopWhen: (ctx) => // custom stop condition (default: undefined) ctx.stats.get('queue').mean > threshold, store: { ... }, // initial global store value (default: {}) });

Options Reference

OptionTypeDefaultDescription
seednumberDate.now()PRNG seed for reproducibility
maxTimenumberInfinityStop when simulation clock reaches this value
maxEventsnumberInfinityStop after processing this many events
logLevelLogLevel'info'Minimum log level
loggerSimLoggerConsoleLoggerCustom logger implementation
namestring'Simulation'Simulation name (used in log prefixes)
realTimeDelaynumber0Delay in ms between events in runAsync
warmUpTimenumberundefinedStats are reset when clock crosses this threshold
stopWhen(ctx) => booleanundefinedCustom stop condition evaluated after each event
storeTStore{}Initial value for the global simulation store

Warm-up Period

The warmUpTime option automatically resets statistics after a transient phase, useful for steady-state analysis. After the clock crosses warmUpTime, ctx.warmUpCompleted becomes true and all stats are reset.

Custom Stop Conditions

The stopWhen callback is evaluated after each processed event. When it returns true, the simulation ends with status 'stopConditionMet'. Useful for optimization, steady-state detection, and Monte Carlo convergence.

Simulation Result

run() returns a SimulationResult:

const result = sim.run(); result.totalEventsProcessed // number of events handled result.totalEventsCancelled // number of cancelled events skipped result.finalClock // final simulation time result.wallClockMs // real-world execution time in ms result.stats // Record<string, StatsSummary> result.status // 'finished' | 'stopped' | 'maxTimeReached' | ... result.store // TStore — final state of the global store

Async Execution

For long simulations that shouldn’t block the Node.js event loop:

const result = await sim.runAsync();
Last updated on