All Projects → google → osqp-cpp

google / osqp-cpp

Licence: Apache-2.0 license
A C++ interface for the OSQP quadratic programming solver.

Programming Languages

C++
36643 projects - #6 most used programming language
CMake
9771 projects

Projects that are alternatives of or similar to osqp-cpp

rlqp
Accelerating Quadratic Optimization with Reinforcement Learning
Stars: ✭ 71 (-55.62%)
Mutual labels:  quadratic-programming, osqp
qpmad
ROS-compatible Eigen-based Goldfarb-Idnani quadratic programming solver
Stars: ✭ 41 (-74.37%)
Mutual labels:  eigen, quadratic-programming
Eigendocinchinese
Eigen3.3.7 Doc中文版
Stars: ✭ 28 (-82.5%)
Mutual labels:  eigen
SimplexSolver
An easy-to-use Simplex solver class for linear programming.
Stars: ✭ 18 (-88.75%)
Mutual labels:  eigen
Hole fixer
Demo implementation of smoothly filling holes in 3D meshes using surface fairing
Stars: ✭ 165 (+3.13%)
Mutual labels:  eigen
Epigraph
A C++ interface to formulate and solve linear, quadratic and second order cone problems.
Stars: ✭ 101 (-36.87%)
Mutual labels:  eigen
Mathtoolbox
Mathematical tools (interpolation, dimensionality reduction, optimization, etc.) written in C++11 with Eigen
Stars: ✭ 172 (+7.5%)
Mutual labels:  eigen
Math
The Stan Math Library is a C++ template library for automatic differentiation of any order using forward, reverse, and mixed modes. It includes a range of built-in functions for probabilistic modeling, linear algebra, and equation solving.
Stars: ✭ 494 (+208.75%)
Mutual labels:  eigen
dtt
A C++ header-only for data transfer between linear algebra libraries (Eigen, Armadillo, OpenCV, ArrayFire, LibTorch).
Stars: ✭ 74 (-53.75%)
Mutual labels:  eigen
Monocular Visual Odometry
A simple monocular visual odometry (part of vSLAM) by ORB keypoints with initialization, tracking, local map and bundle adjustment. (WARNING: Hi, I'm sorry that this project is just tuned for course demo, not for real world applications !!!)
Stars: ✭ 147 (-8.12%)
Mutual labels:  eigen
eigen
Owl's OCaml Interface to Eigen3 C++ Library
Stars: ✭ 30 (-81.25%)
Mutual labels:  eigen
Pydensecrf
Python wrapper to Philipp Krähenbühl's dense (fully connected) CRFs with gaussian edge potentials.
Stars: ✭ 1,633 (+920.63%)
Mutual labels:  eigen
Jpdaf tracking
A tracker based on joint probabilistic data association filtering.
Stars: ✭ 107 (-33.12%)
Mutual labels:  eigen
Dive Into Ml System
Dive into machine learning system, start from reinventing the wheel.
Stars: ✭ 220 (+37.5%)
Mutual labels:  eigen
Numpycpp
A c++ header library for matrix operation inspired Numpy Scipy, MATLAB only using Eigen.
Stars: ✭ 30 (-81.25%)
Mutual labels:  eigen
node-quadprog
Module for solving quadratic programming problems with constraints
Stars: ✭ 28 (-82.5%)
Mutual labels:  quadratic-programming
Cppnumericalsolvers
a lightweight C++17 library of numerical optimization methods for nonlinear functions (Including L-BFGS-B for TensorFlow)
Stars: ✭ 638 (+298.75%)
Mutual labels:  eigen
Modernroboticscpp
Modern Robotics: Mechanics, Planning, and Control C++ Library --- The primary purpose of the provided software is to be easy to read and educational, reinforcing the concepts in the book. The code is optimized neither for efficiency nor robustness. http://modernrobotics.org/
Stars: ✭ 170 (+6.25%)
Mutual labels:  eigen
Mtensor
A C++ Cuda Tensor Lazy Computing Library
Stars: ✭ 115 (-28.12%)
Mutual labels:  eigen
quadruped control
Quadruped control architecture
Stars: ✭ 46 (-71.25%)
Mutual labels:  quadratic-programming

osqp-cpp: A C++ wrapper for OSQP

A C++ wrapper for OSQP, an ADMM-based solver for quadratic programming.

Compared with OSQP's native C interface, the wrapper provides a more convenient input format using Eigen sparse matrices and handles the lifetime of the OSQPWorkspace struct. This package has similar functionality to osqp-eigen.

The full API is documented in-line in osqp++.h. We describe only the input format in this README.

Note: OSQP uses looser default tolerances than other similar solvers. We recommend looking at the description of the convergence tolerances in Section 3.4 of the OSQP paper and adjusting tolerances via the OsqpSettings struct as appropriate.

This is not an officially supported Google product.

OsqpInstance format

OSQP solves the convex quadratic optimization problem:

min_x 0.5 * x'Px + q'x
s.t.  l <= Ax <= u

where P is a symmetric positive semi-definite matrix.

The inequalities are component-wise, and equalities may be enforced by setting l[i] == u[i] for some row i. Single-sided inequalities can be enforced by setting the lower or upper bounds to negative or positive infinity (std::numeric_limits<double>::infinity()), respectively.

This maps to the OsqpInstance struct in osqp++.h as follows.

  • objective_matrix is P.
  • objective_vector is q.
  • constraint_matrix is A.
  • lower_bounds is l.
  • upper_bounds is u.

Example usage

The code below formulates and solves the following 2-dimensional optimization problem:

min_(x,y) x^2 + 0.5 * x * y + y^2 + x
s.t.      x >= 1
const double kInfinity = std::numeric_limits<double>::infinity();
SparseMatrix<double> objective_matrix(2, 2);
const Triplet<double> kTripletsP[] = {
    {0, 0, 2.0}, {1, 0, 0.5}, {0, 1, 0.5}, {1, 1, 2.0}};
objective_matrix.setFromTriplets(std::begin(kTripletsP),
                                   std::end(kTripletsP));

SparseMatrix<double> constraint_matrix(1, 2);
const Triplet<double> kTripletsA[] = {{0, 0, 1.0}};
constraint_matrix.setFromTriplets(std::begin(kTripletsA),
                                      std::end(kTripletsA));

OsqpInstance instance;
instance.objective_matrix = objective_matrix;
instance.objective_vector.resize(2);
instance.objective_vector << 1.0, 0.0;
instance.constraint_matrix = constraint_matrix;
instance.lower_bounds.resize(1);
instance.lower_bounds << 1.0;
instance.upper_bounds.resize(1);
instance.upper_bounds << kInfinity;

OsqpSolver solver;
OsqpSettings settings;
// Edit settings if appropriate.
auto status = solver.Init(instance, settings);
// Assuming status.ok().
OsqpExitCode exit_code = solver.Solve();
// Assuming exit_code == OsqpExitCode::kOptimal.
double optimal_objective = solver.objective_value();
Eigen::VectorXd optimal_solution = solver.primal_solution();

Installation (Unix)

osqp-cpp requires CMake, a C++17 compiler, and the following packages:

On Debian/Ubuntu systems you may install Eigen via the libeigen3-dev package.

osqp-cpp will attempt to automatically detect if the necessary targets exist as part of the same project. If the necessary OSQP, abseil-cpp, or googletest targets are not found, osqp-cpp will attempt to download the sources from their GitHub repositories through the use of CMake's FetchContent functionality. If the Eigen3 targets are not found, osqp-cpp will attempt to find Eigen3 as a system package. To prevent osqp-cpp from unnecessarily downloading target dependencies, please ensure that any target dependencies that are already available are included before osqp-cpp.

To build osqp-cpp, run the following from the osqp-cpp directory:

$ mkdir build; cd build
$ cmake ..
$ make
$ make test

The interface is regularly tested only on Linux. Contributions to support and automatically test additional platforms are welcome.

Installation (Windows)

These instructions are maintained by the community.

Install prerequisite packages:

$ vcpkg install eigen3:x64-windows
$ vcpkg install abseil:x64-windows
$ vcpkg install gtest:x64-windows

Then, run the following from the osqp-cpp directory:

$ mkdir build; cd build
$ cmake ..
$ cmake --build .
$ cd Debug

FAQ

  • Is OSQP deterministic?
    • No, not in its default configuration. Section 5.2 of the OSQP paper describes that the update rule for the step size rho depends on the ratio between the runtime of the iterations and the runtime of the numerical factorization. Setting adaptive_rho to false disables this update rule and makes OSQP deterministic, but this could significantly slow down OSQP's convergence.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].