scivex-optim 0.1.1

Scivex — Optimization, root finding, and numerical integration
Documentation
//! Linear programming via the revised simplex method.
//!
//! Solves problems of the form:
//!
//! ```text
//! minimize    c^T x
//! subject to  A_ub x <= b_ub
//!             x >= 0
//! ```

mod simplex;

pub use simplex::linprog;

use scivex_core::Float;

/// Result of a linear programming solve.
///
/// # Examples
///
/// ```
/// # use scivex_optim::linprog::linprog;
/// // minimize -x - 2y  s.t.  x + y <= 4, x >= 0, y >= 0
/// let result = linprog(&[-1.0_f64, -2.0], &[vec![1.0, 1.0]], &[4.0]).unwrap();
/// assert!(result.converged);
/// ```
#[cfg_attr(
    feature = "serde-support",
    derive(serde::Serialize, serde::Deserialize)
)]
#[derive(Debug, Clone)]
pub struct LinProgResult<T: Float> {
    /// Optimal decision variables.
    pub x: Vec<T>,
    /// Optimal objective value.
    pub fun: T,
    /// Slack variables (b_ub - A_ub x).
    pub slack: Vec<T>,
    /// Number of simplex iterations.
    pub iterations: usize,
    /// Whether the solver found an optimal solution.
    pub converged: bool,
}