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
impl SpawnSchedule
Sourcepub fn burst(
self,
origin: StopId,
destination: StopId,
count: usize,
at_tick: u64,
weight: f64,
) -> Self
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).
Sourcepub fn staggered(
self,
origin: StopId,
destination: StopId,
count: usize,
start_tick: u64,
stagger_ticks: u64,
weight: f64,
) -> Self
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.
Sourcepub fn from_pattern(
self,
pattern: TrafficPattern,
stops: &[StopId],
duration_ticks: u64,
mean_interval_ticks: u32,
weight_range: (f64, f64),
rng: &mut impl RngExt,
) -> Self
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).
Sourcepub fn push(self, spawn: TimedSpawn) -> Self
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).
Sourcepub fn merge(self, other: Self) -> Self
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:
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);Sourcepub fn spawns(&self) -> &[TimedSpawn]
pub fn spawns(&self) -> &[TimedSpawn]
Borrow the underlying spawns (useful for inspection in tests).
Sourcepub fn into_spawns(self) -> Vec<TimedSpawn>
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
impl Clone for SpawnSchedule
Source§fn clone(&self) -> SpawnSchedule
fn clone(&self) -> SpawnSchedule
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more