pub struct TrafficSchedule { /* private fields */ }Expand description
A time-varying traffic schedule that selects patterns based on tick count.
Maps tick ranges to traffic patterns, enabling realistic daily cycles (e.g., up-peak in the morning, lunchtime at noon, down-peak in evening).
§Example
use elevator_core::traffic::{TrafficPattern, TrafficSchedule};
let schedule = TrafficSchedule::new(vec![
(0..3600, TrafficPattern::UpPeak), // First hour: morning rush
(3600..7200, TrafficPattern::Uniform), // Second hour: normal
(7200..10800, TrafficPattern::Lunchtime), // Third hour: lunch
(10800..14400, TrafficPattern::DownPeak), // Fourth hour: evening rush
]);
// Sampling uses the pattern active at the given tick
let stops = vec![/* ... */];
let (origin, dest) = schedule.sample(tick, &stops, &mut rng).unwrap();Implementations§
Source§impl TrafficSchedule
impl TrafficSchedule
Sourcepub const fn new(segments: Vec<(Range<u64>, TrafficPattern)>) -> Self
pub const fn new(segments: Vec<(Range<u64>, TrafficPattern)>) -> Self
Create a schedule from segments.
Segments are (tick_range, pattern) pairs. If the current tick
doesn’t fall within any segment, the fallback Uniform pattern is used.
Sourcepub const fn with_fallback(self, pattern: TrafficPattern) -> Self
pub const fn with_fallback(self, pattern: TrafficPattern) -> Self
Set the fallback pattern for ticks outside all segments.
Sourcepub fn pattern_at(&self, tick: u64) -> &TrafficPattern
pub fn pattern_at(&self, tick: u64) -> &TrafficPattern
Get the active traffic pattern for the given tick.
Sourcepub fn sample(
&self,
tick: u64,
stops: &[EntityId],
rng: &mut impl RngExt,
) -> Option<(EntityId, EntityId)>
pub fn sample( &self, tick: u64, stops: &[EntityId], rng: &mut impl RngExt, ) -> Option<(EntityId, EntityId)>
Sample an (origin, destination) pair using the pattern active at tick.
Delegates to TrafficPattern::sample() for the active pattern.
Sourcepub fn sample_stop_ids(
&self,
tick: u64,
stops: &[StopId],
rng: &mut impl RngExt,
) -> Option<(StopId, StopId)>
pub fn sample_stop_ids( &self, tick: u64, stops: &[StopId], rng: &mut impl RngExt, ) -> Option<(StopId, StopId)>
Sample an (origin, destination) pair by StopId using the active pattern.
Sourcepub fn office_day(ticks_per_hour: u64) -> Self
pub fn office_day(ticks_per_hour: u64) -> Self
Create a typical office-building daily schedule.
Assumes ticks_per_hour ticks per real-world hour:
- Hours 0-1: Up-peak (morning rush)
- Hours 1-4: Uniform (normal traffic)
- Hours 4-5: Lunchtime
- Hours 5-8: Uniform (afternoon)
- Hours 8-9: Down-peak (evening rush)
- Hours 9+: Uniform (fallback)
Sourcepub const fn constant(pattern: TrafficPattern) -> Self
pub const fn constant(pattern: TrafficPattern) -> Self
Create a constant schedule that uses the same pattern for all ticks.
Trait Implementations§
Source§impl Clone for TrafficSchedule
impl Clone for TrafficSchedule
Source§fn clone(&self) -> TrafficSchedule
fn clone(&self) -> TrafficSchedule
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more