temporal_control/lib.rs
1//! # Temporal control
2//!
3//! Simple temporal networks with uncertainty: dynamic controllability checking and dispatchable
4//! execution for `no_std` targets.
5//!
6//! ## Scope
7//!
8//! - Simple Temporal Networks ([`Stn`]): consistency checking with a negative-cycle explanation,
9//! minimal networks (all pairs, or the constrained pairs only with P³C), incremental consistency ([`IncrementalStn`]) and filtered dispatchable
10//! networks ([`Stn::dispatchable`]).
11//! - STNs with Uncertainty ([`Stnu`]): dynamic controllability by independent checkers
12//! ([`Stnu::dispatchable`], which also yields an extended dispatchable network with waits;
13//! [`Stnu::check_controllability`], Morris's `O(n^3)` algorithm; and the others in
14//! [`DcAlgorithm`]). A negative verdict carries a [`SemiReducibleCycle`] naming the
15//! requirements and contingent extremes that conflict.
16//! - An onboard [`Dispatcher`] with fixed capacity that needs no `alloc`, loads in place from
17//! a `const` [`Dispatcher::EMPTY`], and stores handles in a chosen [`Index`] type.
18//! - A compact, versioned, CRC-32-checked encoding of dispatchable networks
19//! ([`dispatch::encoding`]) that the dispatcher validates and loads directly from the bytes.
20//!
21//! Everything except [`Dispatcher`], the encoding and their input types needs the default
22//! `alloc` feature.
23//!
24//! All time values are integer [`Ticks`]. All arithmetic is checked, and every algorithm runs
25//! under an explicit [`Budget`]. Exhausting a budget yields [`Error::BudgetExhausted`], never a
26//! verdict. See `docs/design.md` in the repository for the formal semantics.
27//!
28//! ## Example
29//!
30//! ```
31//! # #[cfg(feature = "alloc")] {
32//! use temporal_control::{Budget, Stn, Ticks, Verdict};
33//!
34//! let mut stn = Stn::new();
35//! let warmup = stn.add_time_point().expect("fits usize");
36//! let analysis = stn.add_time_point().expect("fits usize");
37//! // 5 <= t_analysis - t_warmup <= 15
38//! stn.add_constraint(warmup, analysis, Some(Ticks(5)), Some(Ticks(15)))
39//! .expect("time points exist");
40//!
41//! let verdict = stn.check_consistency(&Budget::UNLIMITED).expect("within budget");
42//! assert!(matches!(verdict, Verdict::Consistent(_)));
43//! # }
44//! ```
45//!
46//! Repository: <https://github.com/sunsided/temporal-control>
47
48#![no_std]
49#![forbid(unsafe_code)]
50
51#[cfg(feature = "alloc")]
52extern crate alloc;
53
54mod budget;
55pub mod dispatch;
56mod error;
57#[cfg(feature = "alloc")]
58pub mod stn;
59#[cfg(feature = "alloc")]
60pub mod stnu;
61mod ticks;
62mod time_point;
63
64pub use budget::Budget;
65#[cfg(feature = "alloc")]
66pub use dispatch::DispatchableNetwork;
67pub use dispatch::{
68 DecodeError, DispatchEdge, DispatchError, Dispatcher, EncodeError, Index, PointKind, Wait,
69};
70pub use error::Error;
71#[cfg(feature = "alloc")]
72pub use stn::{
73 Bound, ChordalNetwork, Constraint, ConstraintId, CycleEdge, IncrementalStn, MinimalNetwork,
74 NegativeCycle, Schedule, Stn, Verdict,
75};
76#[cfg(feature = "alloc")]
77pub use stnu::{
78 ContingentId, ContingentLink, Controllability, CycleStep, DcAlgorithm, DerivedEdge,
79 DispatchAlgorithm, LabelledEdge, Reaction, SemiReducibleCycle, Stnu,
80};
81pub use ticks::Ticks;
82pub use time_point::TimePoint;