Skip to main content

Budget

Struct Budget 

Source
#[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
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional 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

Source

pub const fn unlimited() -> Self

No limit at all.

Source

pub const fn deadline(at: Instant) -> Self

A budget with only an absolute deadline.

Source

pub const fn max_pivots(n: usize) -> Self

A budget with only a pivot (step) cap.

Source

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.

Source

pub const fn time_limit(duration: Duration) -> Self

A budget with only a relative time limit, resolved when the call starts.

Source

pub fn with_deadline(self, at: Instant) -> Self

Set (or replace) the absolute deadline.

Source

pub fn with_time_limit(self, limit: Duration) -> Self

Set (or replace) the relative time limit.

Source

pub fn with_max_pivots(self, n: usize) -> Self

Set (or replace) the pivot cap.

Source

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.

Source

pub const fn is_unlimited(&self) -> bool

Is every limit absent?

Source

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).

Source

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.

Source

pub fn deadline_passed(&self) -> bool

Has the absolute deadline passed? Only deadline is consulted — call start first to account for a time_limit.

Source

pub fn exhausted(&self, spent: usize) -> Option<BudgetHit>

Which limit has run out after spent steps, if any: the deadline is reported before the step cap.

Trait Implementations§

Source§

impl Clone for Budget

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 Budget

Source§

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

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

impl Default for Budget

Source§

fn default() -> Self

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

impl Eq for Budget

Source§

impl PartialEq for Budget

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Budget

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more