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
impl SimplexSolver
Sourcepub fn new(obj_coeffs: Vec<BigRational>, constraints: Vec<Constraint>) -> Self
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.
Sourcepub fn set_objective_coefficient(
&mut self,
i: usize,
val: BigRational,
) -> Result<(), SimplexError>
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.
Sourcepub fn get_objective_coefficient(
&self,
i: usize,
) -> Result<&BigRational, SimplexError>
pub fn get_objective_coefficient( &self, i: usize, ) -> Result<&BigRational, SimplexError>
Get objective coefficient i.
Sourcepub fn get_rhs(&self, i: usize) -> Result<&BigRational, SimplexError>
pub fn get_rhs(&self, i: usize) -> Result<&BigRational, SimplexError>
Get the RHS of constraint i.
Sourcepub fn set_rhs(
&mut self,
i: usize,
val: BigRational,
) -> Result<(), SimplexError>
pub fn set_rhs( &mut self, i: usize, val: BigRational, ) -> Result<(), SimplexError>
Set the RHS of constraint i.
Sourcepub fn shadow_price(&self, i: usize) -> Result<BigRational, SimplexError>
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.
Sourcepub fn objective_value(&self) -> Option<BigRational>
pub fn objective_value(&self) -> Option<BigRational>
Return the cached objective value from the last solve.
Sourcepub fn solve(&mut self) -> Result<SolveResult, SimplexError>
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.
Sourcepub fn n_constraints(&self) -> usize
pub fn n_constraints(&self) -> usize
Number of constraints.
Sourcepub fn obj_coeffs(&self) -> &[BigRational] ⓘ
pub fn obj_coeffs(&self) -> &[BigRational] ⓘ
Access the current objective coefficients.
Sourcepub fn constraints(&self) -> &[Constraint]
pub fn constraints(&self) -> &[Constraint]
Access constraints.
Sourcepub fn last_result(&self) -> Option<&SolveResult>
pub fn last_result(&self) -> Option<&SolveResult>
Access the last solve result.
Trait Implementations§
Source§impl Clone for SimplexSolver
impl Clone for SimplexSolver
Source§fn clone(&self) -> SimplexSolver
fn clone(&self) -> SimplexSolver
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more