Skip to main content

Stn

Struct Stn 

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

A Simple Temporal Network.

Construction only fails on handle validation and checked arithmetic. Algorithms are read-only and take an explicit Budget.

Implementations§

Source§

impl Stn

Source

pub fn new() -> Self

Creates an empty network.

Source

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

Adds a time point and returns its handle.

§Errors

Error::Overflow if the number of time points would exceed usize::MAX.

Source

pub fn time_point_count(&self) -> usize

Number of time points.

Source

pub fn constraints(&self) -> &[Constraint]

All constraints, indexed by ConstraintId.

Source

pub fn constraint(&self, id: ConstraintId) -> Option<&Constraint>

Looks up one constraint.

Source

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

Adds the constraint lo <= t_to - t_from <= hi.

Either bound may be None (unbounded). lo > hi is accepted and makes the network inconsistent, which the checks then explain.

§Errors
Source

pub fn check_consistency( &self, budget: &Budget, ) -> Result<Verdict<Schedule>, Error>

Checks consistency with Bellman-Ford from a virtual source.

Runs in O(n * m) steps and O(n + m) memory. A consistent verdict carries a Schedule that satisfies every constraint; an inconsistent verdict carries a NegativeCycle.

§Errors
Source

pub fn minimal_network( &self, budget: &Budget, ) -> Result<Verdict<MinimalNetwork>, Error>

Computes the minimal network (all-pairs shortest paths) with Floyd-Warshall.

Runs in O(n^3) steps and n^2 cells. On inconsistency, the explanation is extracted with Bellman-Ford using the remaining budget; if Bellman-Ford disagrees, the result is Error::Internal.

§Errors
Source

pub fn partial_path_consistency( &self, budget: &Budget, ) -> Result<Verdict<ChordalNetwork>, Error>

Computes the minimal constraints of every constrained pair with P³C (Planken, de Weerdt and van der Krogt, ICAPS 2008), without the full n^2 minimal network.

The result covers a chordal supergraph of the constraint graph: every pair that shares a constraint, plus the fill edges of a minimum-degree triangulation. For each of those pairs the bounds equal Stn::minimal_network’s. To include a pair that shares no constraint, add one without bounds. Runs in O((n + m + t) log n) steps for m constraints and t triangles of the chordal graph (O(n w*^2) for induced width w*, at most O(n^3)); see the p3c module docs. On inconsistency the explanation comes from Bellman-Ford using the remaining budget, which also decides the verdict if P³C overflows first.

§Errors
§Examples
use temporal_control::{Budget, Stn, Ticks, TimePoint, Verdict};

// A chain a -> b -> c of 2..5 ticks each; the pair (a, c) is of interest.
let mut stn = Stn::new();
let [a, b, c] = [(); 3].map(|()| stn.add_time_point().expect("fits"));
stn.add_constraint(a, b, Some(Ticks(2)), Some(Ticks(5))).expect("exists");
stn.add_constraint(b, c, Some(Ticks(2)), Some(Ticks(5))).expect("exists");
stn.add_constraint(a, c, None, None).expect("exists");

let Verdict::Consistent(net) = stn.partial_path_consistency(&Budget::UNLIMITED).expect("fits")
else {
    panic!("consistent");
};
assert_eq!((net.lower(a, c), net.upper(a, c)), (Some(Ticks(4)), Some(Ticks(10))));
assert!(!net.contains(TimePoint(0), TimePoint(7)));
Source

pub fn dispatchable( &self, budget: &Budget, ) -> Result<Verdict<DispatchableNetwork>, Error>

Computes the minimal network and filters it into a dispatchable network.

Costs O(n^3) steps and n^2 cells. See MinimalNetwork::dispatchable.

§Errors

As for Stn::minimal_network and MinimalNetwork::dispatchable. Each phase is metered against the full budget, so the total can reach twice its step limit.

§Examples
use temporal_control::{Budget, Dispatcher, Stn, Ticks, TimePoint, Verdict};

// A chain a -> b -> c, each step 2..5 ticks: the implied a -> c edges are filtered out.
let mut stn = Stn::new();
let [a, b, c] = [(); 3].map(|()| stn.add_time_point().expect("fits"));
stn.add_constraint(a, b, Some(Ticks(2)), Some(Ticks(5))).expect("exists");
stn.add_constraint(b, c, Some(Ticks(2)), Some(Ticks(5))).expect("exists");

let Verdict::Consistent(net) = stn.dispatchable(&Budget::UNLIMITED).expect("fits") else {
    panic!("consistent");
};
assert_eq!(net.edges().len(), 4);

let mut d: Dispatcher<3, 8> = net.dispatcher().expect("fits");
let mut out = [TimePoint(0); 3];
assert_eq!(d.step(Ticks(0), &[], &mut out), Ok(1));
assert_eq!(d.next_wakeup(), Some(Ticks(2)));

Trait Implementations§

Source§

impl Clone for Stn

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 Stn

Source§

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

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

impl Default for Stn

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl Forget for Stn

§

impl Freeze for Stn

§

impl Move for Stn

§

impl RefUnwindSafe for Stn

§

impl Send for Stn

§

impl Sync for Stn

§

impl Unpin for Stn

§

impl UnsafeUnpin for Stn

§

impl UnwindSafe for Stn

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.