pub struct FixedRateSchedule { /* private fields */ }Expand description
Per-agent fixed-rate sample schedule.
See the module docs for what it is for and what it guarantees.
Implementations§
Source§impl FixedRateSchedule
impl FixedRateSchedule
Sourcepub fn new(
config: FixedRateScheduleConfig,
phase_offset_seconds: f64,
) -> Result<Self, FixedRateScheduleConfigError>
pub fn new( config: FixedRateScheduleConfig, phase_offset_seconds: f64, ) -> Result<Self, FixedRateScheduleConfigError>
A schedule at simulation time zero, sampling every
config.interval_seconds starting at phase_offset_seconds.
Giving each agent a different phase in [0, interval) spreads their
samples across the interval instead of stacking them on one tick. A
phase of zero first samples one whole interval in, not at time zero, so
a freshly built agent does not sample before anything has happened.
§Errors
InvalidInterval if
the interval is not valid, and
InvalidPhaseOffset
if the phase is not finite or falls outside [0, interval).
Sourcepub fn phase_offset_seconds(&self) -> f64
pub fn phase_offset_seconds(&self) -> f64
The phase this schedule was built with.
Sourcepub fn simulation_time_seconds(&self) -> f64
pub fn simulation_time_seconds(&self) -> f64
Simulation time this schedule has been advanced or skipped to.
Sourcepub fn skip_elapsed(
&mut self,
elapsed_seconds: f64,
) -> Result<(), FixedRateScheduleAdvanceError>
pub fn skip_elapsed( &mut self, elapsed_seconds: f64, ) -> Result<(), FixedRateScheduleAdvanceError>
Advances the local clock without emitting samples for unavailable time.
The next sample remains on the configured phase — exactly the one a schedule advanced through the same time would reach next — while its elapsed baseline starts at the skipped endpoint, so sensory state cannot replay historical samples when an agent resumes.
§Errors
InvalidElapsed,
leaving the schedule untouched, if elapsed_seconds is negative or not
finite, if the time it reaches is not finite, or if the next sample
after it is past MAX_SAMPLE_INDEX or within
BOUNDARY_TOLERANCE_SCALE of the skip’s end — an interval too small
for the time reached to tell one sample from the next.
Sourcepub fn advance(
&mut self,
elapsed_seconds: f64,
emit: impl FnMut(FixedRateSample),
) -> Result<(), FixedRateScheduleAdvanceError>
pub fn advance( &mut self, elapsed_seconds: f64, emit: impl FnMut(FixedRateSample), ) -> Result<(), FixedRateScheduleAdvanceError>
Invokes emit once for every sample due in this elapsed-time update,
in increasing scheduled time.
A sample is due when it is at or before the update’s end, or within
BOUNDARY_TOLERANCE_SCALE of it; see the module
docs. An update spanning several intervals emits
every sample in it — none are dropped or merged.
§Errors
InvalidElapsed,
leaving the schedule untouched and emitting nothing, if
elapsed_seconds is negative or not finite, or if the time it reaches
is not finite.
Sourcepub fn next_sample_time_seconds(&self) -> f64
pub fn next_sample_time_seconds(&self) -> f64
When the next sample not yet emitted or skipped is scheduled, on the
schedule’s own clock — the scheduled_simulation_time_seconds the next
advance that reaches it will emit first.
A read: nothing is consumed, so a caller deciding how far to step before
an agent next samples asks this rather than advancing a copy of the
schedule through every sample of the interval. It is always after
simulation_time_seconds by more than
the boundary tolerance — advance stops only once the next sample is
that far past its end, and skip_elapsed refuses
a skip that would leave one due — so subtracting the two is how far
ahead the next sample falls.
Trait Implementations§
Source§impl Clone for FixedRateSchedule
impl Clone for FixedRateSchedule
impl Copy for FixedRateSchedule
Source§impl Debug for FixedRateSchedule
impl Debug for FixedRateSchedule
Source§impl Default for FixedRateSchedule
impl Default for FixedRateSchedule
Source§fn default() -> Self
fn default() -> Self
FixedRateScheduleConfig::default with no phase offset.