Skip to main content

robust_planning/
models.rs

1//! [`Reach`](crate::Reach) models on `polyzonotope-reach`: validated reachable sets of
2//! continuous-time dynamics. Needs the `reach` feature.
3//!
4//! [`Linear`] propagates `x' = A x + B u`, [`Nonlinear`] any
5//! [`Dynamics`](polyzonotope_reach::Dynamics) `x' = f(x, u)`. Both take one input set per
6//! time step as the control of an edge: the system may follow any integrable input signal
7//! with values in that set during the step, so nominal inputs, input errors and
8//! disturbances (as extra input columns) all go into it.
9//!
10//! Each time step yields two sets. The time-interval set holds every state during the step
11//! and becomes one cover set of the edge. The time-point set holds every state at the end
12//! of the step and starts the next one; the last becomes the edge's end set.
13//!
14//! ```mermaid
15//! graph LR
16//!     Start["initial set"] --> Step["step under input set k"]
17//!     Step -->|time interval| Cover["cover set k"]
18//!     Step -->|time point| Next{"more input sets?"}
19//!     Next -->|yes| Step
20//!     Next -->|no| End["end set"]
21//!     Step -->|refused| None["None: Indeterminate"]
22//! ```
23//!
24//! Steering is separate: pair a model with a function that picks the input sets through
25//! [`WithSteering`](crate::WithSteering).
26
27mod linear;
28mod nonlinear;
29
30pub use linear::Linear;
31pub use nonlinear::Nonlinear;
32
33use polyzonotope::{SparsePolyZonotope, Zonotope};
34use polyzonotope_reach::Step;
35
36/// Chains one `step` per input set from `initial`, in order.
37///
38/// Pushes each step's time-interval set to `cover` and starts the next step from its
39/// time-point set. Returns the last time-point set, or `initial` itself for no input sets
40/// (with nothing pushed, which [`check_edge`](crate::check_edge) answers `Indeterminate`).
41/// Returns `None` as soon as `step` refuses one, leaving the sets of the steps before it in
42/// `cover`.
43fn chain(
44    initial: &SparsePolyZonotope,
45    inputs: &[Zonotope],
46    cover: &mut Vec<SparsePolyZonotope>,
47    mut step: impl FnMut(&SparsePolyZonotope, &Zonotope) -> Option<Step>,
48) -> Option<SparsePolyZonotope> {
49    let mut set = initial.clone();
50
51    for input in inputs {
52        let Step {
53            time_point,
54            time_interval,
55            ..
56        } = step(&set, input)?;
57        cover.push(time_interval);
58        set = time_point;
59    }
60
61    Some(set)
62}