Skip to main content

SimplexSolver

Struct SimplexSolver 

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

High-level LP solver for parametric analysis.

Minimises c'x subject to a set of Constraints and x ≥ 0.

Implementations§

Source§

impl SimplexSolver

Source

pub fn new(obj_coeffs: Vec<BigRational>, constraints: Vec<Constraint>) -> Self

Create a solver with the given objective and constraints.

obj_coeffs[i] is the coefficient of variable i in the minimised objective c'x. All decision variables are implicitly non-negative.

Source

pub fn set_objective_coefficient( &mut self, i: usize, val: BigRational, ) -> Result<(), SimplexError>

Update a single objective coefficient.

Returns an error when i ≥ n_vars.

Source

pub fn get_objective_coefficient( &self, i: usize, ) -> Result<&BigRational, SimplexError>

Get objective coefficient i.

Source

pub fn get_rhs(&self, i: usize) -> Result<&BigRational, SimplexError>

Get the RHS of constraint i.

Source

pub fn set_rhs( &mut self, i: usize, val: BigRational, ) -> Result<(), SimplexError>

Set the RHS of constraint i.

Source

pub fn shadow_price(&self, i: usize) -> Result<BigRational, SimplexError>

Return the shadow price (dual variable) for constraint i.

The shadow price represents how much the optimal objective improves (decreases, since we minimise) per unit increase in b_i.

Returns an error if solve() has not been called yet, or if the last solve did not yield an optimal solution.

Source

pub fn objective_value(&self) -> Option<BigRational>

Return the cached objective value from the last solve.

Source

pub fn solve(&mut self) -> Result<SolveResult, SimplexError>

Solve the LP via Big-M primal simplex.

Converts to standard equality form, appends artificial variables with Big-M objective penalty, and runs the primal simplex until optimal or detected infeasible / unbounded. Shadow prices are read directly from the final objective row (reduced costs of slack columns).

Stores the result internally so that subsequent shadow_price() calls do not require re-solving.

Source

pub fn n_vars(&self) -> usize

Number of decision variables.

Source

pub fn n_constraints(&self) -> usize

Number of constraints.

Source

pub fn obj_coeffs(&self) -> &[BigRational]

Access the current objective coefficients.

Source

pub fn constraints(&self) -> &[Constraint]

Access constraints.

Source

pub fn last_result(&self) -> Option<&SolveResult>

Access the last solve result.

Trait Implementations§

Source§

impl Clone for SimplexSolver

Source§

fn clone(&self) -> SimplexSolver

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 Debug for SimplexSolver

Source§

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

Formats the value using the given formatter. 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> 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.