scivex_optim/linprog/mod.rs
1//! Linear programming via the revised simplex method.
2//!
3//! Solves problems of the form:
4//!
5//! ```text
6//! minimize c^T x
7//! subject to A_ub x <= b_ub
8//! x >= 0
9//! ```
10
11mod simplex;
12
13pub use simplex::linprog;
14
15use scivex_core::Float;
16
17/// Result of a linear programming solve.
18///
19/// # Examples
20///
21/// ```
22/// # use scivex_optim::linprog::linprog;
23/// // minimize -x - 2y s.t. x + y <= 4, x >= 0, y >= 0
24/// let result = linprog(&[-1.0_f64, -2.0], &[vec![1.0, 1.0]], &[4.0]).unwrap();
25/// assert!(result.converged);
26/// ```
27#[cfg_attr(
28 feature = "serde-support",
29 derive(serde::Serialize, serde::Deserialize)
30)]
31#[derive(Debug, Clone)]
32pub struct LinProgResult<T: Float> {
33 /// Optimal decision variables.
34 pub x: Vec<T>,
35 /// Optimal objective value.
36 pub fun: T,
37 /// Slack variables (b_ub - A_ub x).
38 pub slack: Vec<T>,
39 /// Number of simplex iterations.
40 pub iterations: usize,
41 /// Whether the solver found an optimal solution.
42 pub converged: bool,
43}