Struct Bound

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

Bound of a decision variable

§Invariant

  • lower <= upper
  • lower and upper never become NaN
  • lower is not +inf and upper is not -inf

§Examples

use ommx::Bound;

// Usual
let bound = Bound::try_from([1.0, 2.0]).unwrap();
// Single point `[1.0, 1.0]`
let bound = Bound::try_from(1.0).unwrap();
// Default is `(-inf, inf)`
assert_eq!(Bound::default(), Bound::try_from([f64::NEG_INFINITY, f64::INFINITY]).unwrap());

Implementations§

Source§

impl Bound

Source

pub fn positive() -> Self

Positive or zero, [0, inf)

Source

pub fn negative() -> Self

Negative or zero, (-inf, 0]

Source

pub fn new(lower: f64, upper: f64) -> Result<Self, BoundError>

Source

pub fn lower(&self) -> f64

Source

pub fn upper(&self) -> f64

Source

pub fn width(&self) -> f64

Source

pub fn set_lower(&mut self, lower: f64) -> Result<(), BoundError>

Source

pub fn set_upper(&mut self, upper: f64) -> Result<(), BoundError>

Source

pub fn as_integer_bound(&self) -> Self

Strengthen the bound for integer decision variables

Since the bound evaluation may be inaccurate due to floating-point arithmetic error, this method rounds to [ceil(lower-atol), floor(upper+atol)] with atol = 1e-6.

Source

pub fn is_finite(&self) -> bool

[lower, upper] with finite lower and upper

Source

pub fn intersection(&self, other: &Self) -> Option<Self>

Take the intersection of two bounds, None if the intersection is empty

Source

pub fn pow(&self, exp: u8) -> Self

Source

pub fn contains(&self, value: f64, atol: f64) -> bool

Check the value is in the bound with absolute tolerance

Source

pub fn as_range(&self) -> RangeInclusive<f64>

Source

pub fn arbitrary_containing(&self, max_abs: f64) -> BoxedStrategy<f64>

Arbitrary finite value within the bound

max_abs is the maximum absolute value of the generated value to keep floating point arithmetic stable.

Trait Implementations§

Source§

impl Add<Bound> for f64

Source§

type Output = <Bound as Add<f64>>::Output

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Bound) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<f64> for Bound

Source§

type Output = Bound

The resulting type after applying the + operator.
Source§

fn add(self, rhs: f64) -> Self::Output

Performs the + operation. Read more
Source§

impl Add for Bound

Source§

type Output = Bound

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl AddAssign<f64> for Bound

Source§

fn add_assign(&mut self, rhs: f64)

Performs the += operation. Read more
Source§

impl AddAssign for Bound

Source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
Source§

impl Arbitrary for Bound

Source§

type Parameters = ()

The type of parameters that arbitrary_with accepts for configuration of the generated Strategy. Parameters must implement Default.
Source§

type Strategy = BoxedStrategy<Bound>

The type of Strategy used to generate values of type Self.
Source§

fn arbitrary_with(_: Self::Parameters) -> Self::Strategy

Generates a Strategy for producing arbitrary values of type the implementing type (Self). The strategy is passed the arguments given in args. Read more
Source§

fn arbitrary() -> Self::Strategy

Generates a Strategy for producing arbitrary values of type the implementing type (Self). Read more
Source§

impl Clone for Bound

Source§

fn clone(&self) -> Bound

Returns a copy of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Bound

Source§

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

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

impl Default for Bound

Source§

fn default() -> Self

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

impl From<Bound> for Bound

Source§

fn from(bound: Bound) -> Self

Converts to this type from the input type.
Source§

impl Mul<Bound> for f64

Source§

type Output = <Bound as Mul<f64>>::Output

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Bound) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<f64> for Bound

Source§

type Output = Bound

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: f64) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul for Bound

Source§

type Output = Bound

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Self) -> Self::Output

Performs the * operation. Read more
Source§

impl MulAssign<f64> for Bound

Source§

fn mul_assign(&mut self, rhs: f64)

Performs the *= operation. Read more
Source§

impl MulAssign for Bound

Source§

fn mul_assign(&mut self, rhs: Self)

Performs the *= operation. Read more
Source§

impl PartialEq<Bound> for f64

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<f64> for Bound

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq for Bound

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd<Bound> for f64

Source§

fn partial_cmp(&self, other: &Bound) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl PartialOrd<f64> for Bound

  • a <= [b, c] means a <= b, i.e. a <= x (forall x \in [b, c])
  • a >= [b, c] means a >= c, i.e. a >= x (forall x \in [b, c])
  • If a is in [b, c], return None
Source§

fn partial_cmp(&self, other: &f64) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl TryFrom<[f64; 2]> for Bound

Source§

type Error = BoundError

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

fn try_from([lower, upper]: [f64; 2]) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Bound> for Bound

Source§

type Error = BoundError

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

fn try_from(value: Bound) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<f64> for Bound

Source§

type Error = BoundError

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

fn try_from(value: f64) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Zero for Bound

Source§

fn zero() -> Self

Returns the additive identity element of Self, 0. Read more
Source§

fn is_zero(&self) -> bool

Returns true if self is equal to the additive identity.
Source§

fn set_zero(&mut self)

Sets self to the additive identity element of Self, 0.
Source§

impl Copy for Bound

Source§

impl StructuralPartialEq for Bound

Auto Trait Implementations§

§

impl Freeze for Bound

§

impl RefUnwindSafe for Bound

§

impl Send for Bound

§

impl Sync for Bound

§

impl Unpin for Bound

§

impl UnwindSafe for Bound

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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T