Skip to main content

IntegerLinearProgram

Struct IntegerLinearProgram 

Source
pub struct IntegerLinearProgram {
    pub ge_ph: Polyhedron,
    pub eq_ph: Polyhedron,
    pub of: Vec<f64>,
}
Expand description

Data structure for an integer linear program (ILP).

Fields§

§ge_ph: Polyhedron

Polyhedron with constraints on the form $ A \ge b $.

§eq_ph: Polyhedron

Polyhedron with constraints on the form $ A = b $.

§of: Vec<f64>

Objective function.

Implementations§

Source§

impl IntegerLinearProgram

Source

pub fn solve(&self) -> IntegerSolution

Solves a linear program with the revised simplex algorithm and produces an integer solution using the Land-Doig-Dakins algorithm.

§Example:

Solve the linear program $$ \max \quad -4x_1+-5x_2 $$ $$ s.t. \quad x_1+4x_2 \geq 4 $$ $$ \qquad \ 3x_1+2x_2 \geq 6 $$ $$ \qquad \ x_1, x_2 \geq 0$$

use puanrs::solver::IntegerLinearProgram;
use puanrs::polyopt::{Polyhedron, VariableFloat};
use puanrs::linalg::Matrix;
let sol = IntegerLinearProgram {
                ge_ph: Polyhedron {
                        a: Matrix{
                            val: vec![1.0, 4.0, 3.0, 2.0],
                            nrows: 2,
                            ncols: 2
                        },
                        b: vec![4.0, 6.0],
                        variables: vec![ VariableFloat { id:0, bounds: (0.0,f64::MAX) }, VariableFloat { id: 1, bounds: (0.0,f64::MAX) }],
                        index: vec![Some(0),Some(1)],
                },
                eq_ph: Default::default(),
                of: vec![-4.0, -5.0],
            }.solve();
assert_eq!(sol.z, -13);
assert_eq!(sol.x, vec![2, 1]);
assert_eq!(sol.status_code, 5);

Trait Implementations§

Source§

impl Clone for IntegerLinearProgram

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 Default for IntegerLinearProgram

Source§

fn default() -> IntegerLinearProgram

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

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