pub struct GeLineq {
pub id: Option<u32>,
pub coeffs: Vec<i64>,
pub bounds: Vec<(i64, i64)>,
pub bias: i64,
pub indices: Vec<u32>,
}Expand description
Data structure for linear inequalities on the following form
$$ c_0 * v_0 + c_1 * v_1 + … + c_n * v_n + bias \ge 0 $$ for $ c \in $ coeffs and $ v $ are variables which can take on the values
given by bounds. Indices represents the global indices of the variables. Note that the length of coeffs, bounds and indices must be the same.
Fields§
§id: Option<u32>id may be used as a reference for later purposes
coeffs: Vec<i64>Coefficients of the linear inequality
bounds: Vec<(i64, i64)>Bounds for every variable
bias: i64d in a linear inequality $ ax+by+cz+d >= 0 $
indices: Vec<u32>Id of each index
Implementations§
Source§impl GeLineq
impl GeLineq
Sourcepub fn merge_disj(ge_lineq1: &GeLineq, ge_lineq2: &GeLineq) -> Option<GeLineq>
pub fn merge_disj(ge_lineq1: &GeLineq, ge_lineq2: &GeLineq) -> Option<GeLineq>
Takes two GeLineqs and merge those into one GeLineq under the condition that one of the GeLineqs must be satisfied.
If it’s not possible to merge the inequalities, i.e. it’s impossible to preserve the logic, none is returned.
§Example:
If atleast one of the two linear inequalities $ x + y - 1 \ge 0 $ where $ x, y \in \{0, 1 \}$ and $ a + b - 1 \ge 0 $ where $ a, b \in \{0, 1\}$ must hold, then they can be merged into one linear inequality as $ x + y + a + b - 1 \ge 0$ where $ x, y, a, b \in \{0, 1\}$. Note that the logic is preserved, i.e the merged inequality will be valid if at least one of the two original inequalities are valid. Likewise, the merged constraint will not be valid if none of the original inequalites are.
use puanrs::polyopt::GeLineq;
let ge_lineq1:GeLineq = GeLineq {
id : None,
coeffs : vec![1, 1],
bounds : vec![(0, 1), (0, 1)],
bias : -1,
indices : vec![1, 2]
};
let ge_lineq2: GeLineq = GeLineq {
id : None,
coeffs : vec![1, 1],
bounds : vec![(0, 1), (0, 1)],
bias : -1,
indices : vec![3, 4]
};
let expected: GeLineq = GeLineq {
id : None,
coeffs : vec![1, 1, 1, 1],
bounds : vec![(0, 1), (0, 1), (0, 1), (0, 1)],
bias : -1,
indices : vec![1, 2, 3, 4]
};
let actual = GeLineq::merge_disj(&ge_lineq1, &ge_lineq2);
assert_eq!(actual.as_ref().expect("Not possible to merge lineqs").coeffs, expected.coeffs);
assert_eq!(actual.as_ref().expect("Not possible to merge lineqs").bounds, expected.bounds);
assert_eq!(actual.as_ref().expect("Not possible to merge lineqs").bias, expected.bias);
assert_eq!(actual.as_ref().expect("Not possible to merge lineqs").indices, expected.indices);Sourcepub fn merge_conj(ge_lineq1: &GeLineq, ge_lineq2: &GeLineq) -> Option<GeLineq>
pub fn merge_conj(ge_lineq1: &GeLineq, ge_lineq2: &GeLineq) -> Option<GeLineq>
Takes two GeLineqs and merge those into one GeLineq under the condition that both of the GeLineqs must be valid.
If it’s not possible to merge the inequalities, i.e. it’s impossible to preserve the logic, none is returned.
Sourcepub fn substitution(
main_gelineq: &GeLineq,
variable_index: u32,
sub_gelineq: &GeLineq,
) -> Option<GeLineq>
pub fn substitution( main_gelineq: &GeLineq, variable_index: u32, sub_gelineq: &GeLineq, ) -> Option<GeLineq>
Takes a GeLineq, referred to as main GeLineq which has a variable (given by variable index) which in turn is a GeLineq, referred to as the sub GeLineq. The function substitutes the variable with the sub GeLineq into the main GeLineq if possible.
§Example
Given the lineq x + Y - 2 >= 0 where Y: a + b - 1 >= 0 a substitution would give 2x + a + b - 3 >= 0. Lets see it in code:
use puanrs::polyopt::GeLineq;
let main_gelineq:GeLineq = GeLineq {
id : None,
coeffs : vec![1, 1],
bounds : vec![(0, 1), (0, 1)],
bias : -2,
indices : vec![1, 2]
};
let sub_gelineq: GeLineq = GeLineq {
id : None,
coeffs : vec![1, 1],
bounds : vec![(0, 1), (0, 1)],
bias : -1,
indices : vec![3, 4]
};
let result = GeLineq::substitution(&main_gelineq, 2, &sub_gelineq);
assert_eq!(vec![2, 1, 1], result.as_ref().expect("No result generated").coeffs);
assert_eq!(vec![(0,1), (0,1), (0,1)], result.as_ref().expect("No result generated").bounds);
assert_eq!(-3, result.as_ref().expect("No result generated").bias);
assert_eq!(vec![1, 3, 4], result.as_ref().expect("No result generated").indices);Sourcepub fn min_max_coefficients(gelineq: &GeLineq) -> Option<GeLineq>
pub fn min_max_coefficients(gelineq: &GeLineq) -> Option<GeLineq>
Takes a GeLineq and minimizes/maximizes the coefficients while preserving the logic
§Example
Consider the GeLineq 2x + y + z >= 1 where x, y, z takes values between 0 and 1. This inequlity can be written as x + y + z >= 1 while preserving the logic.
use puanrs::polyopt::GeLineq;
let gelineq: GeLineq = GeLineq {
id : None,
coeffs : vec![2, 1, 1],
bounds : vec![(0,1), (0,1), (0,1)],
bias : -1,
indices : vec![0, 1, 2]
};
let result = GeLineq::min_max_coefficients(&gelineq);
assert_eq!(vec![1, 1, 1], result.as_ref().expect("").coeffs);Trait Implementations§
Auto Trait Implementations§
impl Freeze for GeLineq
impl RefUnwindSafe for GeLineq
impl Send for GeLineq
impl Sync for GeLineq
impl Unpin for GeLineq
impl UnwindSafe for GeLineq
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> 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