chiark / gitweb /
Use trusty
[nlopt.git] / neldermead / nldrmd.c
index 5091e334d27f38f05b2c23847febfd0e3cf67a3e..a8e7ee479b079560dc04587c1be3c4b0d2d634dc 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2007-2008 Massachusetts Institute of Technology
+/* Copyright (c) 2007-2014 Massachusetts Institute of Technology
  *
  * Permission is hereby granted, free of charge, to any person obtaining
  * a copy of this software and associated documentation files (the
@@ -78,6 +78,7 @@ static int reflectpt(int n, double *xnew,
 
 #define CHECK_EVAL(xc,fc)                                                \
  stop->nevals++;                                                         \
+ if (nlopt_stop_forced(stop)) { ret=NLOPT_FORCED_STOP; goto done; }        \
  if ((fc) <= *minf) {                                                    \
    *minf = (fc); memcpy(x, (xc), n * sizeof(double));                    \
    if (*minf < stop->minf_max) { ret=NLOPT_MINF_MAX_REACHED; goto done; } \
@@ -152,7 +153,12 @@ nlopt_result nldrmd_minimize_(int n, nlopt_func f, void *f_data,
                                           ub[i] : lb[i]) + x[i]);
               }
          }
-         if (close(pt[1+i], x[i])) { ret=NLOPT_FAILURE; goto done; }
+         if (close(pt[1+i], x[i])) { 
+              nlopt_stop_msg(stop, "starting step size led to simplex that was too small in dimension %d: %g is too close to x[%d]=%g",
+                             i, pt[1+i], i, x[i]);
+              ret=NLOPT_FAILURE;
+              goto done; 
+          }
          pt[0] = f(n, pt+1, NULL, f_data);
          CHECK_EVAL(pt+1, pt[0]);
      }
@@ -174,7 +180,7 @@ nlopt_result nldrmd_minimize_(int n, nlopt_func f, void *f_data,
          *fdiff = fh - fl;
 
          if (init_diam == 0) /* initialize diam. for psi convergence test */
-              for (i = 0; i < n; ++i) init_diam = fabs(xl[i] - xh[i]);
+              for (i = 0; i < n; ++i) init_diam += fabs(xl[i] - xh[i]);
 
          if (psi <= 0 && nlopt_stop_ftol(stop, fl, fh)) {
               ret = NLOPT_FTOL_REACHED;
@@ -290,6 +296,7 @@ nlopt_result nldrmd_minimize(int n, nlopt_func f, void *f_data,
 
      *minf = f(n, x, NULL, f_data);
      stop->nevals++;
+     if (nlopt_stop_forced(stop)) return NLOPT_FORCED_STOP;
      if (*minf < stop->minf_max) return NLOPT_MINF_MAX_REACHED;
      if (nlopt_stop_evals(stop)) return NLOPT_MAXEVAL_REACHED;
      if (nlopt_stop_time(stop)) return NLOPT_MAXTIME_REACHED;