From 1e302cd9fc75fcbc20f3037201389cafbc53e5f2 Mon Sep 17 00:00:00 2001 From: stevenj Date: Sat, 12 Feb 2011 20:58:59 -0500 Subject: [PATCH] -b option to fix some params by equating the bounds darcs-hash:20110213015859-c8de0-c548cf8cac5f028a05601f2da9c2f34f8c0acc86.gz --- test/testopt.cpp | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/test/testopt.cpp b/test/testopt.cpp index 1079935..124798f 100644 --- a/test/testopt.cpp +++ b/test/testopt.cpp @@ -51,6 +51,16 @@ static int maxeval = 1000, iterations = 1, center_start = 0; static double maxtime = 0.0; static double xinit_tol = -1; static int force_constraints = 0; +static int fix_bounds[100] = {0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0}; static void listalgs(FILE *f) { @@ -137,6 +147,11 @@ static int test_function(int ifunc) printf("]\n"); memcpy(lb, func.lb, func.n * sizeof(double)); memcpy(ub, func.ub, func.n * sizeof(double)); + for (i = 0; i < func.n; ++i) if (fix_bounds[i]) { + printf("fixing bounds for dim[%d] to xmin[%d]=%g\n", + i, i, func.xmin[i]); + lb[i] = ub[i] = func.xmin[i]; + } if (force_constraints) { for (i = 0; i < func.n; ++i) { if (nlopt_iurand(2) == 0) @@ -258,6 +273,7 @@ static void usage(FILE *f) " -a : use optimization algorithm \n" " -o : use objective function \n" " -0 : starting guess within + (1+) * optimum\n" + " -b : eliminate given dims by equating bounds\n" " -c : starting guess at center of cell\n" " -C : put optimum outside of bound constraints\n" " -e : use at most evals (default: %d, 0 to disable)\n" @@ -286,7 +302,7 @@ int main(int argc, char **argv) feenableexcept(FE_INVALID); #endif - while ((c = getopt(argc, argv, "hLvCc0:r:a:o:i:e:t:x:X:f:F:m:")) != -1) + while ((c = getopt(argc, argv, "hLvCc0:r:a:o:i:e:t:x:X:f:F:m:b:")) != -1) switch (c) { case 'h': usage(stdout); @@ -348,6 +364,19 @@ int main(int argc, char **argv) center_start = 0; xinit_tol = atof(optarg); break; + case 'b': { + const char *s = optarg; + while (s && *s) { + int b = atoi(s); + if (b < 0 || b >= 100) { + fprintf(stderr, "invalid -b argument"); + return EXIT_FAILURE; + } + fix_bounds[b] = 1; + s = strchr(s, ','); if (s) ++s; + } + break; + } default: fprintf(stderr, "harminv: invalid argument -%c\n", c); usage(stderr); -- 2.30.2