chiark / gitweb /
skeleton of future equality-constraint support
authorstevenj <stevenj@alum.mit.edu>
Tue, 25 Nov 2008 19:37:07 +0000 (14:37 -0500)
committerstevenj <stevenj@alum.mit.edu>
Tue, 25 Nov 2008 19:37:07 +0000 (14:37 -0500)
darcs-hash:20081125193707-c8de0-5a57e367a994ab4bd65f667197312bfd4e8c0a02.gz

api/nlopt.c
api/nlopt.h

index 056165f95bbdf6aaf25d1f369977b1b381addf76..28fd621da03a44f7393fe8d6140715f644ae937e 100644 (file)
@@ -252,11 +252,13 @@ void nlopt_set_local_search_algorithm(nlopt_algorithm deriv,
 
 /*************************************************************************/
 
-/* same as nlopt_minimize, but xtol_abs is required to be non-NULL */
+/* same as nlopt_minimize_econstrained, 
+   but xtol_abs is required to be non-NULL */
 static nlopt_result nlopt_minimize_(
      nlopt_algorithm algorithm,
      int n, nlopt_func f, void *f_data,
      int m, nlopt_func fc, void *fc_data, ptrdiff_t fc_datum_size,
+     int p, nlopt_func h, void *h_data, ptrdiff_t h_datum_size,
      const double *lb, const double *ub, /* bounds */
      double *x, /* in: initial guess, out: minimizer */
      double *minf, /* out: minimum */
@@ -269,7 +271,7 @@ static nlopt_result nlopt_minimize_(
      nlopt_stopping stop;
 
      /* some basic argument checks */
-     if (!minf || !f || n < 0 || m < 0
+     if (!minf || !f || n < 0 || m < 0 || p < 0 || (p > 0 && !h)
          || (m > 0 && !fc)) return NLOPT_INVALID_ARGS;
      if (n == 0) { /* trivial case: no degrees of freedom */
          *minf = f(n, x, NULL, f_data);
@@ -282,6 +284,10 @@ static nlopt_result nlopt_minimize_(
      if (m != 0 && algorithm != NLOPT_LD_MMA && algorithm != NLOPT_LN_COBYLA) 
          return NLOPT_INVALID_ARGS;
 
+     /* nonlinear equality constraints (h(x) = 0) not yet supported */
+     if (p != 0)
+         return NLOPT_INVALID_ARGS;
+
      d.f = f;
      d.f_data = f_data;
      d.lb = lb;
@@ -515,10 +521,11 @@ static nlopt_result nlopt_minimize_(
      return NLOPT_SUCCESS;
 }
 
-nlopt_result nlopt_minimize_constrained(
+nlopt_result nlopt_minimize_econstrained(
      nlopt_algorithm algorithm,
      int n, nlopt_func f, void *f_data,
      int m, nlopt_func fc, void *fc_data, ptrdiff_t fc_datum_size,
+     int p, nlopt_func h, void *h_data, ptrdiff_t h_datum_size,
      const double *lb, const double *ub, /* bounds */
      double *x, /* in: initial guess, out: minimizer */
      double *minf, /* out: minimum */
@@ -529,7 +536,9 @@ nlopt_result nlopt_minimize_constrained(
      nlopt_result ret;
      if (xtol_abs)
          ret = nlopt_minimize_(algorithm, n, f, f_data,
-                               m, fc, fc_data, fc_datum_size, lb, ub,
+                               m, fc, fc_data, fc_datum_size, 
+                               p, h, h_data, h_datum_size,
+                               lb, ub,
                                x, minf, minf_max, ftol_rel, ftol_abs,
                                xtol_rel, xtol_abs, maxeval, maxtime);
      else {
@@ -538,7 +547,9 @@ nlopt_result nlopt_minimize_constrained(
          if (!xtol) return NLOPT_OUT_OF_MEMORY;
          for (i = 0; i < n; ++i) xtol[i] = -1;
          ret = nlopt_minimize_(algorithm, n, f, f_data, 
-                               m, fc, fc_data, fc_datum_size, lb, ub,
+                               m, fc, fc_data, fc_datum_size,
+                               p, h, h_data, h_datum_size,
+                               lb, ub,
                                x, minf, minf_max, ftol_rel, ftol_abs,
                                xtol_rel, xtol, maxeval, maxtime);
          free(xtol);
@@ -546,6 +557,24 @@ nlopt_result nlopt_minimize_constrained(
      return ret;
 }
 
+nlopt_result nlopt_minimize_constrained(
+     nlopt_algorithm algorithm,
+     int n, nlopt_func f, void *f_data,
+     int m, nlopt_func fc, void *fc_data, ptrdiff_t fc_datum_size,
+     const double *lb, const double *ub, /* bounds */
+     double *x, /* in: initial guess, out: minimizer */
+     double *minf, /* out: minimum */
+     double minf_max, double ftol_rel, double ftol_abs,
+     double xtol_rel, const double *xtol_abs,
+     int maxeval, double maxtime)
+{
+     return nlopt_minimize_econstrained(
+         algorithm, n, f, f_data, 
+         m, fc, fc_data, fc_datum_size, 0, NULL, NULL, 0,
+         lb, ub, x, minf, minf_max, ftol_rel, ftol_abs,
+         xtol_rel, xtol_abs, maxeval, maxtime);
+}
+
 nlopt_result nlopt_minimize(
      nlopt_algorithm algorithm,
      int n, nlopt_func f, void *f_data,
index 46670d6af09e3394d7a8c8ca524e3a981d310498..e2362be2dad202f7b9c7e1433df7fd44e952dd93 100644 (file)
@@ -130,6 +130,18 @@ extern nlopt_result nlopt_minimize_constrained(
      double xtol_rel, const double *xtol_abs,
      int maxeval, double maxtime);
 
+extern nlopt_result nlopt_minimize_econstrained(
+     nlopt_algorithm algorithm,
+     int n, nlopt_func f, void *f_data,
+     int m, nlopt_func fc, void *fc_data, ptrdiff_t fc_datum_size,
+     int p, nlopt_func h, void *h_data, ptrdiff_t h_datum_size,
+     const double *lb, const double *ub, /* bounds */
+     double *x, /* in: initial guess, out: minimizer */
+     double *minf, /* out: minimum */
+     double minf_max, double ftol_rel, double ftol_abs,
+     double xtol_rel, const double *xtol_abs,
+     int maxeval, double maxtime);
+
 extern void nlopt_srand(unsigned long seed);
 extern void nlopt_srand_time(void);