pub struct Bound { /* private fields */ }Expand description
Bound of a decision variable
§Invariant
lower <= upperloweranduppernever becomeNaNloweris not+infandupperis 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
impl Bound
pub fn new(lower: f64, upper: f64) -> Result<Self, BoundError>
pub fn lower(&self) -> f64
pub fn upper(&self) -> f64
pub fn width(&self) -> f64
pub fn set_lower(&mut self, lower: f64) -> Result<(), BoundError>
pub fn set_upper(&mut self, upper: f64) -> Result<(), BoundError>
Sourcepub fn as_integer_bound(&self) -> Self
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.
Sourcepub fn intersection(&self, other: &Self) -> Option<Self>
pub fn intersection(&self, other: &Self) -> Option<Self>
Take the intersection of two bounds, None if the intersection is empty
pub fn pow(&self, exp: u8) -> Self
Sourcepub fn contains(&self, value: f64, atol: f64) -> bool
pub fn contains(&self, value: f64, atol: f64) -> bool
Check the value is in the bound with absolute tolerance
pub fn as_range(&self) -> RangeInclusive<f64>
Sourcepub fn arbitrary_containing(&self, max_abs: f64) -> BoxedStrategy<f64>
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 AddAssign<f64> for Bound
impl AddAssign<f64> for Bound
Source§fn add_assign(&mut self, rhs: f64)
fn add_assign(&mut self, rhs: f64)
Performs the
+= operation. Read moreSource§impl AddAssign for Bound
impl AddAssign for Bound
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
Performs the
+= operation. Read moreSource§impl Arbitrary for Bound
impl Arbitrary for Bound
Source§type Parameters = ()
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>
type Strategy = BoxedStrategy<Bound>
The type of
Strategy used to generate values of type Self.Source§fn arbitrary_with(_: Self::Parameters) -> Self::Strategy
fn arbitrary_with(_: Self::Parameters) -> Self::Strategy
Source§impl MulAssign<f64> for Bound
impl MulAssign<f64> for Bound
Source§fn mul_assign(&mut self, rhs: f64)
fn mul_assign(&mut self, rhs: f64)
Performs the
*= operation. Read moreSource§impl MulAssign for Bound
impl MulAssign for Bound
Source§fn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
Performs the
*= operation. Read moreSource§impl PartialOrd<Bound> for f64
impl PartialOrd<Bound> for f64
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
impl PartialOrd<f64> for Bound
a <= [b, c]meansa <= b, i.e.a <= x (forall x \in [b, c])a >= [b, c]meansa >= c, i.e.a >= x (forall x \in [b, c])- If
ais in[b, c], returnNone
impl Copy for Bound
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> 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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
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 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>
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