Skip to main content

SpawnSchedule

Struct SpawnSchedule 

Source
pub struct SpawnSchedule { /* private fields */ }
Expand description

Fluent builder for TimedSpawn sequences that feed Scenario::spawns.

Unifies two common authoring shapes in one place:

  • Deterministic bursts (fixed origin/destination, fixed tick or regular cadence), where exact tick counts matter — e.g. “20 riders leave the lobby at tick 0”, “1 rider every 600 ticks for 10 minutes”.
  • Poisson draws from a TrafficPattern, where the origin/destination pair is stochastic but the arrival process is exponential.

The final Vec<TimedSpawn> is extracted via into_spawns and handed to Scenario::spawns. Scenarios with mixed shapes chain builders via merge:

use elevator_core::scenario::SpawnSchedule;
use elevator_core::stop::StopId;

let schedule = SpawnSchedule::new()
    .burst(StopId(0), StopId(5), 10, 0, 70.0)
    .staggered(StopId(0), StopId(3), 5, 1_000, 300, 70.0);
assert_eq!(schedule.len(), 15);

Implementations§

Source§

impl SpawnSchedule

Source

pub const fn new() -> Self

Create an empty schedule.

Source

pub fn burst( self, origin: StopId, destination: StopId, count: usize, at_tick: u64, weight: f64, ) -> Self

Append count identical spawns, all firing on at_tick. Use this for the classic “crowd appears simultaneously” shape (morning stand-up, event dismissal).

Source

pub fn staggered( self, origin: StopId, destination: StopId, count: usize, start_tick: u64, stagger_ticks: u64, weight: f64, ) -> Self

Append count spawns starting at start_tick, each stagger_ticks apart. A stagger_ticks = 0 degenerates to burst. Use this for deterministic arrival cadences — e.g. “one rider every 10 seconds” — where Poisson variance would obscure the test signal.

Source

pub fn from_pattern( self, pattern: TrafficPattern, stops: &[StopId], duration_ticks: u64, mean_interval_ticks: u32, weight_range: (f64, f64), rng: &mut impl RngExt, ) -> Self

Append Poisson-distributed spawns from a TrafficPattern over duration_ticks, with exponential inter-arrival times of mean mean_interval_ticks. weight_range is a uniform draw per spawn. The supplied rng advances but is not taken — callers can continue using it for other deterministic draws.

stops must be sorted by position (lobby first) to match TrafficPattern’s lobby-origin peak-pattern assumption. See TrafficPattern::sample_stop_ids.

Returns the schedule with generated spawns appended. If stops has fewer than 2 entries, no spawns are generated (pattern sampling requires at least two stops).

Requires the traffic feature — gated so no-default-features builds (notably the wasm32 gate CI job) don’t pull in rand and the traffic module transitively.

Source

pub fn push(self, spawn: TimedSpawn) -> Self

Append a single spawn. Useful for one-off riders mixed into a larger pattern (e.g. a “stranded top-floor” rider sitting atop a from_pattern stream).

Source

pub fn merge(self, other: Self) -> Self

Absorb another schedule’s spawns. Chainable drop-in for composing heterogeneous arrival shapes — e.g. up-peak burst plus a uniform inter-floor background:

use elevator_core::scenario::SpawnSchedule;
use elevator_core::stop::StopId;
use elevator_core::traffic::TrafficPattern;
use rand::SeedableRng;
let mut rng = rand::rngs::StdRng::seed_from_u64(7);
let stops = vec![StopId(0), StopId(1), StopId(2)];
let background = SpawnSchedule::new().from_pattern(
    TrafficPattern::Uniform, &stops, 10_000, 300, (70.0, 80.0), &mut rng,
);
let up_peak = SpawnSchedule::new().burst(StopId(0), StopId(2), 20, 0, 70.0);
let combined = up_peak.merge(background);
assert!(combined.len() >= 20);
Source

pub const fn len(&self) -> usize

Number of spawns currently in the schedule.

Source

pub const fn is_empty(&self) -> bool

Whether the schedule has no spawns.

Source

pub fn spawns(&self) -> &[TimedSpawn]

Borrow the underlying spawns (useful for inspection in tests).

Source

pub fn into_spawns(self) -> Vec<TimedSpawn>

Consume the builder and return the spawns, ready to drop into Scenario::spawns. ScenarioRunner::new sorts them by tick on construction, so builders don’t need to maintain a sorted invariant.

Trait Implementations§

Source§

impl Clone for SpawnSchedule

Source§

fn clone(&self) -> SpawnSchedule

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SpawnSchedule

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SpawnSchedule

Source§

fn default() -> SpawnSchedule

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.