{"id":24895396,"url":"https://github.com/albertosantini/quadprog","last_synced_at":"2025-12-16T21:44:44.481Z","repository":{"id":1653387,"uuid":"2379302","full_name":"albertosantini/quadprog","owner":"albertosantini","description":"Module for solving quadratic programming problems with constraints","archived":false,"fork":false,"pushed_at":"2023-07-13T20:28:29.000Z","size":179,"stargazers_count":33,"open_issues_count":0,"forks_count":10,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-01-09T11:33:30.309Z","etag":null,"topics":["quadratic-programming"],"latest_commit_sha":null,"homepage":"https://github.com/albertosantini/node-conpa","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/albertosantini.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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}},"created_at":"2011-09-13T15:44:12.000Z","updated_at":"2023-11-13T10:31:55.000Z","dependencies_parsed_at":"2023-09-25T04:52:22.326Z","dependency_job_id":"dedc04a3-7e07-4a3a-af43-03ed934b2d31","html_url":"https://github.com/albertosantini/quadprog","commit_stats":null,"previous_names":["albertosantini/node-quadprog"],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/albertosantini%2Fquadprog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/albertosantini%2Fquadprog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/albertosantini%2Fquadprog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/albertosantini%2Fquadprog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/albertosantini","download_url":"https://codeload.github.com/albertosantini/quadprog/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":236706757,"owners_count":19192046,"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":["quadratic-programming"],"created_at":"2025-02-01T19:18:24.589Z","updated_at":"2025-10-16T10:30:59.139Z","avatar_url":"https://github.com/albertosantini.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"QUADPROG\n========\n[![NPM version](https://badge.fury.io/js/quadprog.svg)](http://badge.fury.io/js/quadprog)\n![](https://github.com/albertosantini/quadprog/workflows/CI/badge.svg)\n\nThis module contains routines for solving quadratic programming problems,\nwritten in JavaScript.\n\nquadprog is a porting of a [R](http://www.r-project.org) package:\n[quadprog](http://cran.r-project.org/web/packages/quadprog/), implemented in\nFortran.\n\nIt implements the dual method of Goldfarb and Idnani (1982, 1983) for solving\nquadratic programming problems of the form\n\n$$\n\\begin{aligned}\n\\text{minimize} \\quad \u0026 -d^T b + \\frac{1}{2} b^T D b \\\\\n\\text{subject to} \\quad \u0026 A^T b \\geq b_0\n\\end{aligned}\n$$\n\nReferences\n==========\n\n- D. Goldfarb and A. Idnani (1982). Dual and Primal-Dual Methods for Solving\nStrictly Convex Quadratic Programs. In J. P. Hennart (ed.), Numerical Analysis,\nSpringer-Verlag, Berlin, pages 226–239.\n\n- D. Goldfarb and A. Idnani (1983). A numerically stable dual method for solving\nstrictly convex quadratic programs. Mathematical Programming, 27, 1–33.\n\n\nInstallation and usage\n======================\n\nTo install with [npm](http://github.com/isaacs/npm):\n\n    npm install quadprog\n\nUsage:\n\n    import { solveQP } from \"quadprog\"; // ESM\n\nor\n\n    const { solveQP } = require(\"quadprog\"); // CJS\n\nTested locally with Node.js 22.x and with R 4.x.\n\nExample\n========\n\n```r\n## Assume we want to minimize: -(0 5 0) %*% b + 1/2 b^T b\n## under the constraints: A^T b \u003e= b0\n## with b0 = (-8,2,0)^T\n## and\n##     (-4 2  0)\n## A = (-3 1 -2)\n##     ( 0 0  1)\n## we can use solve.QP as follows:\n##\nrequire(quadprog)\n\nDmat \u003c- matrix(0, 3, 3)\ndiag(Dmat) \u003c- 1\ndvec \u003c- c(0, 5 ,0)\nAmat \u003c- matrix(c(-4, -3, 0, 2, 1, 0, 0, -2, 1), 3, 3)\nbvec \u003c- c(-8, 2 ,0)\n\nsolve.QP(Dmat, dvec, Amat, bvec=bvec)\n\n# $solution\n# [1] 0.4761905 1.0476190 2.0952381\n\n# $value\n# [1] -2.380952\n\n# $unconstrained.solution\n# [1] 0 5 0\n\n# $iterations\n# [1] 3 0\n\n# $Lagrangian\n# [1] 0.0000000 0.2380952 2.0952381\n\n# $iact\n# [1] 3 2\n```\n\n```javascript\nimport { solveQP } from \"quadprog\";\n\nconst Dmat = [], dvec = [], Amat = [], bvec = [];\n\nDmat[1] = [];\nDmat[2] = [];\nDmat[3] = [];\nDmat[1][1] = 1;\nDmat[2][1] = 0;\nDmat[3][1] = 0;\nDmat[1][2] = 0;\nDmat[2][2] = 1;\nDmat[3][2] = 0;\nDmat[1][3] = 0;\nDmat[2][3] = 0;\nDmat[3][3] = 1;\n\ndvec[1] = 0;\ndvec[2] = 5;\ndvec[3] = 0;\n\nAmat[1] = [];\nAmat[2] = [];\nAmat[3] = [];\nAmat[1][1] = -4;\nAmat[2][1] = -3;\nAmat[3][1] = 0;\nAmat[1][2] = 2;\nAmat[2][2] = 1;\nAmat[3][2] = 0;\nAmat[1][3] = 0;\nAmat[2][3] = -2;\nAmat[3][3] = 1;\n\nbvec[1] = -8;\nbvec[2] = 2;\nbvec[3] = 0;\n\nsolveQP(Dmat, dvec, Amat, bvec)\n\n// {\n//   solution: [\n//     \u003c1 empty item\u003e,\n//     0.47619047619047616,\n//     1.0476190476190477,\n//     2.0952380952380953\n//   ],\n//   Lagrangian: [ \u003c1 empty item\u003e, 0, 0.23809523809523808, 2.0952380952380953 ],\n//   value: [ \u003c1 empty item\u003e, -2.380952380952381 ],\n//   unconstrained_solution: [ \u003c1 empty item\u003e, 0, 5, 0 ],\n//   iterations: [ \u003c1 empty item\u003e, 3, 0 ],\n//   iact: [ \u003c1 empty item\u003e, 3, 2, 0 ],\n//   message: ''\n// }\n```\n\nNotes\n=====\n\nThis is a strictly porting from Fortran code contained in R package [quadprog](https://cran.r-project.org/web/packages/quadprog/).\n\n**To maintain a one-to-one porting with the Fortran implementation, the array\nindex starts from 1 and not from zero. Please, be aware and give a look at the\nexamples in the test folder**.\n\nIf you are using `quadprog` via Numeric.js, don't forget the releases may\nbe not in sync.\n\nLatest release is [here](https://github.com/albertosantini/quadprog).\n\nApplications\n============\n\n- [ConPA](https://github.com/albertosantini/node-conpa)\n- [Numeric.js](https://github.com/sloisel/numeric)\n\nSee also\n========\n\n- [GPU Accelerated JavaScript](https://github.com/gpujs/gpu.js)\n- [Vincent Zoonekynd's Blog](http://zoonek.free.fr/blosxom/R/2012-06-01_Optimization.html)\n- [fast.js](https://github.com/codemix/fast.js)\n- [Vectorious](https://github.com/mateogianolio/vectorious)\n\nMethods\n=======\n\nsolveQP(Dmat, dvec, Amat, bvec, meq=0, factorized=FALSE)\n-------\n\n**Arguments**\n\n- *Dmat* matrix appearing in the quadratic function to be minimized.\n\n- *dvec* vector appearing in the quadratic function to be minimized.\n\n- *Amat* matrix deﬁning the constraints under which we want to minimize the\nquadratic function.\n\n- *bvec* vector holding the values of b0 (defaults to zero).\n\n- *meq* the ﬁrst meq constraints are treated as equality constraints, all\nfurther as inequality constraints (defaults to 0).\n\n- *factorized* logical ﬂag: if TRUE, then we are passing R1 (where D = RT R)\ninstead of the matrix D in the argument Dmat.\n\n**Value**\n\nAn object with the following property:\n\n- *solution* vector containing the solution of the quadratic programming\nproblem.\n\n- *value* scalar, the value of the quadratic function at the solution\n\n- *unconstrained.solution* vector containing the unconstrained minimizer of the\nquadratic function.\n\n- *iterations* vector of length 2, the ﬁrst component contains the number of\niterations the algorithm needed, the second indicates how often constraints\nbecame inactive after becoming active ﬁrst.\n\n- *Lagrangian* vector with the Lagrangian multipliers at the solution.\n\n- *iact* vector with the indices of the active constraints at the solution.\n\n- *message* string containing an error message, if the call failed, otherwise empty.\n\nTesting\n=======\n\nBase test cases are in json formatted files with the name `\u003cname\u003e-data.json`.\nThese can be passed into `solve.R` to create the standard R results for solveQP with the name `\u003cname\u003e-result.json`.\nThe standard usage is `Rscript solve.R *-data.json`, but you may wish to only create result files for specific tests.\nThe combination of these files is then used by `solution-test.js` and `bench.js`.\n\n\nAdding Tests\n------------\n\nTo add a new test simply create a file called `\u003cname\u003e-data.json` in the test directory, and then call `Rscript solve.R \u003cname\u003e-data.json` and commit the results.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falbertosantini%2Fquadprog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falbertosantini%2Fquadprog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falbertosantini%2Fquadprog/lists"}