Engine

open class Engine<T, P : Position<out P>>(environment: Environment<T, P>, scheduler: Scheduler<T>) : AbstractEngine<T, P>

Represents a simulation engine that manages execution and scheduling. Provides multiple factory methods to simplify the creation process.

Parameters

environment

the simulation environment

Type Parameters

T

the concentration type

P

the position type, extending Position

Constructors

Link copied to clipboard
constructor(environment: Environment<T, P>, scheduler: Scheduler<T>)
constructor(environment: Environment<T, P>)

Properties

Link copied to clipboard
override val environment: Environment<T, P>

the simulation environment

Link copied to clipboard
override var error: Option<Throwable>

The error that made the simulation fail, if any.

Link copied to clipboard

The registered output monitors, as a read-only view.

Link copied to clipboard

The current simulation status.

Link copied to clipboard
override val step: Long

The current step (thread-safe).

Link copied to clipboard
override val time: Time

The current simulation time (thread-safe).

Functions

Link copied to clipboard
open override fun addOutputMonitor(op: OutputMonitor<T, P>)

Adds an output monitor to track simulation events.

Link copied to clipboard
fun <T, P : Position<P>> Simulation<T, P>.equalsForSteps(other: Simulation<T, P>, steps: Long)
Link copied to clipboard
open override fun goToStep(steps: Long): CompletableFuture<Unit>

Moves the simulation forward until the given step is reached.

Link copied to clipboard
open override fun goToTime(time: Time): CompletableFuture<Unit>

Moves the simulation forward until the given time is reached.

Link copied to clipboard
open override fun pause(): CompletableFuture<Unit>

Pauses the simulation.

Link copied to clipboard
open override fun play(): CompletableFuture<Unit>

Resumes the simulation.

Link copied to clipboard
open override fun reactionAdded(reactionToAdd: Reaction<T>)

Notifies the simulation that a reaction host has registered reactionToAdd. Model code should register the reaction through its host; the host invokes this callback after membership actually changes. Adding a node invokes this callback once for each reaction already hosted by that node; node and topology changes have no separate simulation callback.

Link copied to clipboard
open override fun reactionInvalidated(reactionToUpdate: Reaction<T>)

Marks reactionToUpdate as a reaction whose observed scheduling inputs changed. The notification is synchronous and must originate on the simulation thread. The engine refreshes each affected reaction once when the enclosing model mutation completes.

Link copied to clipboard
open override fun reactionRemoved(reactionToRemove: Reaction<T>)

Notifies the simulation that a reaction host has unregistered reactionToRemove. Model code should unregister the reaction through its host; the host invokes this callback after membership actually changes. Removing a node invokes this callback once for each hosted reaction before disposing it.

Link copied to clipboard
open override fun removeOutputMonitor(monitor: OutputMonitor<T, P>)
Link copied to clipboard
open override fun run()

Internal method to run the simulation loop. Implementations must provide initialize, doStep, and hooks for run cycle.

Link copied to clipboard

Runs an existing Simulation in the current thread.

Link copied to clipboard
open override fun schedule(action: () -> Unit)

Schedules a task for execution.

Link copied to clipboard
fun <T, P : Position<P>, Vector<P>> Simulation<T, P>.startSimulation(onceInitialized: (EuclideanEnvironment<T, P>) -> Unit = { }, atEachStep: (EuclideanEnvironment<T, P>, Reaction<T>?, Time, Long) -> Unit = { _, _, _, _ -> }, whenFinished: (EuclideanEnvironment<T, P>, Time, Long) -> Unit = { _, _, _ -> }, steps: Long = 10000): EuclideanEnvironment<T, P>

Run the simulation this environment owns.

Link copied to clipboard
open override fun terminate(): CompletableFuture<Unit>

Terminates the simulation.

Link copied to clipboard
Link copied to clipboard
open override fun toString(): String
Link copied to clipboard
open override fun waitFor(state: SimulationState, timeout: Long, timeunit: TimeUnit): SimulationState

Waits for the simulation to reach a given status.