 Module for solving quadratic programming problems

## Stats

StarsIssuesVersionUpdatedCreatedSize
3101.6.15 years ago12 years ago QUADPROG ========  This module contains routines for solving quadratic programming problems, written in JavaScript. quadprog is a porting of a R package: quadprog, implemented in Fortran. It implements the dual method of Goldfarb and Idnani (1982, 1983) for solving quadratic programming problems of the form min(d T b + 1=2b T Db) with the constraints AT b >= b0. References ========== D. Goldfarb and A. Idnani (1982). Dual and Primal-Dual Methods for Solving Strictly Convex Quadratic Programs. In J. P. Hennart (ed.), Numerical Analysis, Springer-Verlag, Berlin, pages 226–239. D. Goldfarb and A. Idnani (1983). A numerically stable dual method for solving strictly convex quadratic programs. Mathematical Programming, 27, 1–33. Example ======== ``` // ## // ## Assume we want to minimize: -(0 5 0) %% b + 1/2 b^T b // ## under the constraints: A^T b >= b0 // ## with b0 = (-8,2,0)^T // ## and // ## (-4 2 0) // ## A = (-3 1 -2) // ## ( 0 0 1) // ## we can use solve.QP as follows: // ## // Dmat <- matrix(0,3,3) // diag(Dmat) <- 1 // dvec <- c(0,5,0) // Amat <- matrix(c(-4,-3,0,2,1,0,0,-2,1),3,3) // bvec <- c(-8,2,0) // solve.QP(Dmat,dvec,Amat,bvec=bvec) var qp = require('quadprog'); var Dmat = , dvec = , Amat = , bvec = , res; Dmat1 = ; Dmat2 = ; Dmat3 = ; Dmat11 = 1; Dmat21 = 0; Dmat31 = 0; Dmat12 = 0; Dmat22 = 1; Dmat32 = 0; Dmat13 = 0; Dmat23 = 0; Dmat33 = 1; dvec1 = 0; dvec2 = 5; dvec3 = 0; Amat1 = ; Amat2 = ; Amat3 = ; Amat11 = -4; Amat21 = -3; Amat31 = 0; Amat12 = 2; Amat22 = 1; Amat32 = 0; Amat13 = 0; Amat23 = -2; Amat33 = 1; bvec1 = -8; bvec2 = 2; bvec3 = 0; res = qp.solveQP(Dmat, dvec, Amat, bvec) ``` Installation ============ To install with npm:
``npm install quadprog``
Tested locally with Node.js 10.x and with R 3.4.1. Notes ===== To maintain a one-to-one porting with the Fortran implementation, the array index starts from 1 and not from zero. Please, be aware and give a look at the examples in the test folder. If you are using `node-quadprog` via Numeric.js, don't forget the releases may be not in sync. Latest release is here. Applications ============ See also ======== Methods ======= solveQP(Dmat, dvec, Amat, bvec, meq=0, factorized=FALSE) ------- Arguments
• Dmat matrix appearing in the quadratic function to be minimized.
• dvec vector appearing in the quadratic function to be minimized.
• Amat matrix deﬁning the constraints under which we want to minimize the
• bvec vector holding the values of b0 (defaults to zero).
• meq the ﬁrst meq constraints are treated as equality constraints, all
further as inequality constraints (defaults to 0).
• factorized logical ﬂag: if TRUE, then we are passing R1 (where D = RT R)
instead of the matrix D in the argument Dmat. Value An object with the following property:
• solution vector containing the solution of the quadratic programming
problem.
• value scalar, the value of the quadratic function at the solution
• unconstrained.solution vector containing the unconstrained minimizer of the
Testing ======= Base test cases are in json formatted files with the name `<name>-data.json`. These can be passed into `solve.R` to create the standard R results for solveQP with the name `<name>-result.json`. The standard usage is `Rscript solve.R *-data.json`, but you may wish to only create result files for specific tests. The combination of these files is then used by `solution-test.js` and `bench.js`. Adding Tests ------------ To add a new test simply create a file called `<name>-data.json` in the test directory, and then call `Rscript solve.R <name>-data.json` and commit the results.