Skip to content

Commit

Permalink
support initial_step in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stevengj committed Aug 9, 2024
1 parent e5a069c commit 1c211cb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 4 additions & 0 deletions test/t_tutorial.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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<double> x(2);
x[0] = 1.234; x[1] = 5.678;
double minf;
Expand Down
9 changes: 8 additions & 1 deletion test/testopt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -290,6 +293,7 @@ static void usage(FILE * f)
" -a <n> : use optimization algorithm <n>\n"
" -o <n> : use objective function <n>\n"
" -0 <x> : starting guess within <x> + (1+<x>) * optimum\n"
" -S <dx>: initial step size dx (default: none)\n"
" -b <dim0,dim1,...>: eliminate given dims by equating bounds\n");
fprintf(f,
" -c : starting guess at center of cell\n"
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 1c211cb

Please sign in to comment.