Skip to main content

IncrementalStn

Struct IncrementalStn 

Source
pub struct IncrementalStn { /* private fields */ }
Expand description

An STN that keeps its minimal network up to date as constraints are added.

Each IncrementalStn::add_constraint costs O(n^2) steps instead of the O(n^3) of a full Stn::minimal_network recomputation. A constraint that would make the network inconsistent is rejected: the network stays as it was and the verdict explains why.

§Examples

use temporal_control::{Budget, IncrementalStn, Ticks, Verdict};

let mut stn = IncrementalStn::new();
let budget = Budget::UNLIMITED;
let a = stn.add_time_point(&budget).expect("fits");
let b = stn.add_time_point(&budget).expect("fits");

let ok = stn.add_constraint(a, b, Some(Ticks(5)), Some(Ticks(15)), &budget).expect("ok");
assert!(matches!(ok, Verdict::Consistent(_)));

// 20 <= t_b - t_a contradicts t_b - t_a <= 15 and is rejected.
let bad = stn.add_constraint(a, b, Some(Ticks(20)), None, &budget).expect("ok");
assert!(matches!(bad, Verdict::Inconsistent(_)));
assert_eq!(stn.stn().constraints().len(), 1);
assert_eq!(stn.upper(a, b), Some(Ticks(15)));

Implementations§

Source§

impl IncrementalStn

Source

pub fn new() -> Self

Creates an empty network.

Source

pub fn add_time_point(&mut self, budget: &Budget) -> Result<TimePoint, Error>

Adds an unconstrained time point.

Costs O(n^2) steps to grow the matrix.

§Errors
Source

pub fn add_constraint( &mut self, from: TimePoint, to: TimePoint, lo: Option<Ticks>, hi: Option<Ticks>, budget: &Budget, ) -> Result<Verdict<ConstraintId>, Error>

Adds lo <= t_to - t_from <= hi if the network stays consistent.

Returns the new ConstraintId on success. On inconsistency the constraint is not added and the verdict carries a negative cycle through the rejected constraint, whose id in the cycle is the one it would have received.

§Errors
Source

pub fn upper(&self, from: TimePoint, to: TimePoint) -> Option<Ticks>

Tightest upper bound on t_to - t_from; None if unbounded or a handle is unknown.

Source

pub fn lower(&self, from: TimePoint, to: TimePoint) -> Option<Ticks>

Tightest lower bound on t_to - t_from; None if unbounded or a handle is unknown.

Source

pub fn stn(&self) -> &Stn

The accepted constraints as a plain Stn.

Source

pub fn minimal_network(&self) -> Result<MinimalNetwork, Error>

A snapshot of the current minimal network.

§Errors

Error::Overflow if an entry is i64::MIN; Error::OutOfMemory if the copy fails.

Trait Implementations§

Source§

impl Clone for IncrementalStn

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for IncrementalStn

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for IncrementalStn

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.