From f0d77d4ea75aac9369d32e899b4ac67dc8cc1e8c Mon Sep 17 00:00:00 2001 From: stevenj Date: Tue, 6 Jul 2010 15:51:54 -0400 Subject: [PATCH] fix mma mconstraints darcs-hash:20100706195154-c8de0-126475272c5018ef183651a9a52582e6f83629c5.gz --- api/optimize.c | 3 ++- mma/mma.c | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/api/optimize.c b/api/optimize.c index 92e0797..52f4433 100644 --- a/api/optimize.c +++ b/api/optimize.c @@ -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)); diff --git a/mma/mma.c b/mma/mma.c index 7d55335..f9fa5f2 100644 --- 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; -- 2.30.2