changeset 22224:20e0c0b8820c

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.
author Lachlan Andrew <lachlanbis@gmail.com>
date Sat, 27 Feb 2016 16:16:36 +1100
parents cf18d6e791a1
children 42456fc9bf6c
files scripts/optimization/glpk.m scripts/optimization/qp.m scripts/optimization/sqp.m
diffstat 3 files changed, 10 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- 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
--- 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);
--- 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