pub struct Simulation<S> { /* private fields */ }Expand description
The overarching simulation state. Contains the scenario being modelled, the current state of the simulation, as well as a cursor pointing to the next event in the timeline that is scheduled to be applied.
Implementations§
Source§impl<S> Simulation<S>
Methods for affecting control over the simulation. Most of these emit a broad SimulationError
if something goes wrong, with a specific error variant for each envisaged error type. Not all
methods use every available SimulationError variant.
impl<S> Simulation<S>
Methods for affecting control over the simulation. Most of these emit a broad SimulationError
if something goes wrong, with a specific error variant for each envisaged error type. Not all
methods use every available SimulationError variant.
Check the documentation of each method for the specific variants that are returned by that method, bearing in mind that the variants that a method is allowed to return may change over time.
Sourcepub fn step(&mut self) -> Result<(), SimulationError<S>>
pub fn step(&mut self) -> Result<(), SimulationError<S>>
Evaluates the next event in the timeline, applying it to the current state to transition to the next state.
§Errors
SimulationError if an error occurs. Expected variants:
SimulationError::TimelineExhausted, if the cursor is already parked at the end of the timeline.SimulationError::Transition, if the event could not be evaluated.
Sourcepub fn reset(&mut self)where
S: Clone,
pub fn reset(&mut self)where
S: Clone,
Resets the simulation, reinitialising the current state from the initial state specified in the simulation scenario, and resetting the cursor to location 0.
Sourcepub fn jump(&mut self, location: usize) -> Result<(), SimulationError<S>>where
S: Clone,
pub fn jump(&mut self, location: usize) -> Result<(), SimulationError<S>>where
S: Clone,
Jumps to a specified location in the timeline and evaluates the event at that location.
§Errors
SimulationError if an error occurs. Expected variants:
SimulationError::TimelineExhausted, if the cursor is already parked at the end of the timeline.SimulationError::Transition, if the event could not be evaluated.
Sourcepub fn run(&mut self) -> Result<(), SimulationError<S>>
pub fn run(&mut self) -> Result<(), SimulationError<S>>
Evaluates the remaining events in the timeline.
§Errors
SimulationError if an error occurs. Expected variants:
SimulationError::TimelineExhausted, if the cursor is already parked at the end of the timeline.SimulationError::Transition, if the event could not be evaluated.
Sourcepub fn push_event(
&mut self,
event: Box<dyn Event<State = S>>,
) -> Result<(), SimulationError<S>>
pub fn push_event( &mut self, event: Box<dyn Event<State = S>>, ) -> Result<(), SimulationError<S>>
Appends an event to the timeline at the current cursor location, assuming that there are no events at and beyond that location.
§Errors
SimulationError if an error occurs. Expected variants:
SimulationError::TruncationRequired, if there is already an event at the cursor location. The error returns the event object that is otherwise consumed by this method.
Sourcepub fn truncate(&mut self)
pub fn truncate(&mut self)
Truncates the timeline at the current cursor location, dropping all events at and beyond this point.
Sourcepub fn set_scenario(&mut self, scenario: Scenario<S>)where
S: Clone,
pub fn set_scenario(&mut self, scenario: Scenario<S>)where
S: Clone,
Assigns a new scenario, resetting the simulation in the process.
Sourcepub fn current_state(&self) -> &S
pub fn current_state(&self) -> &S
A reference to the current simulation state.