# HG changeset patch # User Lachlan Andrew # Date 1456550196 -39600 # Node ID 20e0c0b8820c9c4094f018b54426e2b258c07654 # Parent cf18d6e791a140b7df0dd32b32354d975c5554a1 Allow sequential quadratic programs with infeasible QPs (bug #36015). * qp.m: Use conformant sizes of temporary C and lower bound in call to glpk. * glpk.m: State size of A if its size doesn't match C and lb. * sqp.m: If the QP was infeasible, restore lambda to the correct size. diff -r cf18d6e791a1 -r 20e0c0b8820c scripts/optimization/glpk.m --- a/scripts/optimization/glpk.m Thu Feb 11 21:06:45 2016 +1100 +++ b/scripts/optimization/glpk.m Sat Feb 27 16:16:36 2016 +1100 @@ -498,9 +498,13 @@ if (isempty (A)) error ("glpk: A cannot be an empty matrix"); endif + if (! isreal (A)) + error ("glpk: A must be real valued, not %s", typeinfo (A)); + endif [nc, nxa] = size (A); - if (! isreal (A) || nxa != nx) - error ("glpk: A must be a real valued %d by %d matrix", nc, nx); + if (nxa != nx) + error ("glpk: A must be %d by %d, not %d by %d", + nc, nx, rows(A), columns(A)); endif ## 3) RHS diff -r cf18d6e791a1 -r 20e0c0b8820c scripts/optimization/qp.m --- a/scripts/optimization/qp.m Thu Feb 11 21:06:45 2016 +1100 +++ b/scripts/optimization/qp.m Sat Feb 27 16:16:36 2016 +1100 @@ -373,8 +373,8 @@ Atmp = [Ain, gamma]; btmp = bin; endif - ctmp = [zeros(n-n_eq, 1); ones(n_in, 1)]; - lb = [-Inf(n-n_eq,1); zeros(n_in,1)]; + ctmp = [zeros(n, 1); ones(n_in, 1)]; + lb = [-Inf(n,1); zeros(n_in,1)]; ub = []; ctype = repmat ("L", n_in, 1); [P, dummy, status] = glpk (ctmp, Atmp, btmp, lb, ub, ctype); diff -r cf18d6e791a1 -r 20e0c0b8820c scripts/optimization/sqp.m --- a/scripts/optimization/sqp.m Thu Feb 11 21:06:45 2016 +1100 +++ b/scripts/optimization/sqp.m Sat Feb 27 16:16:36 2016 +1100 @@ -408,6 +408,7 @@ g = -ce; d = -ci; + old_lambda = lambda; [p, obj_qp, INFO, lambda] = qp (x, B, c, F, g, [], [], d, C, Inf (size (d))); @@ -425,6 +426,7 @@ INFO.solveiter); case 6 warning (id, "sqp: QP subproblem is infeasible"); + lambda = old_lambda; # The return value was size 0x0 in this case. endswitch ## Choose mu such that p is a descent direction for the chosen