.BI " double " "ub" );
.sp
.SH NONLINEAR CONSTRAINTS
-Several of the algorithms in NLopt (MMA, COBYLA, and ORIG_DIRECT) also
-support arbitrary nonlinear inequality constraints, and some also
-allow nonlinear equality constraints (ISRES and AUGLAG). For these
+Several of the algorithms in NLopt (MMA and ORIG_DIRECT) also support
+arbitrary nonlinear inequality constraints, and some also allow
+nonlinear equality constraints (COBYLA, ISRES, and AUGLAG). For these
algorithms, you can specify as many nonlinear constraints as you wish
by calling the following functions multiple times.
.sp
of Powell (Constrained Optimization BY Linear Approximations).
The
.B NLOPT_LN_COBYLA
-algorithm supports both bound-constrained and unconstrained optimization,
-and also supports an arbitrary number (\fIm\fR) of nonlinear constraints
-as described above.
+algorithm supports both bound-constrained and unconstrained
+optimization, and also supports an arbitrary number (\fIm\fR) of
+nonlinear inequality/equality constraints as described above.
.TP
.B NLOPT_LN_NEWUOA
Local (L) derivative-free (N) optimization using a variant of the
return NLOPT_OUT_OF_MEMORY;
return cobyla_minimize(ni, f, f_data,
opt->m, opt->fc,
+ opt->p, opt->h,
lb, ub, x, minf, &stop,
step);
}
{
if (opt && h && tol >= 0) {
/* equality constraints (h(x) = 0) only via some algorithms */
- if (!AUGLAG_ALG(opt->algorithm) && opt->algorithm != NLOPT_GN_ISRES)
+ if (!AUGLAG_ALG(opt->algorithm) && opt->algorithm != NLOPT_GN_ISRES
+ && opt->algorithm != NLOPT_LN_COBYLA)
return NLOPT_INVALID_ARGS;
return add_constraint(&opt->p, &opt->p_alloc, &opt->h,
h, h_data, tol);
void *f_data;
int m_orig;
nlopt_constraint *fc;
+ int p;
+ nlopt_constraint *h;
double *xtmp;
const double *lb, *ub;
} func_wrap_state;
*f = s->f(n, xtmp, NULL, s->f_data);
for (i = 0; i < s->m_orig; ++i)
con[i] = -s->fc[i].f(n, xtmp, NULL, s->fc[i].f_data);
+ for (j = 0; j < s->p; ++j) {
+ double h = s->h[j].f(n, xtmp, NULL, s->h[j].f_data);
+ con[i++] = h;
+ con[i++] = -h;
+ }
for (j = 0; j < n; ++j) {
if (!nlopt_isinf(lb[j]))
con[i++] = x[j] - lb[j];
nlopt_result cobyla_minimize(int n, nlopt_func f, void *f_data,
int m, nlopt_constraint *fc,
+ int p, nlopt_constraint *h,
const double *lb, const double *ub, /* bounds */
double *x, /* in: initial guess, out: minimizer */
double *minf,
s.f = f; s.f_data = f_data;
s.m_orig = m;
s.fc = fc;
+ s.p = p;
+ s.h = h;
s.lb = lb; s.ub = ub;
s.xtmp = (double *) malloc(sizeof(double) * n);
if (!s.xtmp) return NLOPT_OUT_OF_MEMORY;
+ /* each equality constraint gives two inequality constraints */
+ m += 2*p;
+
/* add constraints for lower/upper bounds (if any) */
for (j = 0; j < n; ++j) {
if (!nlopt_isinf(lb[j]))
/* NLopt-style interface function */
nlopt_result cobyla_minimize(int n, nlopt_func f, void *f_data,
int m, nlopt_constraint *fc,
+ int p, nlopt_constraint *h,
const double *lb, const double *ub, /* bounds */
double *x, /* in: initial guess, out: minimizer */
double *minf,