From: <sla...@us...> - 2009-09-21 14:57:22
|
Revision: 6256 http://octave.svn.sourceforge.net/octave/?rev=6256&view=rev Author: slackydeb Date: 2009-09-21 14:57:12 +0000 (Mon, 21 Sep 2009) Log Message: ----------- linprog.m: compatibility fix (thanks to Adrian Burlacu for the report) * let empty A and/or b of whatever dimensions as user input, sanitizing them inside the function * add a test case for the above fix See also http://sourceforge.net/mailarchive/forum.php?thread_name=684314.52352.qm%40web110015.mail.gq1.yahoo.com&forum_name=octave-dev Bump package version. Modified Paths: -------------- trunk/octave-forge/main/optim/DESCRIPTION trunk/octave-forge/main/optim/inst/linprog.m Modified: trunk/octave-forge/main/optim/DESCRIPTION =================================================================== --- trunk/octave-forge/main/optim/DESCRIPTION 2009-09-20 12:04:30 UTC (rev 6255) +++ trunk/octave-forge/main/optim/DESCRIPTION 2009-09-21 14:57:12 UTC (rev 6256) @@ -1,6 +1,6 @@ Name: Optim -Version: 1.0.7 -Date: 2009-07-22 +Version: 1.0.8 +Date: 2009-09-21 Author: Various Authors Maintainer: The Octave Community Title: Optimzation. Modified: trunk/octave-forge/main/optim/inst/linprog.m =================================================================== --- trunk/octave-forge/main/optim/inst/linprog.m 2009-09-20 12:04:30 UTC (rev 6255) +++ trunk/octave-forge/main/optim/inst/linprog.m 2009-09-21 14:57:12 UTC (rev 6256) @@ -45,22 +45,28 @@ ## @end deftypefn ## Author: Luca Favatella <sla...@gm...> -## Version: 0.4 +## Version: 0.5 - # TODO: write a test using not null and - # not zero Aeq and beq - function [x fval] = linprog (f, A, b, Aeq = [], beq = [], lb = [], ub = []) + if (((nargin != 3) && (nargin != 5) && (nargin != 7)) || + (nargout > 2)) + print_usage (); + endif + nr_f = rows(f); + + # Sanitize A and b + if (isempty (A) && isempty (b)) + A = zeros (0, nr_f); + b = zeros (rows (A), 1); + endif + nr_A = rows (A); - if (((nargin != 3) && (nargin != 5) && (nargin != 7)) || - (nargout > 2)) - print_usage (); - elseif (columns (f) != 1) + if (columns (f) != 1) error ("f must be a column vector"); elseif (columns (A) != nr_f) error ("columns (A) != rows (f)"); @@ -112,6 +118,18 @@ endfunction +%!test +%! f = [1; -1]; +%! A = []; +%! b = []; +%! Aeq = [1, 0]; +%! beq = [2]; +%! lb = [0; Inf]; +%! ub = [-Inf; 0]; +%! x_exp = [2; 0]; +%! assert (linprog (f, A, b, Aeq, beq, lb, ub), x_exp); + + %!shared f, A, b, lb, ub, x_exp, fval_exp %! f = [21 25 31 34 23 19 32 36 27 25 19]'; %! @@ -143,4 +161,4 @@ %!test %! Aeq = zeros (1, rows (f)); %! beq = 0; -%! assert(linprog (f, A, b, Aeq, beq, lb, ub), x_exp); \ No newline at end of file +%! assert (linprog (f, A, b, Aeq, beq, lb, ub), x_exp); \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |