From: stevenj Date: Mon, 12 Jul 2010 22:30:58 +0000 (-0400) Subject: print out which bound was violated for bounds violation X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=ab013156e577db1ff93c36e4e64cfd8027ad74d2;p=nlopt.git print out which bound was violated for bounds violation darcs-hash:20100712223058-c8de0-28424889fa63e686e5377c0625b0891bc2446b84.gz --- diff --git a/test/testopt.cpp b/test/testopt.cpp index 2319ea1..b1fed82 100644 --- a/test/testopt.cpp +++ b/test/testopt.cpp @@ -78,11 +78,20 @@ static double bounds_wrap_func(int n, const double *x, double *grad, void *d_) { bounds_wrap_data *d = (bounds_wrap_data *) d_; int i; - for (i = 0; i < n; ++i) - if (x[i] < d->lb[i] || x[i] > d->ub[i]) + double b = 0; + for (i = 0; i < n; ++i) { + if (x[i] < d->lb[i]) { + b = d->lb[i]; + break; + } + else if (x[i] > d->ub[i]) { + b = d->ub[i]; break; + } + } if (i < n) - fprintf(stderr, "WARNING: bounds violated by x[%d] = %g\n", i, x[i]); + fprintf(stderr, "WARNING: bounds violated by x[%d] = %g = %g + %g\n", + i, x[i], b, x[i] - b); return d->f(n, x, grad, d->f_data); }