Skip to main content

Runner

Trait Runner 

Source
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§

Source

type Err: Debug

Implementation-specific error type that may occur during simulation.

Required Methods§

Source

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 an FnMut, it can track internal state like retry counts or cumulative errors to trigger dynamic stops.

Provided Methods§

Source

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.

Source

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.

Source

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).

Source

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,

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.

Source

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,

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.

Implementors§

Source§

impl<E, Command, M, CS: ContinueStrategy<E, M, ()>> Runner<E, M, CS> for ParallelRunner<Command, CS>
where E: Send + 'static, M: Send + Sync + 'static + ParallelModel<E, Command>, Command: Send,

Source§

impl<E, M: Model<E>, CS: ContinueStrategy<E, M, ()>> Runner<E, M, CS> for RealtimeRunner<CS>

Source§

impl<E, M: Model<E>, CS: ContinueStrategy<E, M, ()>> Runner<E, M, CS> for StandardRunner<CS>