From 1c211cb9a3584d158bf19485dcad6d73b74ed1e8 Mon Sep 17 00:00:00 2001 From: "Steven G. Johnson" Date: Fri, 9 Aug 2024 11:53:19 -0400 Subject: [PATCH] support initial_step in tests --- test/t_tutorial.cxx | 4 ++++ test/testopt.c | 9 ++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/test/t_tutorial.cxx b/test/t_tutorial.cxx index 3594fc55..c49532e5 100644 --- a/test/t_tutorial.cxx +++ b/test/t_tutorial.cxx @@ -51,6 +51,10 @@ int main() { return EXIT_FAILURE; } + // set a couple of other parameters + opt.set_param("rho_init", 0.5); + opt.set_initial_step(0.1); + std::vector x(2); x[0] = 1.234; x[1] = 5.678; double minf; diff --git a/test/testopt.c b/test/testopt.c index 3e086493..07c098b9 100644 --- a/test/testopt.c +++ b/test/testopt.c @@ -49,6 +49,7 @@ extern "C" int feenableexcept(int EXCEPTS); static nlopt_algorithm algorithm = NLOPT_GN_DIRECT_L; static double ftol_rel = 0, ftol_abs = 0, xtol_rel = 0, xtol_abs = 0, minf_max_delta; +static double initial_step = 0; static int maxeval = 1000, iterations = 1, center_start = 0; static double maxtime = 0.0; static double xinit_tol = -1; @@ -235,6 +236,8 @@ static int test_function(int ifunc) nlopt_set_xtol_abs(opt, xtabs); nlopt_set_maxeval(opt, maxeval); nlopt_set_maxtime(opt, maxtime); + if (initial_step != 0) + nlopt_set_initial_step1(opt, initial_step); ret = nlopt_optimize(opt, x, &minf); printf("finished after %g seconds.\n", nlopt_seconds() - start); printf("return code %d from nlopt_minimize\n", ret); @@ -290,6 +293,7 @@ static void usage(FILE * f) " -a : use optimization algorithm \n" " -o : use objective function \n" " -0 : starting guess within + (1+) * optimum\n" + " -S : initial step size dx (default: none)\n" " -b : eliminate given dims by equating bounds\n"); fprintf(f, " -c : starting guess at center of cell\n" @@ -321,7 +325,7 @@ int main(int argc, char **argv) feenableexcept(FE_INVALID); #endif - while ((c = getopt(argc, argv, "hLvVCc0:r:a:o:i:e:t:x:X:f:F:m:b:")) != -1) + while ((c = getopt(argc, argv, "hLvVCc0:r:a:o:i:e:t:x:X:f:F:m:b:S:")) != -1) switch (c) { case 'h': usage(stdout); @@ -389,6 +393,9 @@ int main(int argc, char **argv) center_start = 0; xinit_tol = atof(optarg); break; + case 'S': + initial_step = atof(optarg); + break; case 'b':{ const char *s = optarg; while (s && *s) {