chiark / gitweb /
fix mma mconstraints
authorstevenj <stevenj@alum.mit.edu>
Tue, 6 Jul 2010 19:51:54 +0000 (15:51 -0400)
committerstevenj <stevenj@alum.mit.edu>
Tue, 6 Jul 2010 19:51:54 +0000 (15:51 -0400)
darcs-hash:20100706195154-c8de0-126475272c5018ef183651a9a52582e6f83629c5.gz

api/optimize.c
mma/mma.c

index 92e079717cdf48fd38979f822dcd5496f7878946..52f443345f11ade43ec7ef9b257ca1225b0e0b76 100644 (file)
@@ -415,7 +415,8 @@ static nlopt_result nlopt_optimize_(nlopt_opt opt, double *x, double *minf)
 #define LO(param, def) (opt->local_opt ? opt->local_opt->param : (def))
              dual_opt = nlopt_create(LO(algorithm,
                                         nlopt_local_search_alg_deriv),
-                                     opt->m);
+                                     nlopt_count_constraints(opt->m,
+                                                             opt->fc));
              if (!dual_opt) return NLOPT_FAILURE;
              nlopt_set_ftol_rel(dual_opt, LO(ftol_rel, 1e-12));
              nlopt_set_ftol_abs(dual_opt, LO(ftol_abs, 0.0));
index 7d55335aade890f984bb1aaa92aa213336a99f25..f9fa5f2d4b47f19f5379506967d5550a204fe9dc 100644 (file)
--- a/mma/mma.c
+++ b/mma/mma.c
@@ -164,6 +164,7 @@ nlopt_result mma_minimize(unsigned n, nlopt_func f, void *f_data,
      unsigned mfc;
 
      m = nlopt_count_constraints(mfc = m, fc);
+     if (nlopt_get_dimension(dual_opt) != m) return NLOPT_INVALID_ARGS;
      sigma = (double *) malloc(sizeof(double) * (6*n + 2*m*n + m*7));
      if (!sigma) return NLOPT_OUT_OF_MEMORY;
      dfdx = sigma + n;
@@ -238,6 +239,8 @@ nlopt_result mma_minimize(unsigned n, nlopt_func f, void *f_data,
      nlopt_set_lower_bounds(dual_opt, dual_lb);
      nlopt_set_upper_bounds(dual_opt, dual_ub);
      nlopt_set_stopval(dual_opt, -HUGE_VAL);
+     nlopt_remove_inequality_constraints(dual_opt);
+     nlopt_remove_equality_constraints(dual_opt);
 
      while (1) { /* outer iterations */
          double fprev = fcur;
@@ -323,8 +326,10 @@ nlopt_result mma_minimize(unsigned n, nlopt_func f, void *f_data,
                       be violated slightly by rounding errors etc. so we
                       must be a little careful about checking feasibility */
                    if (infeasibility_cur == 0) {
-                        if (!feasible) /* reset upper bounds to infinity */
+                        if (!feasible) { /* reset upper bounds to infin. */
                              for (i = 0; i < m; ++i) dual_ub[i] = HUGE_VAL;
+                             nlopt_set_upper_bounds(dual_opt, dual_ub);
+                        }
                         feasible = 1;
                    }
                    else if (new_infeasible_constraint) feasible = 0;