# HG changeset patch
# User Lachlan Andrew
# Date 1456550196 -39600
# Sat Feb 27 16:16:36 2016 +1100
# Node ID 34498e4e67a6587cede872d1429caa38f7e7c245
# Parent c284d51a7c81b2aaae1aa087993c5845f570fde1
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 c284d51a7c81 -r 34498e4e67a6 scripts/optimization/glpk.m
--- a/scripts/optimization/glpk.m Sat Feb 27 15:27:52 2016 +1100
+++ b/scripts/optimization/glpk.m Sat Feb 27 16:16:36 2016 +1100
@@ -498,9 +498,13 @@ function [xopt, fmin, errnum, extra] = g
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 c284d51a7c81 -r 34498e4e67a6 scripts/optimization/qp.m
--- a/scripts/optimization/qp.m Sat Feb 27 15:27:52 2016 +1100
+++ b/scripts/optimization/qp.m Sat Feb 27 16:16:36 2016 +1100
@@ -373,8 +373,8 @@ function [x, obj, INFO, lambda] = qp (x0
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 c284d51a7c81 -r 34498e4e67a6 scripts/optimization/sqp.m
--- a/scripts/optimization/sqp.m Sat Feb 27 15:27:52 2016 +1100
+++ b/scripts/optimization/sqp.m Sat Feb 27 16:16:36 2016 +1100
@@ -408,6 +408,7 @@ function [x, obj, info, iter, nf, lambda
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 @@ function [x, obj, info, iter, nf, lambda
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