1 unstable release
0.6.2 | Mar 7, 2023 |
---|
#1876 in Algorithms
Used in 2 crates
1.5MB
33K
SLoC
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
.
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
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
use osqp_rust::{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"));
#