nlopt_result NLOPT_STDCALL nlopt_add_inequality_mconstraint(nlopt_opt opt, unsigned m, nlopt_mfunc fc, void *fc_data, const double *tol) { nlopt_result ret; if (!m) { /* empty constraints are always ok */ if (opt && opt->munge_on_destroy) opt->munge_on_destroy(fc_data); return NLOPT_SUCCESS; } if (!opt || !inequality_ok(opt->algorithm)) ret = NLOPT_INVALID_ARGS; else ret = add_constraint(&opt->m, &opt->m_alloc, &opt->fc, m, NULL, fc, NULL, fc_data, tol); if (ret < 0 && opt && opt->munge_on_destroy) opt->munge_on_destroy(fc_data); return ret; }
nlopt_result NLOPT_STDCALL nlopt_add_inequality_constraint(nlopt_opt opt, nlopt_func fc, void *fc_data, double tol) { nlopt_result ret; if (!opt || !inequality_ok(opt->algorithm)) ret = NLOPT_INVALID_ARGS; else ret = add_constraint(&opt->m, &opt->m_alloc, &opt->fc, 1, fc, NULL, fc_data, &tol); if (ret < 0 && opt && opt->munge_on_destroy) opt->munge_on_destroy(fc_data); return ret; }
nlopt_result NLOPT_STDCALL nlopt_set_max_objective(nlopt_opt opt, nlopt_func f, void *f_data) { if (opt) { if (opt->munge_on_destroy) opt->munge_on_destroy(opt->f_data); opt->f = f; opt->f_data = f_data; opt->maximize = 1; if (nlopt_isinf(opt->stopval) && opt->stopval < 0) opt->stopval = +HUGE_VAL; /* switch default from min to max */ return NLOPT_SUCCESS; } return NLOPT_INVALID_ARGS; }
nlopt_result NLOPT_STDCALL nlopt_set_precond_min_objective(nlopt_opt opt, nlopt_func f, nlopt_precond pre, void *f_data) { if (opt) { if (opt->munge_on_destroy) opt->munge_on_destroy(opt->f_data); opt->f = f; opt->f_data = f_data; opt->pre = pre; opt->maximize = 0; if (nlopt_isinf(opt->stopval) && opt->stopval > 0) opt->stopval = -HUGE_VAL; /* switch default from max to min */ return NLOPT_SUCCESS; } return NLOPT_INVALID_ARGS; }
nlopt_result NLOPT_STDCALL nlopt_add_precond_equality_constraint(nlopt_opt opt, nlopt_func fc, nlopt_precond pre, void *fc_data, double tol) { nlopt_result ret; if (!opt || !equality_ok(opt->algorithm) || nlopt_count_constraints(opt->p, opt->h) + 1 > opt->n) ret = NLOPT_INVALID_ARGS; else ret = add_constraint(&opt->p, &opt->p_alloc, &opt->h, 1, fc, NULL, pre, fc_data, &tol); if (ret < 0 && opt && opt->munge_on_destroy) opt->munge_on_destroy(fc_data); return ret; }