9 releases (breaking)
0.7.0 | Feb 13, 2021 |
---|---|
0.6.0 | Feb 7, 2021 |
0.5.0 | Jun 9, 2019 |
0.4.2 | Feb 17, 2019 |
0.1.0 | Jan 19, 2019 |
#45 in Science
24 downloads per month
140KB
3K
SLoC
totsu
Totsu (凸 in Japanese) means convex.
This crate for Rust provides a first-order conic linear program solver.
Target problem
A common target problem is continuous scalar convex optimization such as LP, QP, QCQP, SOCP and SDP. Each of those problems can be represented as a conic linear program.
Algorithm and design concepts
The author combines the two papers [1] [2] so that the homogeneous self-dual embedding matrix in [2] is formed as a linear operator in [1].
See documentation for more details.
Features
This crate can be used without the standard library (#![no_std]
).
Use this in Cargo.toml
:
[dependencies.totsu]
version = "0.7.0"
default-features = false
features = ["nostd"]
Some module and structs are not availale in this case.
Changelog
Changelog is available in CHANGELOG.md.
Examples
QP
use float_eq::assert_float_eq;
use totsu::prelude::*;
use totsu::operator::MatBuild;
use totsu::problem::ProbQP;
type LA = FloatGeneric<f64>;
type AMatBuild = MatBuild<LA, f64>;
type AProbQP = ProbQP<LA, f64>;
type ASolver = Solver<LA, f64>;
let n = 2; // x0, x1
let m = 1;
let p = 0;
// (1/2)(x - a)^2 + const
let mut sym_p = AMatBuild::new(MatType::SymPack(n));
sym_p[(0, 0)] = 1.;
sym_p[(1, 1)] = 1.;
let mut vec_q = AMatBuild::new(MatType::General(n, 1));
vec_q[(0, 0)] = -(-1.); // -a0
vec_q[(1, 0)] = -(-2.); // -a1
// 1 - x0/b0 - x1/b1 <= 0
let mut mat_g = AMatBuild::new(MatType::General(m, n));
mat_g[(0, 0)] = -1. / 2.; // -1/b0
mat_g[(0, 1)] = -1. / 3.; // -1/b1
let mut vec_h = AMatBuild::new(MatType::General(m, 1));
vec_h[(0, 0)] = -1.;
let mat_a = AMatBuild::new(MatType::General(p, n));
let vec_b = AMatBuild::new(MatType::General(p, 1));
let s = ASolver::new().par(|p| {
p.max_iter = Some(100_000);
});
let mut qp = AProbQP::new(sym_p, vec_q, mat_g, vec_h, mat_a, vec_b, s.par.eps_zero);
let rslt = s.solve(qp.problem(), NullLogger).unwrap();
assert_float_eq!(rslt.0[0..2], [2., 0.].as_ref(), abs_all <= 1e-3);
Other Examples
You can find other tests of pre-defined solvers. More practical examples are also available.
Dependencies
~2.5MB
~104K SLoC