chiark / gitweb /
use NLopt stop criteria in Luksan code: in particular, absolute tolerances were missi...
authorstevenj <stevenj@alum.mit.edu>
Tue, 9 Feb 2010 22:47:41 +0000 (17:47 -0500)
committerstevenj <stevenj@alum.mit.edu>
Tue, 9 Feb 2010 22:47:41 +0000 (17:47 -0500)
darcs-hash:20100209224741-c8de0-3df6ca15549dfe15027bc582948587adbcaa3b29.gz

TODO
luksan/luksan.h
luksan/plip.c
luksan/plis.c
luksan/pnet.c
luksan/pssubs.c
util/nlopt-util.h
util/stop.c

diff --git a/TODO b/TODO
index ff8e01ce07f3d88bf23de51be23e8799a89b52c4..1ec38fc8f96170617c3805082ea440cfb25ba3ea 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,6 +1,3 @@
-Modify luksan code (e.g. luksan/plis.c) to use full NLopt stopping
-criteria, and in particular the absolute tolerances and maxtime.
-
 Python interface.
 
 SLSQP routine from scipy.
index 94ce69e52444919a38b7fe455521104966e36528..9e375577a71e7527b1d3d4754fc9824099145e75 100644 (file)
@@ -98,10 +98,10 @@ void luksan_pulvp3__(int *n, int *m, double *xm,
 void luksan_pyadc0__(int *nf, int *n, double *x, 
                     int *ix, double *xl, double *xu, int *inew);
 void luksan_pyfut1__(int *n, double *f, double *
-                    fo, double *umax, double *gmax, double *dmax__, 
-                    double *tolx, double *tolf, double *tolb, double *
-                    tolg, int *kd, int *nit, int *kit, int *mit, int *
-                    nfv, int *mfv, int *nfg, int *mfg, int *ntesx, 
+                    fo, double *umax, double *gmax,
+                    int xstop, const nlopt_stopping *stop,
+                    double *tolg, int *kd, int *nit, int *kit, int *mit,
+                    int *nfg, int *mfg, int *ntesx, 
                     int *mtesx, int *ntesf, int *mtesf, int *ites, 
                     int *ires1, int *ires2, int *irest, int *iters, 
                     int *iterm);
index c6109ace79ddc791a4698f5db93aef98dd302b86..7d1e254274759b2ed3b59f5930f44221ec519f5f 100644 (file)
@@ -141,6 +141,7 @@ static void plip_(int *nf, int *nb, double *x, int *
     double eps8, eps9;
     int meta, mred, nred, iold;
     double maxf, dmax__;
+    int xstop = 0;
     int inew;
     double told;
     int ites;
@@ -282,8 +283,8 @@ static void plip_(int *nf, int *nb, double *x, int *
     ++stat_1->nfg;
 L11120:
     luksan_pytrcg__(nf, nf, &ix[1], &gf[1], &umax, gmax, &kbf, &iold);
-    luksan_pyfut1__(nf, f, &fo, &umax, gmax, &dmax__, tolx, tolf, tolb, tolg, 
-           &kd, &stat_1->nit, &kit, mit, &stop->nevals, mfv, &stat_1->nfg, &mfg, 
+    luksan_pyfut1__(nf, f, &fo, &umax, gmax, xstop, stop, tolg, 
+           &kd, &stat_1->nit, &kit, mit, &stat_1->nfg, &mfg, 
            &ntesx, &mtesx, &ntesf, &mtesf, &ites, &ires1, &ires2, &irest, &
            iters, iterm);
     if (*iterm != 0) {
@@ -399,6 +400,7 @@ L11174:
     luksan_mxuneg__(nf, &go[1], &s[1], &ix[1], &kbf);
     luksan_pytrcd__(nf, &x[1], &ix[1], &xo[1], &gf[1], &go[1], &r__, f, &fo, &
            p, &po, &dmax__, &kbf, &kd, &ld, &iters);
+    xstop = nlopt_stop_dx(stop, &x[1], &xo[1]);
     luksan_mxucop__(nf, &gf[1], &so[1], &ix[1], &kbf);
     if (nn < *mf) {
        luksan_pulsp3__(nf, &nn, mf, &xm[1], &gr[1], &xo[1], &go[1], &r__, &
index 3c6b71ad1b67c7a47834cb2ae1d0e0b375462f47..e9ef510b08dc2dd942f3fffab61ae9faad372c0f 100644 (file)
@@ -132,6 +132,7 @@ static void plis_(int *nf, int *nb, double *x, int *
     double eps8, eps9;
     int mred, iold, nred;
     double maxf, dmax__;
+    int xstop = 0;
     int inew;
     double told;
     int ites;
@@ -264,8 +265,8 @@ static void plis_(int *nf, int *nb, double *x, int *
     ++stat_1->nfg;
 L11120:
     luksan_pytrcg__(nf, nf, &ix[1], &gf[1], &umax, gmax, &kbf, &iold);
-    luksan_pyfut1__(nf, f, &fo, &umax, gmax, &dmax__, tolx, tolf, tolb, tolg, 
-           &kd, &stat_1->nit, &kit, mit, &stop->nevals, mfv, &stat_1->nfg, &mfg, 
+    luksan_pyfut1__(nf, f, &fo, &umax, gmax, xstop, stop, tolg, 
+           &kd, &stat_1->nit, &kit, mit, &stat_1->nfg, &mfg, 
            &ntesx, &mtesx, &ntesf, &mtesf, &ites, &ires1, &ires2, &irest, &
            iters, iterm);
     if (*iterm != 0) {
@@ -405,6 +406,7 @@ L11174:
     }
     luksan_pytrcd__(nf, &x[1], &ix[1], &xo[1], &gf[1], &go[1], &r__, f, &fo, &
            p, &po, &dmax__, &kbf, &kd, &ld, &iters);
+    xstop = nlopt_stop_dx(stop, &x[1], &xo[1]);
 L11175:
     if (kbf > 0) {
        luksan_mxvine__(nf, &ix[1]);
index 012dc6e9c35aaf8ed1be9ffaa37ac0307d6df4a7..c563c96d165e8151f0de8570df9e4649d7e2563b 100644 (file)
@@ -160,6 +160,7 @@ static void pnet_(int *nf, int *nb, double *x, int *
     double rho1, rho2, eps8, eps9;
     int mred, iold, nred;
     double maxf, dmax__;
+    int xstop = 0;
     int inew;
     double told;
     int ites;
@@ -304,8 +305,8 @@ static void pnet_(int *nf, int *nb, double *x, int *
 L11020:
     luksan_pytrcg__(nf, nf, &ix[1], &gf[1], &umax, gmax, &kbf, &iold);
     luksan_mxvcop__(nf, &gf[1], &gn[1]);
-    luksan_pyfut1__(nf, f, &fo, &umax, gmax, &dmax__, tolx, tolf, tolb, tolg, 
-           &kd, &stat_1->nit, &kit, mit, &stop->nevals, mfv, &stat_1->nfg, mfg, &
+    luksan_pyfut1__(nf, f, &fo, &umax, gmax, xstop, stop, tolg, 
+           &kd, &stat_1->nit, &kit, mit, &stat_1->nfg, mfg, &
            ntesx, &mtesx, &ntesf, &mtesf, &ites, &ires1, &ires2, &irest, &
            iters, iterm);
     if (*iterm != 0) {
@@ -540,6 +541,7 @@ L11064:
     }
     luksan_pytrcd__(nf, &x[1], &ix[1], &xo[1], &gf[1], &go[1], &r__, f, &fo, &
            p, &po, &dmax__, &kbf, &kd, &ld, &iters);
+    xstop = nlopt_stop_dx(stop, &x[1], &xo[1]);
     if (*mos2 > 1) {
 /* Computing MIN */
        i__1 = mx + 1;
index c6ae5b4ca83b46988b07aee5b2bd97879acf9406..2096c198bd963fcee2b525e7caa8ea8ee7a8259e 100644 (file)
@@ -866,11 +866,11 @@ void luksan_pyadc0__(int *nf, int *n, double *x,
 *         ITERATIONS. ITERM=12-TERMINATION AFTER MAXIMUM NUMBER OF
 *         COMPUTED FUNCTION VALUES.
 */
-void luksan_pyfut1__(int *n, double *f, double *
-       fo, double *umax, double *gmax, double *dmax__, 
-       double *tolx, double *tolf, double *tolb, double *
-       tolg, int *kd, int *nit, int *kit, int *mit, int *
-       nfv, int *mfv, int *nfg, int *mfg, int *ntesx, 
+void luksan_pyfut1__(int *n, double *f, double *fo, double *umax, 
+                    double *gmax, int xstop, /* double *dmax__,  */
+                    const nlopt_stopping *stop,
+                    double *tolg, int *kd, int *nit, int *kit, int *mit, 
+                    int *nfg, int *mfg, int *ntesx, 
        int *mtesx, int *ntesf, int *mtesf, int *ites, 
        int *ires1, int *ires2, int *irest, int *iters, 
        int *iterm)
@@ -880,9 +880,6 @@ void luksan_pyfut1__(int *n, double *f, double *
 
     /* Builtin functions */
 
-    /* Local variables */
-    double temp;
-
     if (*iterm < 0) {
        return;
     }
@@ -897,7 +894,7 @@ void luksan_pyfut1__(int *n, double *f, double *
        d__1 = sqrt((fabs(*f))), d__2 = fabs(*f) / 10.;
        *fo = *f + min(d__1,d__2);
     }
-    if (*f <= *tolb) {
+    if (*f <= stop->minf_max /* *tolb */) {
        *iterm = 3;
        return;
     }
@@ -911,7 +908,7 @@ void luksan_pyfut1__(int *n, double *f, double *
        *ntesx = 0;
        *ntesf = 0;
     }
-    if (*dmax__ <= *tolx) {
+    if (xstop) /* (*dmax__ <= *tolx) */ {
        *iterm = 1;
        ++(*ntesx);
        if (*ntesx >= *mtesx) {
@@ -920,10 +917,7 @@ void luksan_pyfut1__(int *n, double *f, double *
     } else {
        *ntesx = 0;
     }
-/* Computing MAX */
-    d__2 = fabs(*f);
-    temp = (d__1 = *fo - *f, fabs(d__1)) / max(d__2,1.);
-    if (temp <= *tolf) {
+    if (nlopt_stop_ftol(stop, *f, *fo)) {
        *iterm = 2;
        ++(*ntesf);
        if (*ntesf >= *mtesf) {
@@ -937,7 +931,7 @@ L1:
        *iterm = 11;
        return;
     }
-    if (*nfv >= *mfv) {
+    if (nlopt_stop_evals(stop)) /* (*nfv >= *mfv) */ {
        *iterm = 12;
        return;
     }
index 861914df353e1c47ac1e1301014d38b24a9189aa..a6b9744d3c6982cf9da340f6f2c97fe15e2993da 100644 (file)
@@ -79,6 +79,8 @@ extern int nlopt_stop_f(const nlopt_stopping *stop, double f, double oldf);
 extern int nlopt_stop_ftol(const nlopt_stopping *stop, double f, double oldf);
 extern int nlopt_stop_x(const nlopt_stopping *stop, 
                        const double *x, const double *oldx);
+extern int nlopt_stop_dx(const nlopt_stopping *stop, 
+                        const double *x, const double *dx);
 extern int nlopt_stop_xs(const nlopt_stopping *stop, 
                         const double *xs, const double *oldxs,
                         const double *scale_min, const double *scale_max);
index 534b76ce81fb2c9e2fb21550e490dc709986d4f4..17ddbf59671b076c0a0baa051106cb398557b56a 100644 (file)
@@ -52,6 +52,15 @@ int nlopt_stop_x(const nlopt_stopping *s, const double *x, const double *oldx)
      return 1;
 }
 
+int nlopt_stop_dx(const nlopt_stopping *s, const double *x, const double *dx)
+{
+     int i;
+     for (i = 0; i < s->n; ++i)
+         if (!relstop(x[i] - dx[i], x[i], s->xtol_rel, s->xtol_abs[i]))
+              return 0;
+     return 1;
+}
+
 static double sc(double x, double smin, double smax)
 {
      return smin + x * (smax - smin);