Expand description
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_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"));
Structs
- A matrix in Compressed Sparse Column format.
- A proof of dual infeasibility.
- A problem that failed to be solved.
- A proof of primal infeasibility.
- An instance of the OSQP solver.
- The settings used when initialising a solver.
- A solution to a problem.
Enums
- The linear system solver for OSQP to use.
- The status of the polish operation.
- An error that can occur when setting up the solver.
- The result of solving a problem.