From ab013156e577db1ff93c36e4e64cfd8027ad74d2 Mon Sep 17 00:00:00 2001 From: stevenj Date: Mon, 12 Jul 2010 18:30:58 -0400 Subject: [PATCH] print out which bound was violated for bounds violation darcs-hash:20100712223058-c8de0-28424889fa63e686e5377c0625b0891bc2446b84.gz --- test/testopt.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) 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); } -- 2.30.2