From 730b3672b30c07bc3cfa3887fb896d95aeeb86eb Mon Sep 17 00:00:00 2001 From: stevenj Date: Mon, 10 Nov 2008 23:50:39 -0500 Subject: [PATCH] fixes in octave/matlab wrappers darcs-hash:20081111045039-c8de0-8f6ef260280dad83f9fad6f89f4392e681c1e22e.gz --- octave/nlopt_minimize.m | 6 +++--- octave/nlopt_minimize_constrained-oct.cc | 27 ++++++++++++++---------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/octave/nlopt_minimize.m b/octave/nlopt_minimize.m index 5dc64e1..4c23429 100644 --- a/octave/nlopt_minimize.m +++ b/octave/nlopt_minimize.m @@ -64,7 +64,7 @@ % % For more information on individual functions, see their individual % help pages (e.g. "help NLOPT_LN_SUBPLEX"). -[xopt, fmin, retcode] = nlopt_minimize(algorithm, f, f_data, lb, ub, xinit, stop) - +function [xopt, fmin, retcode] = nlopt_minimize(algorithm, f, f_data, lb, ub, xinit, stop) + [xopt, fmin, retcode] = nlopt_minimize_constrained(algorithm, f, f_data, {}, {}, lb, ub, xinit, stop); - + diff --git a/octave/nlopt_minimize_constrained-oct.cc b/octave/nlopt_minimize_constrained-oct.cc index ba75c7a..58b87c6 100644 --- a/octave/nlopt_minimize_constrained-oct.cc +++ b/octave/nlopt_minimize_constrained-oct.cc @@ -119,17 +119,15 @@ DEFUN_DLD(nlopt_minimize_constrained, args, nargout, NLOPT_MINIMIZE_CONSTRAINED_ CHECK(args(4).is_cell(), "fc_data must be cell array"); int m = args(3).length(); CHECK(m == args(4).length(), "fc and fc_data must have the same length"); - user_function_data *dc = new user_function_data[m]; - { - Cell fc = args(3).cell_value(); - Cell fc_data = args(4).cell_value(); - for (int i; i < m; ++i) { - CHECK(fc(i).is_function() || fc(i).is_function_handle(), - "fc must be a cell array of function handles"); - dc[i].f = fc(i).function_value(); - CHECK(fc_data(i).is_cell(), "fc_data must be cell array of cell arrays"); - dc[i].f_data = fc_data(i).cell_value(); - } + user_function_data *dc = new user_function_data[m+1]; + Cell fc = args(3).cell_value(); + Cell fc_data = args(4).cell_value(); + for (int i = 0; i < m; ++i) { + CHECK(fc(i).is_function() || fc(i).is_function_handle(), + "fc must be a cell array of function handles"); + dc[i].f = fc(i).function_value(); + CHECK(fc_data(i).is_cell(), "fc_data must be cell array of cell arrays"); + dc[i].f_data = fc_data(i).cell_value(); } CHECK(args(5).is_real_matrix() || args(5).is_real_scalar(), @@ -161,6 +159,13 @@ DEFUN_DLD(nlopt_minimize_constrained, args, nargout, NLOPT_MINIMIZE_CONSTRAINED_ CHECK(n == xtol_abs.length(), "stop.xtol_abs must have same length as x"); int maxeval = int(struct_val_default(stop, "maxeval", -1)); double maxtime = struct_val_default(stop, "maxtime", -1); + + d.neval = 0; + d.verbose = (int) struct_val_default(stop, "verbose", 0); + for (int i = 0; i < m; ++i) { + dc[i].neval = 0; + dc[i].verbose = d.verbose > 1; + } double minf = HUGE_VAL; nlopt_result ret = nlopt_minimize_constrained(algorithm, -- 2.30.2