From: stevenj Date: Thu, 27 Nov 2008 20:37:09 +0000 (-0500) Subject: added test function with minimum at side (i.e. one active bound constraint), which... X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=f2ca7ead4674b2672fd798be6fc9a15ee60dcc7c;p=nlopt.git added test function with minimum at side (i.e. one active bound constraint), which is more challenging than the corner case darcs-hash:20081127203709-c8de0-248be9ce8ebbedc63edea548940c330579979276.gz --- diff --git a/test/testfuncs.c b/test/testfuncs.c index bbe75e9..e589d82 100644 --- a/test/testfuncs.c +++ b/test/testfuncs.c @@ -390,6 +390,48 @@ static const double corner4d_lb[4] = {0,0,0,0}; static const double corner4d_ub[4] = {1,1,1,1}; static const double corner4d_xmin[4] = {0,0,0,0}; +/****************************************************************************/ +static double side4d_f(int n, const double *x, double *grad, void *data) +{ + UNUSED(data); + UNUSED(n); + double x0, x1, x2, x3, d0,d1,d2,d3; + const double w0 = 0.1, w1 = 0.2, w2 = 0.3, w3 = 0.4; + x0 = +0.4977 * x[0] - 0.3153 * x[1] - 0.5066 * x[2] - 0.4391 * x[3]; + x1 = -0.3153 * x[0] + 0.3248 * x[1] - 0.4382 * x[2] - 0.4096 * x[3]; + x2 = -0.5066 * x[0] - 0.4382 * x[1] + 0.3807 * x[2] - 0.4543 * x[3]; + x3 = -0.4391 * x[0] - 0.4096 * x[1] - 0.4543 * x[2] + 0.5667 * x[3]; + + d0 = -1. / (x0*x0 + w0*w0); + d1 = -1. / (x1*x1 + w1*w1); + d2 = -1. / (x2*x2 + w2*w2); + d3 = -1. / (x3*x3 + w3*w3); + + if (grad) { + grad[0] = 2 * (x0*d0*d0 * +0.4977 + + x1*d1*d1 * -0.3153 + + x2*d2*d2 * -0.5066 + + x3*d3*d3 * -0.4391); + grad[1] = 2 * (x0*d0*d0 * -0.3153 + + x1*d1*d1 * +0.3248 + + x2*d2*d2 * -0.4382 + + x3*d3*d3 * -0.4096); + grad[2] = 2 * (x0*d0*d0 * -0.5066 + + x1*d1*d1 * -0.4382 + + x2*d2*d2 * +0.3807 + + x3*d3*d3 * -0.4543); + grad[3] = 2 * (x0*d0*d0 * -0.4391 + + x1*d1*d1 * -0.4096 + + x2*d2*d2 * -0.4543 + + x3*d3*d3 * +0.5667); + } + RETURN(d0 + d1 + d2 + d3); +} + +static const double side4d_lb[4] = {0.1,-1,-1,-1}; +static const double side4d_ub[4] = {1,1,1,1}; +static const double side4d_xmin[4] = {0.1,0.102971169,0.0760520641,-0.0497098571}; + /****************************************************************************/ /****************************************************************************/ @@ -456,5 +498,8 @@ const testfunc testfuncs[NTESTFUNCS] = { -1.0, "1d oscillating function with a single minimum" }, { corner4d_f, NULL, 1, 4, corner4d_lb, corner4d_ub, corner4d_xmin, - 1.0, "4d function with minimum at corner" } + 1.0, "4d function with minimum at corner" }, + { side4d_f, NULL, 1, 4, + side4d_lb, side4d_ub, side4d_xmin, + -141.285020472, "4d function with minimum at side" } }; diff --git a/test/testfuncs.h b/test/testfuncs.h index b20ea88..328d2e3 100644 --- a/test/testfuncs.h +++ b/test/testfuncs.h @@ -18,7 +18,7 @@ typedef struct { const char *name; } testfunc; -#define NTESTFUNCS 21 +#define NTESTFUNCS 22 extern const testfunc testfuncs[NTESTFUNCS]; extern int testfuncs_verbose; diff --git a/test/testopt.cpp b/test/testopt.cpp index 3ea4050..7c5c435 100644 --- a/test/testopt.cpp +++ b/test/testopt.cpp @@ -149,7 +149,7 @@ static int test_function(int ifunc) f0 = func.f(func.n, x, x + func.n, func.f_data); printf("Starting function value = %g\n", f0); - if (iter > 0 && testfuncs_verbose && func.has_gradient) { + if (iter == 0 && testfuncs_verbose && func.has_gradient) { printf("checking gradient:\n"); for (i = 0; i < func.n; ++i) { double f;