Simulation

interface Simulation<T, P : Position<out P>> : Runnable

A simulation, running as an independent thread and controllable from an external console.

Type Parameters

T

concentration type

P

position type

Inheritors

Properties

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

The environment of this simulation. It is not a copy, but the actual environment used in the simulation: manipulate it carefully.

Link copied to clipboard
abstract val error: Option<Throwable>

The exception that made the simulation fail, or arrow.core.None if the simulation is ongoing or has terminated successfully.

Link copied to clipboard

The OutputMonitors currently attached to this simulation.

Link copied to clipboard
abstract val state: SimulationState

The current SimulationState of the simulation.

Link copied to clipboard
abstract val step: Long

The current simulation step.

Link copied to clipboard
abstract val time: Time

The current simulation time.

Functions

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

Adds an OutputMonitor to this simulation.

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

Executes the simulation up to steps steps, then pauses it. The returned future completes when the steps are executed.

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

Executes the simulation until the target time time is reached, then pauses it. The returned future completes when the target time is reached.

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

Sends a pause command to the simulation. There is no guarantee on when this command will be actually processed. The returned future completes when the simulation is paused.

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

Sends a play command to the simulation. There is no guarantee on when this command will be actually processed. The returned future completes when the simulation is played.

Link copied to clipboard
abstract 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
abstract 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
abstract 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
abstract fun removeOutputMonitor(monitor: OutputMonitor<T, P>)

Removes an OutputMonitor from this simulation. If monitor was not among those already added, nothing happens.

Link copied to clipboard
abstract fun run()
Link copied to clipboard

Runs an existing Simulation in the current thread.

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

Schedules action to be executed by the simulation thread, useful for synchronization purposes (e.g., make sure that the environment is not being changed while the requested operation is being executed). An exception thrown by action makes the simulation terminate.

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

Sends a terminate command to the simulation. There is no guarantee on when this command will be actually processed. The returned future completes when the simulation is terminated.

Link copied to clipboard
Link copied to clipboard
abstract fun waitFor(state: SimulationState, timeout: Long, timeunit: TimeUnit): SimulationState

Suspends the caller until the simulation reaches the selected SimulationState, or the timeout, expressed in timeunit, expires. Waiting for a status does not mean that every OutputMonitor has already been notified of the update.