2 releases
0.0.1 | Dec 4, 2021 |
---|---|
0.0.0 | Dec 4, 2021 |
#11 in #quadratic
110 downloads per month
42KB
937 lines
QuadProg
A dense quadratic program solver in pure rust, based on the Goldfarb Idnani algorithm. This implementation is based on a few sources, but drew primarily from quadprog.
Usage
Add this to your Cargo.toml
:
[dependencies]
quadprog = "0.0.1"
Then solve using:
quadprog::solve_qp(...)
lib.rs
:
Solve dense quadratic programs.
This crate implements the Goldfarb Indiani method[^1] for solving quadratic programs of the form:
minimize 1/2 x' Q x + c' x
subject to A1 x = b1
A2 x <= b2
in pure rust. These are solved via the only exported function [solve_qp] which returns a [Solution] struct.
Examples
If we want to solve
minimize 1/2 x^2 + 1/2 y^2 + x
subject to x + 2 y >= 1
we can do so with the following example:
let mut q = [1., 0., 0., 1.];
let c = [1., 0.];
let a = [-1., -2.];
let b = [-1.];
let sol = solve_qp(&mut q, &c, &a, &b, 0, false).unwrap();
assert_eq!(sol.sol, &[-0.6, 0.8]);
[^1] D. Goldfarb and A. Idnani (1983). A numerically stable dual method for solving strictly convex quadratic programs. Mathematical Programming, 27, 1-33.