Crates.io | simple_qp |
lib.rs | simple_qp |
version | 0.2.2 |
source | src |
created_at | 2024-07-07 15:10:17.142043 |
updated_at | 2024-10-04 14:46:03.288814 |
description | Allows formulating Quadratic Programming problems in a symbolic way. |
homepage | https://github.com/Deepthought73/simple_qp |
repository | https://github.com/Deepthought73/simple_qp |
max_upload_size | |
id | 1294941 |
size | 61,206 |
simple_qp
allows formulating Quadratic Programming (QP) problems in a symbolic way.
Define your QP without unreadable matrix initializations.
At the moment, these are the available solver backends:
OSQP
CLARABEL
COIN CBC
: restricted to Linear Programming problemsuse simple_qp::constraint;
use simple_qp::problem_variables::ProblemVariables;
use simple_qp::solver::osqp_solver::OSQPSolver;
use simple_qp::solver::Solver;
fn main() {
let mut problem = ProblemVariables::default();
let x = problem.add_variable(Some(85.), None);
let y = problem.add_variable(Some(4.0), None);
let objective = (x - 42).square() + (y - 73).square() + (x - y).square();
let constraints = vec![
constraint!(50 <= 1.5 * (x / 3 + 2 * y) <= 100),
constraint!(x - y == 75 + 2 * y),
];
let solver = OSQPSolver::default();
let res = solver
.solve(problem, objective, constraints)
.expect("Solver error");
let x_solution = res.value(x);
let y_solution = res.value(y);
println!("x = {}, y = {}", x_solution, y_solution);
}
Thanks FlorianNAdam for the constraint!
macro.