double *gradient, const int *need_gradient,
void *func_data);
+typedef void (*nlopt_f77_mfunc)(const int *m,
+ double *val, const int *n, const double *x,
+ double *gradient, const int *need_gradient,
+ void *func_data);
+
typedef struct {
nlopt_f77_func f;
+ nlopt_f77_mfunc mf;
void *f_data;
} f77_func_data;
return val;
}
+static void f77_mfunc_wrap(unsigned m, double *result, unsigned n, const double *x, double *grad, void *data)
+{
+ f77_func_data *d = (f77_func_data *) data;
+ int mi = (int) m;
+ int ni = (int) n;
+ int need_gradient = grad != 0;
+ d->mf(&mi, result, &ni, x, grad, &need_gradient, d->f_data);
+}
+
/*-----------------------------------------------------------------------*/
#define F77_GET(name,NAME,T) void F77_(nlo_get_##name,NLO_GET_##NAME)(T *val, nlopt_opt *opt) { *val = (T) nlopt_get_##name(*opt); }
*ret = (int) nlopt_add_inequality_constraint(*opt, f77_func_wrap,d, *tol);
}
+void F77_(nlo_add_inequality_mconstraint,NLO_ADD_INEQUALITY_MCONSTRAINT)(
+ int *ret, nlopt_opt *opt, int *m,
+ nlopt_f77_mfunc mfc, void *mfc_data, double *tol)
+{
+ f77_func_data *d;
+ if (*m < 0) { *ret = (int) NLOPT_INVALID_ARGS; return; }
+ if (*m == 0) { *ret = (int) NLOPT_SUCCESS; return; }
+ d = (f77_func_data*) malloc(sizeof(f77_func_data));
+ if (!d) { *ret = (int) NLOPT_OUT_OF_MEMORY; return; }
+ d->mf = mfc;
+ d->f_data = mfc_data;
+ *ret = (int) nlopt_add_inequality_mconstraint(*opt, (unsigned) *m,
+ f77_mfunc_wrap, d, tol);
+}
+
void F77_(nlo_remove_equality_constraints,NLO_REMOVE_EQUALITY_CONSTRAINTS)(
int *ret, nlopt_opt *opt) {
*ret = (int) nlopt_remove_equality_constraints(*opt);
*ret = (int) nlopt_add_equality_constraint(*opt, f77_func_wrap,d, *tol);
}
+void F77_(nlo_add_equality_mconstraint,NLO_ADD_EQUALITY_MCONSTRAINT)(
+ int *ret, nlopt_opt *opt, int *m,
+ nlopt_f77_mfunc mfc, void *mfc_data, double *tol)
+{
+ f77_func_data *d;
+ if (*m < 0) { *ret = (int) NLOPT_INVALID_ARGS; return; }
+ if (*m == 0) { *ret = (int) NLOPT_SUCCESS; return; }
+ d = (f77_func_data*) malloc(sizeof(f77_func_data));
+ if (!d) { *ret = (int) NLOPT_OUT_OF_MEMORY; return; }
+ d->mf = mfc;
+ d->f_data = mfc_data;
+ *ret = (int) nlopt_add_equality_mconstraint(*opt, (unsigned) *m,
+ f77_mfunc_wrap, d, tol);
+}
+
F77_GETSET(stopval, STOPVAL, double)
F77_GETSET(ftol_rel, FTOL_REL, double)
F77_GETSET(ftol_abs, FTOL_ABS, double)