Expand description
§Resource timeline
Resource timelines for onboard scheduling: energy, memory, thermal and communication budgets.
A Timeline tracks the level of one numeric resource over integer time ticks. Activities
add Impacts to it:
- a consumable resource (battery energy, data volume) changes by permanent
Impact::Steps and by linearImpact::Rates (charging, discharging, thermal drift); - a reusable resource (an instrument, a transmitter, a power channel) is borrowed by an
Impact::Claimfor a half-open interval and returned afterwards.
Timeline::first_violation reports the first tick at which the level leaves its
[min, max] Bounds or misses an end-state Target, with the activities responsible.
A StateTimeline does the same for discrete states such as instrument modes and comm
visibility windows. Timeline::breakpoints, Timeline::samples and
Timeline::export extract the level line for display and telemetry.
On top of single timelines:
- a
Planholds one timeline per resource, places activities given asDemands atomically and finds the earliest start at which an activity fits, in closed form per linear piece when rates are involved; greedy::scheduleplaces activities in priority order at their earliest feasible start;envelope::Envelopebounds the level over every schedule that startWindows admit, including uncertain durations and precedences, so a flexible schedule can be checked once instead of per dispatch decision;envelope::StateEnvelopedoes the same for states.
Every timeline and plan is generic over its storage: heap-allocated by default, or
fixed-capacity and allocation-free (FixedTimeline, storage::FixedPlan) for onboard
use, with the same algorithms and typed Error::CapacityExceeded errors.
This crate is the companion of temporal-control but does not depend on it: temporal
controllability does not imply resource safety, so both checks must run independently. Both
crates share the time representation only by convention: a Tick is a plain i64, and
start windows come from the STN (see envelope for the bridge).
graph LR
demands["Demands of an activity"] --> plan["Plan: numeric and state timelines"]
plan --> search["earliest_start, greedy::schedule"]
plan --> check["first_violation with contributors"]
windows["Start windows from an STN"] --> envelope["Envelope: Safe, Possible, Certain"]
plan --> envelope§Example
use resource_timeline::{ActivityId, Bound, Bounds, Impact, Timeline};
// Battery with 100 units, a reserve of 20 and a capacity of 120.
let mut battery = Timeline::depletable(0, 100, Bounds::new(20, 120)?, 16)?;
let warm_up = ActivityId(1);
let analyze = ActivityId(2);
battery.add(warm_up, Impact::Step { at: 5, delta: -40 })?;
battery.add(analyze, Impact::Step { at: 20, delta: -50 })?;
let violation = battery.first_violation()?.expect("the reserve is broken");
assert_eq!(violation.at, 20);
assert_eq!(violation.level, 10);
assert_eq!(violation.bound, Bound::BelowMin(20));
assert_eq!(violation.contributors, [warm_up, analyze]);§Features
alloc(default): heap storage (storage::Heap, the default storage of every type),envelopeandgreedy. Without it the crate needs no allocator: timelines, state timelines and plans usestorage::Fixedandstorage::FixedPlan.
Repository: https://github.com/sunsided/resource-timeline
Modules§
- codec
- A compact, checksummed byte encoding of profiles and timelines, without allocation.
- envelope
- Level envelopes for activities whose start lies in a window.
- greedy
- A greedy scheduler: place activities by priority at their earliest feasible start.
- storage
- Storage strategies: heap-allocated or fixed-capacity, chosen per timeline and plan.
Structs§
- Activity
Id - An opaque identifier of an activity, chosen by the caller.
- Bounds
- The inclusive range
[min, max]a resource level must stay in. - Breakpoint
- A tick at which the level line of a timeline changes: it jumps, or its slope changes.
- Breakpoints
- The breakpoints of a timeline in time order; see
Timeline::breakpoints. - Level
Profile - A self-contained copy of a timeline’s level line, for display and telemetry.
- Plan
- A set of numeric and state timelines, one per resource, checked together.
- Samples
- The level of a timeline at regular ticks; see
Timeline::samples. - Search
Scratch - Working memory of
Plan::fitsandPlan::earliest_start, for callers that keep it outside the stack. - StateId
- A handle of a
StateTimelinein aPlan. - State
Timeline - A discrete state over time, built from activity sets and checked against requirements.
- Target
- A minimum level the timeline must have at one tick, for example the battery reserve required at the end of a sol so the rover survives the night.
- Timeline
- The level of one resource over time, built from activity impacts.
- Timeline
Id - A handle of a numeric
Timelinein aPlan. - Violation
- The first tick at which a timeline’s level is out of bounds, and why.
- Window
- The inclusive range
[earliest, latest]of allowed start ticks of an activity.
Enums§
- Bound
- The bound a level broke, with the bound’s value.
- Container
- The containers a timeline, plan or check keeps, named in
Error::CapacityExceeded. - Demand
- One effect of an activity on one timeline of a plan, with ticks relative to the activity start.
- Error
- Why a timeline could not be built, an impact was rejected, or a check could not finish.
- Impact
- One effect of an activity on the level of a resource.
- Kind
- How impacts change a timeline’s level.
- Plan
Violation - The earliest violation of a plan and the timeline it occurs on.
- State
Impact - One effect of an activity on a state timeline.
- State
Violation - The first tick at which a state timeline is inconsistent, and why.
Type Aliases§
- Fixed
State Timeline - A state timeline with room for
Nimpacts that never allocates. - Fixed
Timeline - A numeric timeline with room for
Nimpacts that never allocates. - Level
- A resource level in a mission-chosen integer unit, for example mWh, KiB or instrument units.
- State
Value - A discrete state value. The meaning of each value is chosen by the mission.
- Tick
- A point in time, as a count of integer ticks.