use polyzonotope::{Reduction, SparsePolyZonotope, Zonotope};
use polyzonotope_reach::{LinearReach, LinearSystem, ReachError};
use crate::Reach;
pub struct Linear<const N: usize> {
reach: LinearReach,
order: f64,
}
impl<const N: usize> Linear<N> {
pub fn new(
system: LinearSystem,
step: f64,
taylor_terms: usize,
order: f64,
) -> Result<Self, ReachError> {
assert_eq!(system.a.nrows(), N, "A needs one row per state");
assert!(order >= 1.0, "order must be at least 1");
Ok(Self {
reach: LinearReach::new(system, step, taylor_terms)?,
order,
})
}
}
impl<const N: usize> Reach<N> for Linear<N> {
type Control = Vec<Zonotope>;
fn propagate(
&self,
initial: &SparsePolyZonotope,
control: &Self::Control,
cover: &mut Vec<SparsePolyZonotope>,
) -> Option<SparsePolyZonotope> {
super::chain(initial, control, cover, |set, input| {
let mut step = self.reach.step(set, input);
step.time_point = step.time_point.reduce(self.order, Reduction::Girard);
Some(step)
})
}
}