pub struct AtLeast {
pub ids: Vec<u32>,
pub bias: i64,
pub sign: Sign,
}
Expand description
Data structure for representing an at least
constraint on form
$$ c * v_0 + c * v_1 + … + c * v_n + bias \ge 0 $$
where $c=1$ if sign == Sign::Positive
, or, $c=-1$ if sign == Sign::Negative
.
ids
vector property holds what variables are connected to this constraint.
Fields§
§ids: Vec<u32>
§bias: i64
§sign: Sign
Implementations§
Source§impl AtLeast
impl AtLeast
Sourcepub fn to_lineq(
&self,
id: Option<u32>,
variable_hm: &HashMap<u32, Variable>,
) -> GeLineq
pub fn to_lineq( &self, id: Option<u32>, variable_hm: &HashMap<u32, Variable>, ) -> GeLineq
Transform into a linear inequality constraint.
variable_hm
is a hash map of id’s and variables.
§Example:
use puanrs::AtLeast;
use puanrs::Sign;
use puanrs::polyopt::GeLineq;
use puanrs::polyopt::Variable;
use std::{collections::HashMap};
let at_least: AtLeast = AtLeast {
ids : vec![0,1,2],
bias : -1,
sign : Sign::Positive,
};
let mut variable_hm: HashMap<u32, Variable> = HashMap::default();
variable_hm.insert(0, Variable {id: 0, bounds: (0,1)});
variable_hm.insert(1, Variable {id: 1, bounds: (0,1)});
variable_hm.insert(2, Variable {id: 2, bounds: (0,1)});
let actual: GeLineq = at_least.to_lineq(None, &variable_hm);
assert_eq!(actual.coeffs, vec![1,1,1]);
assert_eq!(actual.bias, -1);
assert_eq!(actual.bounds, vec![(0,1),(0,1),(0,1)]);
assert_eq!(actual.indices, vec![0,1,2]);
Trait Implementations§
Auto Trait Implementations§
impl Freeze for AtLeast
impl RefUnwindSafe for AtLeast
impl Send for AtLeast
impl Sync for AtLeast
impl Unpin for AtLeast
impl UnwindSafe for AtLeast
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