Skip to main content

Crate resource_timeline

Crate resource_timeline 

Source
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 linear Impact::Rates (charging, discharging, thermal drift);
  • a reusable resource (an instrument, a transmitter, a power channel) is borrowed by an Impact::Claim for 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 Plan holds one timeline per resource, places activities given as Demands atomically and finds the earliest start at which an activity fits, in closed form per linear piece when rates are involved;
  • greedy::schedule places activities in priority order at their earliest feasible start;
  • envelope::Envelope bounds the level over every schedule that start Windows admit, including uncertain durations and precedences, so a flexible schedule can be checked once instead of per dispatch decision; envelope::StateEnvelope does 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

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§

ActivityId
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.
LevelProfile
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.
SearchScratch
Working memory of Plan::fits and Plan::earliest_start, for callers that keep it outside the stack.
StateId
A handle of a StateTimeline in a Plan.
StateTimeline
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.
TimelineId
A handle of a numeric Timeline in a Plan.
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.
PlanViolation
The earliest violation of a plan and the timeline it occurs on.
StateImpact
One effect of an activity on a state timeline.
StateViolation
The first tick at which a state timeline is inconsistent, and why.

Type Aliases§

FixedStateTimeline
A state timeline with room for N impacts that never allocates.
FixedTimeline
A numeric timeline with room for N impacts that never allocates.
Level
A resource level in a mission-chosen integer unit, for example mWh, KiB or instrument units.
StateValue
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.