{"id":13437446,"url":"https://github.com/google/osqp-cpp","last_synced_at":"2025-03-19T06:31:11.770Z","repository":{"id":40514074,"uuid":"285065928","full_name":"google/osqp-cpp","owner":"google","description":"A C++ interface for the OSQP quadratic programming solver.","archived":false,"fork":false,"pushed_at":"2023-10-04T15:15:52.000Z","size":33,"stargazers_count":250,"open_issues_count":2,"forks_count":63,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-01-07T16:08:41.094Z","etag":null,"topics":["eigen","osqp","quadratic-programming"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/google.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2020-08-04T18:32:04.000Z","updated_at":"2025-01-07T06:37:09.000Z","dependencies_parsed_at":"2024-04-14T00:48:37.219Z","dependency_job_id":null,"html_url":"https://github.com/google/osqp-cpp","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/google%2Fosqp-cpp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/google%2Fosqp-cpp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/google%2Fosqp-cpp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/google%2Fosqp-cpp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/google","download_url":"https://codeload.github.com/google/osqp-cpp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244371041,"owners_count":20442330,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["eigen","osqp","quadratic-programming"],"created_at":"2024-07-31T03:00:57.083Z","updated_at":"2025-03-19T06:31:10.007Z","avatar_url":"https://github.com/google.png","language":"C++","readme":"# osqp-cpp: A C++ wrapper for [OSQP](https://osqp.org/)\n\nA C++ wrapper for [OSQP](https://github.com/oxfordcontrol/osqp), an\n[ADMM](http://stanford.edu/~boyd/admm.html)-based solver for\n[quadratic programming](https://en.wikipedia.org/wiki/Quadratic_programming).\n\nCompared with OSQP's native C interface, the wrapper provides a more convenient\ninput format using Eigen sparse matrices and handles the lifetime of the\n`OSQPWorkspace` struct. This package has similar functionality to\n[osqp-eigen](https://github.com/robotology/osqp-eigen).\n\nThe full API is documented in-line in `osqp++.h`. We describe only the input\nformat in this README.\n\nNote: OSQP uses looser default tolerances than other similar solvers. We\nrecommend looking at the description of the convergence tolerances in Section\n3.4 of the OSQP [paper](https://arxiv.org/abs/1711.08013) and adjusting\ntolerances via the `OsqpSettings` struct as appropriate.\n\nThis is not an officially supported Google product.\n\n## `OsqpInstance` format\n\nOSQP solves the convex quadratic optimization problem:\n\n```\nmin_x 0.5 * x'Px + q'x\ns.t.  l \u003c= Ax \u003c= u\n```\n\nwhere `P` is a symmetric positive semi-definite matrix.\n\nThe inequalities are component-wise, and equalities may be enforced by setting\n`l[i] == u[i]` for some row `i`. Single-sided inequalities can be enforced by\nsetting the lower or upper bounds to negative or positive infinity\n(`std::numeric_limits\u003cdouble\u003e::infinity()`), respectively.\n\nThis maps to the `OsqpInstance` struct in `osqp++.h` as follows.\n\n-   `objective_matrix` is `P`.\n-   `objective_vector` is `q`.\n-   `constraint_matrix` is `A`.\n-   `lower_bounds` is `l`.\n-   `upper_bounds` is `u`.\n\n## Example usage\n\nThe code below formulates and solves the following 2-dimensional optimization\nproblem:\n\n```\nmin_(x,y) x^2 + 0.5 * x * y + y^2 + x\ns.t.      x \u003e= 1\n```\n\n```C++\nconst double kInfinity = std::numeric_limits\u003cdouble\u003e::infinity();\nSparseMatrix\u003cdouble\u003e objective_matrix(2, 2);\nconst Triplet\u003cdouble\u003e kTripletsP[] = {\n    {0, 0, 2.0}, {1, 0, 0.5}, {0, 1, 0.5}, {1, 1, 2.0}};\nobjective_matrix.setFromTriplets(std::begin(kTripletsP),\n                                   std::end(kTripletsP));\n\nSparseMatrix\u003cdouble\u003e constraint_matrix(1, 2);\nconst Triplet\u003cdouble\u003e kTripletsA[] = {{0, 0, 1.0}};\nconstraint_matrix.setFromTriplets(std::begin(kTripletsA),\n                                      std::end(kTripletsA));\n\nOsqpInstance instance;\ninstance.objective_matrix = objective_matrix;\ninstance.objective_vector.resize(2);\ninstance.objective_vector \u003c\u003c 1.0, 0.0;\ninstance.constraint_matrix = constraint_matrix;\ninstance.lower_bounds.resize(1);\ninstance.lower_bounds \u003c\u003c 1.0;\ninstance.upper_bounds.resize(1);\ninstance.upper_bounds \u003c\u003c kInfinity;\n\nOsqpSolver solver;\nOsqpSettings settings;\n// Edit settings if appropriate.\nauto status = solver.Init(instance, settings);\n// Assuming status.ok().\nOsqpExitCode exit_code = solver.Solve();\n// Assuming exit_code == OsqpExitCode::kOptimal.\ndouble optimal_objective = solver.objective_value();\nEigen::VectorXd optimal_solution = solver.primal_solution();\n```\n\n## Installation (Unix)\n\nosqp-cpp requires CMake, a C++17 compiler, and the following packages:\n\n- [OSQP](https://github.com/oxfordcontrol/osqp) (compiled with 64-bit integers)\n- [abseil-cpp](https://github.com/abseil/abseil-cpp)\n- [Eigen](http://eigen.tuxfamily.org/index.php?title=Main_Page)\n- [googletest](https://github.com/google/googletest) (for testing only)\n\nOn Debian/Ubuntu systems you may install Eigen via the `libeigen3-dev` package.\n\nosqp-cpp will attempt to automatically detect if the necessary targets exist as\npart of the same project. If the necessary `OSQP`, `abseil-cpp`, or `googletest`\ntargets are not found, osqp-cpp will attempt to download the sources from their\nGitHub repositories through the use of CMake's `FetchContent` functionality. If\nthe `Eigen3` targets are not found, osqp-cpp will attempt to find Eigen3 as a\nsystem package. To prevent osqp-cpp from unnecessarily downloading target\ndependencies, please ensure that any target dependencies that are already\navailable are included before osqp-cpp.\n\nTo build osqp-cpp, run the following from the `osqp-cpp` directory:\n\n```sh\n$ mkdir build; cd build\n$ cmake ..\n$ make\n$ make test\n```\n\nThe interface is regularly tested only on Linux. Contributions to support and\nautomatically test additional platforms are welcome.\n\n## Installation (Windows)\n\n*These instructions are maintained by the community.*\n\nInstall prerequisite packages:\n\n```sh\n$ vcpkg install eigen3:x64-windows\n$ vcpkg install abseil:x64-windows\n$ vcpkg install gtest:x64-windows\n```\n\nThen, run the following from the `osqp-cpp` directory:\n\n```sh\n$ mkdir build; cd build\n$ cmake ..\n$ cmake --build .\n$ cd Debug\n```\n\n## FAQ\n\n-   Is OSQP deterministic?\n    -   No, not in its default configuration. Section 5.2 of the OSQP\n        [paper](https://arxiv.org/abs/1711.08013) describes that the update rule\n        for the step size rho depends on the ratio between the runtime of the\n        iterations and the runtime of the numerical factorization. Setting\n        `adaptive_rho` to `false` disables this update rule and makes OSQP\n        deterministic, but this could significantly slow down OSQP's\n        convergence.\n","funding_links":[],"categories":["Libraries"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoogle%2Fosqp-cpp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgoogle%2Fosqp-cpp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoogle%2Fosqp-cpp/lists"}