#[non_exhaustive]pub struct Budget {
pub deadline: Option<Instant>,
pub time_limit: Option<Duration>,
pub max_pivots: Option<usize>,
}Expand description
A limit on one call: an absolute deadline, a relative time limit and/or a cap on the number of steps (pivots, iterations). Each defaults to “none”.
The deadline is checked at every step (for the simplex: before the
entering column is chosen), the step cap before the step is performed,
and both are shared by the i64 → i128 → 256-bit → BigInt attempts of
one solve: steps begun by an attempt that overflowed its cell type
still count, and the deadline is absolute. When it runs out,
LpProblem::solve returns
LpStatus::BudgetExhausted.
Absolute vs relative. deadline is an instant;
time_limit is measured from the moment the
budgeted call starts (start resolves it; when both are
set the earlier applies). within is the eager form:
it fixes the deadline now.
#[non_exhaustive]: build it with the constructors and with_*
builders.
use std::time::Duration;
use symplex::linprog::{Budget, LpProblem, LpStatus, qi};
// min x + y s.t. x + 2y ≥ 1, 3x + y ≥ 1 needs two pivots: one is not enough.
let p = LpProblem::minimize(vec![qi(1), qi(1)])
.ge(vec![qi(1), qi(2)], qi(1))
.ge(vec![qi(3), qi(1)], qi(1));
let sol = p.clone().with_budget(Budget::max_pivots(1)).solve().unwrap();
assert_eq!(sol.status, LpStatus::BudgetExhausted);
assert!(sol.x.is_empty() && sol.objective.is_none());
// A generous budget changes nothing.
let sol = p.with_budget(Budget::within(Duration::from_secs(60)).with_max_pivots(1000)).solve().unwrap();
assert_eq!(sol.status, LpStatus::Optimal);Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.deadline: Option<Instant>Stop once this instant has passed.
time_limit: Option<Duration>Time allowed, measured from the start of the budgeted call. When
both this and deadline are set the earlier one applies.
max_pivots: Option<usize>Stop before performing this many steps — simplex pivots, across both phases and all cell-type attempts (and, for a prover, across every LP of the call).
Implementations§
Source§impl Budget
impl Budget
Sourcepub const fn max_pivots(n: usize) -> Self
pub const fn max_pivots(n: usize) -> Self
A budget with only a pivot (step) cap.
Sourcepub fn within(duration: Duration) -> Self
pub fn within(duration: Duration) -> Self
A budget whose deadline is duration from now (eager: the clock
starts here, not when the call starts). A duration too large to
represent as an instant means no deadline. For a per-call
allowance use time_limit.
Sourcepub const fn time_limit(duration: Duration) -> Self
pub const fn time_limit(duration: Duration) -> Self
A budget with only a relative time limit, resolved when the call starts.
Sourcepub fn with_deadline(self, at: Instant) -> Self
pub fn with_deadline(self, at: Instant) -> Self
Set (or replace) the absolute deadline.
Sourcepub fn with_time_limit(self, limit: Duration) -> Self
pub fn with_time_limit(self, limit: Duration) -> Self
Set (or replace) the relative time limit.
Sourcepub fn with_max_pivots(self, n: usize) -> Self
pub fn with_max_pivots(self, n: usize) -> Self
Set (or replace) the pivot cap.
Sourcepub fn with_max_steps(self, n: usize) -> Self
pub fn with_max_steps(self, n: usize) -> Self
Set (or replace) the step cap — the same field as
with_max_pivots, named for algorithms
whose step is not a pivot.
Sourcepub const fn is_unlimited(&self) -> bool
pub const fn is_unlimited(&self) -> bool
Is every limit absent?
Sourcepub fn deadline_from_now(&self) -> Option<Instant>
pub fn deadline_from_now(&self) -> Option<Instant>
The deadline of a call starting now: the earlier of deadline and
now + time_limit (see deadline_from).
Sourcepub fn start(&self) -> Self
pub fn start(&self) -> Self
The budget of a call starting now: the relative time limit is
folded into the absolute deadline (the earlier of the two) and
cleared, so the result can be checked with
deadline_passed alone.
Sourcepub fn deadline_passed(&self) -> bool
pub fn deadline_passed(&self) -> bool
Has the absolute deadline passed? Only deadline is consulted —
call start first to account for a time_limit.
Trait Implementations§
impl Eq for Budget
impl StructuralPartialEq for Budget
Auto Trait Implementations§
impl Freeze for Budget
impl RefUnwindSafe for Budget
impl Send for Budget
impl Sync for Budget
impl Unpin for Budget
impl UnsafeUnpin for Budget
impl UnwindSafe for Budget
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more