changeset 33020:db32db01963a stable

glpk: Fix lower bound for GLP_DB. * libinterp/dldfcn/__glpk__.cc (glpk): Use correct lower bound if the constraint type is "D" (symmetric inequality constraint). * glpk.m: Add BIST with "ctype" set to "D". See: https://github.com/gnu-octave/octave/pull/22
author Jörg Sommrey <git@sommrey.de>
date Tue, 13 Feb 2024 11:50:03 +0100
parents f034172cb600
children 46fc602f334c 4239095e41c1
files libinterp/dldfcn/__glpk__.cc scripts/optimization/glpk.m
diffstat 2 files changed, 17 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/dldfcn/__glpk__.cc	Tue Feb 13 13:54:04 2024 -0500
+++ b/libinterp/dldfcn/__glpk__.cc	Tue Feb 13 11:50:03 2024 +0100
@@ -167,7 +167,7 @@
           break;
         }
 
-      glp_set_row_bnds (lp, i+1, typx, b[i], b[i]);
+      glp_set_row_bnds (lp, i+1, typx, typx == GLP_DB ? -b[i] : b[i], b[i]);
 
     }
 
--- a/scripts/optimization/glpk.m	Tue Feb 13 13:54:04 2024 -0500
+++ b/scripts/optimization/glpk.m	Tue Feb 13 11:50:03 2024 +0100
@@ -652,6 +652,22 @@
 %!   assert (A(i,:) * xmin <= b(i));
 %! endfor
 
+%!testif HAVE_GLPK
+%! sense = 1;
+%! c = [-1, -1]';
+%! A = [1, 0; 0, 1];
+%! b = [1, 1]';
+%! ctype = ['D', 'D']';
+%! lb = [-1, -1]';
+%! ub = [];
+%! vartype = ['I', 'I']';
+%! param.msglev = 0;
+%! [xmin, fmin, errnum, extra] = glpk (c, A, b, lb, ub, ctype, vartype, ...
+%!   sense, param);
+%! assert (fmin, c' * xmin);
+%! for i = 1:2
+%!   assert (A(i,:) * xmin <= b(i));
+%! endfor
 
 %!testif HAVE_GLPK
 %! sense = 1;