14 releases

Uses old Rust 2015

0.6.2 Jan 7, 2021
0.6.1 Sep 28, 2020
0.6.0 Sep 5, 2019
0.5.0 Dec 11, 2018
0.0.1-pre.2 Dec 13, 2017

#725 in Algorithms

Download history 20/week @ 2023-11-29 26/week @ 2023-12-06 37/week @ 2023-12-13 16/week @ 2023-12-20 6/week @ 2023-12-27 58/week @ 2024-01-03 122/week @ 2024-01-10 108/week @ 2024-01-17 15/week @ 2024-01-24 10/week @ 2024-01-31 18/week @ 2024-02-07 26/week @ 2024-02-14 38/week @ 2024-02-21 81/week @ 2024-02-28 69/week @ 2024-03-06 43/week @ 2024-03-13

239 downloads per month
Used in 6 crates (3 directly)

Apache-2.0

1MB
9K SLoC

C 6K SLoC // 0.3% comments Rust 2K SLoC // 0.0% comments Python 699 SLoC // 0.2% comments Bitbake 318 SLoC // 0.8% comments Shell 243 SLoC // 0.2% comments Batch 126 SLoC // 0.2% comments

osqp.rs

Rust wrapper for OSQP: the Operator Splitting QP Solver.

The OSQP (Operator Splitting Quadratic Program) solver is a numerical optimization package for solving problems in the form

minimize        0.5 x' P x + q' x

subject to      l <= A x <= u

where x in R^n is the optimization variable.

The objective function is defined by a positive semidefinite matrix P in S^n_+ and vector q in R^n.

The linear constraints are defined by matrix A in R^{m x n} and vectors l in R^m U {-inf}^m, u in R^m U {+inf}^m.

Rust Interface Documentation

Solver Documentation


lib.rs:

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>

The OSQP (Operator Splitting Quadratic Program) solver is a numerical optimization package for solving convex quadratic programs in the form

\[\begin{split}\begin{array}{ll} \mbox{minimize} & \frac{1}{2} x^T P x + q^T x \\ \mbox{subject to} & l \leq A x \leq u \end{array}\end{split}\]

where \(x\) is the optimization variable and \(P \in \mathbf{S}^{n}_{+}\) a positive semidefinite matrix.

Further information about the solver is available at osqp.org.

Example

Consider the following QP

\[\begin{split}\begin{array}{ll} \mbox{minimize} & \frac{1}{2} x^T \begin{bmatrix}4 & 1\\ 1 & 2 \end{bmatrix} x + \begin{bmatrix}1 \\ 1\end{bmatrix}^T x \\ \mbox{subject to} & \begin{bmatrix}1 \\ 0 \\ 0\end{bmatrix} \leq \begin{bmatrix} 1 & 1\\ 1 & 0\\ 0 & 1\end{bmatrix} x \leq \begin{bmatrix}1 \\ 0.7 \\ 0.7\end{bmatrix} \end{array}\end{split}\]
use osqp::{CscMatrix, Problem, Settings};

// Define problem data
let P = &[[4.0, 1.0],
          [1.0, 2.0]];
let q = &[1.0, 1.0];
let A = &[[1.0, 1.0],
          [1.0, 0.0],
          [0.0, 1.0]];
let l = &[1.0, 0.0, 0.0];
let u = &[1.0, 0.7, 0.7];

// Extract the upper triangular elements of `P`
let P = CscMatrix::from(P).into_upper_tri();

// Disable verbose output
let settings = Settings::default()
    .verbose(false);

// Create an OSQP problem
let mut prob = Problem::new(P, q, A, l, u, &settings).expect("failed to setup problem");

// Solve problem
let result = prob.solve();

// Print the solution
println!("{:?}", result.x().expect("failed to solve problem"));
#

Dependencies