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
impl IncrementalStn
Sourcepub fn add_time_point(&mut self, budget: &Budget) -> Result<TimePoint, Error>
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
Error::MemoryBudgetExceededif(n + 1)^2exceedsBudget::max_cells.Error::OutOfMemoryif the allocator refuses the new matrix.Error::BudgetExhaustedif the step budget cannot cover the copy.Error::Overflowif the time point count overflows.
Sourcepub fn add_constraint(
&mut self,
from: TimePoint,
to: TimePoint,
lo: Option<Ticks>,
hi: Option<Ticks>,
budget: &Budget,
) -> Result<Verdict<ConstraintId>, Error>
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
Error::UnknownTimePointiffromortois not in this network.Error::Overflowifloisi64::MINor a path length overflows. The network is unchanged.Error::BudgetExhaustedif theO(n^2)update, or the explanation search after a rejection, does not fit the step budget. The network is unchanged.Error::Internalif the explanation search disagrees with the matrix (a bug).
Sourcepub fn upper(&self, from: TimePoint, to: TimePoint) -> Option<Ticks>
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.
Sourcepub fn lower(&self, from: TimePoint, to: TimePoint) -> Option<Ticks>
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.
Sourcepub fn minimal_network(&self) -> Result<MinimalNetwork, Error>
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.