pub trait Runner<E, M: Model<E>, CS: ContinueStrategy<E, M, Self::Err>> {
type Err: Debug;
// Required method
fn run<F>(
&mut self,
engine: Engine<E, M>,
model: M,
should_stop: F,
) -> SimulationResult<M, CS::Err>
where F: FnMut(&M, ExecutorStatus, TickStatus) -> bool;
// Provided methods
fn run_playback<F>(
&mut self,
engine: Engine<E, M>,
model: M,
duration: Duration,
should_stop: F,
) -> SimulationResult<M, CS::Err>
where F: FnMut(&M, ExecutorStatus, TickStatus) -> bool { ... }
fn run_do_ticks(
&mut self,
engine: Engine<E, M>,
model: M,
tick_count: TimeTick,
include_zero_tick: bool,
) -> SimulationResult<M, CS::Err> { ... }
fn run_until_idle(
&mut self,
engine: Engine<E, M>,
model: M,
) -> SimulationResult<M, CS::Err> { ... }
fn run_until_model_condition<F>(
&mut self,
engine: Engine<E, M>,
model: M,
should_stop_model_condition: F,
) -> SimulationResult<M, CS::Err>
where F: FnMut(&M) -> bool { ... }
fn run_batch_parallel<MF, EF, F>(
&self,
count: usize,
engine_builder: EF,
model_builder: MF,
should_stop: F,
) -> Vec<SimulationResult<M, CS::Err>> ⓘ
where Self: Clone + Sync,
EF: Fn(usize) -> Engine<E, M> + Sync,
M: Send,
MF: Fn(usize) -> M + Sync,
F: FnMut(&M, ExecutorStatus, TickStatus) -> bool + Clone + Sync,
CS::Err: Send { ... }
}Expand description
A trait defining the execution policy for simulation engines.
The Runner orchestrates the interaction between a Model and an Engine.
It provides a standardized interface for different execution strategies—such
as synchronous execution, playback, or parallel batch processing—allowing
the user to control how the simulation proceeds over time.
Required Associated Types§
Required Methods§
Sourcefn run<F>(
&mut self,
engine: Engine<E, M>,
model: M,
should_stop: F,
) -> SimulationResult<M, CS::Err>
fn run<F>( &mut self, engine: Engine<E, M>, model: M, should_stop: F, ) -> SimulationResult<M, CS::Err>
The core, low-level method for driving the simulation.
§Arguments
engine- The engine managing the event scheduler and context.model- The initial model state.should_stop- A closure invoked before each tick to evaluate termination conditions. As anFnMut, it can track internal state like retry counts or cumulative errors to trigger dynamic stops.
Provided Methods§
Sourcefn run_playback<F>(
&mut self,
engine: Engine<E, M>,
model: M,
duration: Duration,
should_stop: F,
) -> SimulationResult<M, CS::Err>
fn run_playback<F>( &mut self, engine: Engine<E, M>, model: M, duration: Duration, should_stop: F, ) -> SimulationResult<M, CS::Err>
Advances the simulation while inserting a specified delay between ticks.
Ideal for GUI/CUI visualizations or debugging where the simulation progress needs to be observable by a human.
Sourcefn run_do_ticks(
&mut self,
engine: Engine<E, M>,
model: M,
tick_count: TimeTick,
include_zero_tick: bool,
) -> SimulationResult<M, CS::Err>
fn run_do_ticks( &mut self, engine: Engine<E, M>, model: M, tick_count: TimeTick, include_zero_tick: bool, ) -> SimulationResult<M, CS::Err>
Advances the simulation until a specific tick count is reached.
If the Runner implementation optimizes by skipping time periods, this
method ensures a safe exit at the first appropriate processing step
exceeding the specified threshold.
Sourcefn run_until_idle(
&mut self,
engine: Engine<E, M>,
model: M,
) -> SimulationResult<M, CS::Err>
fn run_until_idle( &mut self, engine: Engine<E, M>, model: M, ) -> SimulationResult<M, CS::Err>
Automatically advances the simulation until the event queue is exhausted (idle).
Sourcefn run_until_model_condition<F>(
&mut self,
engine: Engine<E, M>,
model: M,
should_stop_model_condition: F,
) -> SimulationResult<M, CS::Err>
fn run_until_model_condition<F>( &mut self, engine: Engine<E, M>, model: M, should_stop_model_condition: F, ) -> SimulationResult<M, CS::Err>
Advances the simulation until the model’s internal state satisfies a condition.
Allows for domain-specific termination criteria, such as reaching a production target or a specific KPI threshold.
Sourcefn run_batch_parallel<MF, EF, F>(
&self,
count: usize,
engine_builder: EF,
model_builder: MF,
should_stop: F,
) -> Vec<SimulationResult<M, CS::Err>> ⓘ
fn run_batch_parallel<MF, EF, F>( &self, count: usize, engine_builder: EF, model_builder: MF, should_stop: F, ) -> Vec<SimulationResult<M, CS::Err>> ⓘ
Executes multiple simulation trials in parallel across multiple CPU cores.
Useful for Monte Carlo simulations or parametric studies. Each thread constructs its own independent instance using the provided builders.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.