chiark / gitweb /
Use trusty
[nlopt.git] / cdirect / cdirect.c
index f61df07f6f370946200f4fe742f85be80aa888ac..165f8e8dff24dcf20596ee70828549dd7a428023 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
@@ -142,7 +142,7 @@ static double function_eval(const double *x, params *p) {
      p->stop->nevals++;
      return f;
 }
-#define FUNCTION_EVAL(fv,x,p,freeonerr) fv = function_eval(x, p); if (p->minf < p->stop->minf_max) { free(freeonerr); return NLOPT_MINF_MAX_REACHED; } else if (nlopt_stop_evals((p)->stop)) { free(freeonerr); return NLOPT_MAXEVAL_REACHED; } else if (nlopt_stop_time((p)->stop)) { free(freeonerr); return NLOPT_MAXTIME_REACHED; }
+#define FUNCTION_EVAL(fv,x,p,freeonerr) fv = function_eval(x, p); if (nlopt_stop_forced((p)->stop)) { free(freeonerr); return NLOPT_FORCED_STOP; } else if (p->minf < p->stop->minf_max) { free(freeonerr); return NLOPT_MINF_MAX_REACHED; } else if (nlopt_stop_evals((p)->stop)) { free(freeonerr); return NLOPT_MAXEVAL_REACHED; } else if (nlopt_stop_time((p)->stop)) { free(freeonerr); return NLOPT_MAXTIME_REACHED; }
 
 #define THIRD (0.3333333333333333333333)
 
@@ -152,7 +152,7 @@ static double function_eval(const double *x, params *p) {
 static nlopt_result divide_rect(double *rdiv, params *p)
 {
      int i;
-     const const int n = p->n;
+     const int n = p->n;
      const int L = p->L;
      double *c = rdiv + 3; /* center of rect to divide */
      double *w = c + n; /* widths of rect to divide */
@@ -408,13 +408,13 @@ static nlopt_result divide_good_rects(params *p)
          int im, ip;
 
          /* find unequal points before (im) and after (ip) to get slope */
-         for (im = i-1; im >= 0 && hull[im][0] == hull[i][0]; --im);
-         for (ip = i+1; ip < nhull && hull[ip][0] == hull[i][0]; ++ip);
+         for (im = i-1; im >= 0 && hull[im][0] == hull[i][0]; --im) ;
+         for (ip = i+1; ip < nhull && hull[ip][0] == hull[i][0]; ++ip) ;
 
          if (im >= 0)
               K1 = (hull[i][1] - hull[im][1]) / (hull[i][0] - hull[im][0]);
          if (ip < nhull)
-              K1 = (hull[i][1] - hull[ip][1]) / (hull[i][0] - hull[ip][0]);
+              K2 = (hull[i][1] - hull[ip][1]) / (hull[i][0] - hull[ip][0]);
          K = MAX(K1, K2);
          if (hull[i][1] - K * hull[i][0]
              <= p->minf - magic_eps * fabs(p->minf) || ip == nhull) {
@@ -552,11 +552,11 @@ nlopt_result cdirect_unscaled(int n, nlopt_func f, void *f_data,
    coordinates to a unit hypercube ... we do this simply by
    wrapping cdirect() around cdirect_unscaled(). */
 
-double cdirect_uf(int n, const double *xu, double *grad, void *d_)
+double cdirect_uf(unsigned n, const double *xu, double *grad, void *d_)
 {
      cdirect_uf_data *d = (cdirect_uf_data *) d_;
      double f;
-     int i;
+     unsigned i;
      for (i = 0; i < n; ++i)
          d->x[i] = d->lb[i] + xu[i] * (d->ub[i] - d->lb[i]);
      f = d->f(n, d->x, grad, d->f_data);