The Alchemist Simulation Engine

The core part of the tool is the incarnation-agnostic simulation engine. Its current implementation is based on Gibson and Bruck’s Next Reaction, extended to support adding and removing reactions and nodes while a simulation is running.

The engine’s entry point is Simulation. It provides commands such as play, pause, and stop and publishes simulation progress to OutputMonitor implementations. The output monitor can be a graphical interface, a logger or any kind of environment inspector.

Reaction occurrence ownership, condition-driven invalidation, and the initialization, firing, and removal transitions are model semantics. They are described in Reaction Scheduling and Ownership.

Engine responsibilities

Each Reaction publishes its absolute nextOccurrence. The engine owns the simulation clock, command processing, output-monitor notifications, runtime scheduling subscriptions, and the scheduler that selects the earliest occurrence.

For each active reaction, the engine owns one exact subscription to nextOccurrence. Reaction executions and scheduled commands form model-mutation transactions: direct invalidation callbacks mark affected reactions dirty, and the engine refreshes each of them once when the mutation completes. Each resulting occurrence emission causes the scheduler to reindex that reaction immediately. Reaction registration, occurrence updates, scheduler operations, and removal are confined to the simulation thread; external mutations must enter through the simulation command queue.

Nodes and reactions may be added or removed while a simulation is running. Registration initializes the reaction before scheduler insertion, while removal releases the engine-owned subscription before removing the scheduler entry and disposing the reaction.