1 /* Copyright (c) 2007-2014 Massachusetts Institute of Technology
3 * Permission is hereby granted, free of charge, to any person obtaining
4 * a copy of this software and associated documentation files (the
5 * "Software"), to deal in the Software without restriction, including
6 * without limitation the rights to use, copy, modify, merge, publish,
7 * distribute, sublicense, and/or sell copies of the Software, and to
8 * permit persons to whom the Software is furnished to do so, subject to
9 * the following conditions:
11 * The above copyright notice and this permission notice shall be
12 * included in all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 /* Fortran API wrappers, using the F77 macro defined in f77api.c.
24 This header file is #included one or more times from f77api.c
25 in order to define verions of the Fortran API for various compilers.
27 All of the functions in this file have underscores in their names,
28 which means that they are treated differently for name-mangling
29 (thank you, g77 and f2c) than names without underscores.
31 The return value of a function is converted to the first argument
34 void F77_(nlo_create, NLO_CREATE) (nlopt_opt * opt, int *alg, int *n) {
38 *opt = nlopt_create((nlopt_algorithm) * alg, (unsigned) *n);
39 nlopt_set_munge(*opt, free_f77_func_data, dup_f77_func_data);
43 void F77_(nlo_copy, NLO_COPY) (nlopt_opt * nopt, nlopt_opt * opt) {
44 *nopt = nlopt_copy(*opt);
47 void F77_(nlo_destroy, NLO_DESTROY) (nlopt_opt * opt) {
51 void F77_(nlo_optimize, NLO_OPTIMIZE) (int *ret, nlopt_opt * opt, double *x, double *optf) {
52 *ret = (int) nlopt_optimize(*opt, x, optf);
55 void F77_(nlo_set_min_objective, NLO_SET_MIN_OBJECTIVE) (int *ret, nlopt_opt * opt, nlopt_f77_func f, void *f_data) {
56 f77_func_data *d = (f77_func_data *) malloc(sizeof(f77_func_data));
58 *ret = (int) NLOPT_OUT_OF_MEMORY;
63 *ret = (int) nlopt_set_min_objective(*opt, f77_func_wrap, d);
66 void F77_(nlo_set_max_objective, NLO_SET_MAX_OBJECTIVE) (int *ret, nlopt_opt * opt, nlopt_f77_func f, void *f_data) {
67 f77_func_data *d = (f77_func_data *) malloc(sizeof(f77_func_data));
69 *ret = (int) NLOPT_OUT_OF_MEMORY;
74 *ret = (int) nlopt_set_max_objective(*opt, f77_func_wrap, d);
77 F77_GET(algorithm, ALGORITHM, int) F77_GET(dimension, DIMENSION, int)
78 F77_GETSETA(lower_bounds, LOWER_BOUNDS, double) F77_GETSETA(upper_bounds, UPPER_BOUNDS, double)
80 void F77_(nlo_remove_inequality_constraints, NLO_REMOVE_INEQUALITY_CONSTRAINTS) (int *ret, nlopt_opt * opt)
82 *ret = (int) nlopt_remove_inequality_constraints(*opt);
85 void F77_(nlo_add_inequality_constraint, NLO_ADD_INEQUALITY_CONSTRAINT) (int *ret, nlopt_opt * opt, nlopt_f77_func fc, void *fc_data, double *tol) {
86 f77_func_data *d = (f77_func_data *) malloc(sizeof(f77_func_data));
88 *ret = (int) NLOPT_OUT_OF_MEMORY;
93 *ret = (int) nlopt_add_inequality_constraint(*opt, f77_func_wrap, d, *tol);
96 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) {
99 *ret = (int) NLOPT_INVALID_ARGS;
103 *ret = (int) NLOPT_SUCCESS;
106 d = (f77_func_data *) malloc(sizeof(f77_func_data));
108 *ret = (int) NLOPT_OUT_OF_MEMORY;
112 d->f_data = mfc_data;
113 *ret = (int) nlopt_add_inequality_mconstraint(*opt, (unsigned) *m, f77_mfunc_wrap, d, tol);
116 void F77_(nlo_remove_equality_constraints, NLO_REMOVE_EQUALITY_CONSTRAINTS) (int *ret, nlopt_opt * opt) {
117 *ret = (int) nlopt_remove_equality_constraints(*opt);
120 void F77_(nlo_add_equality_constraint, NLO_ADD_EQUALITY_CONSTRAINT) (int *ret, nlopt_opt * opt, nlopt_f77_func fc, void *fc_data, double *tol) {
121 f77_func_data *d = (f77_func_data *) malloc(sizeof(f77_func_data));
123 *ret = (int) NLOPT_OUT_OF_MEMORY;
128 *ret = (int) nlopt_add_equality_constraint(*opt, f77_func_wrap, d, *tol);
131 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) {
134 *ret = (int) NLOPT_INVALID_ARGS;
138 *ret = (int) NLOPT_SUCCESS;
141 d = (f77_func_data *) malloc(sizeof(f77_func_data));
143 *ret = (int) NLOPT_OUT_OF_MEMORY;
147 d->f_data = mfc_data;
148 *ret = (int) nlopt_add_equality_mconstraint(*opt, (unsigned) *m, f77_mfunc_wrap, d, tol);
151 F77_GETSET(stopval, STOPVAL, double)
152 F77_GETSET(ftol_rel, FTOL_REL, double)
153 F77_GETSET(ftol_abs, FTOL_ABS, double)
154 F77_GETSET(xtol_rel, XTOL_REL, double) F77_GETSETA(xtol_abs, XTOL_ABS, double) F77_GETSET(maxeval, MAXEVAL, int) F77_GET(numevals, NUMEVALS, int) F77_GETSET(maxtime, MAXTIME, double)
155 F77_GETSET(force_stop, FORCE_STOP, int)
156 void F77_(nlo_force_stop, NLO_FORCE_STOP) (int *ret, nlopt_opt * opt)
158 *ret = (int) nlopt_force_stop(*opt);
161 F77_SET(local_optimizer, LOCAL_OPTIMIZER, nlopt_opt)
162 F77_GETSET(population, POPULATION, unsigned) F77_GETSET(vector_storage, vector_storage, unsigned)
163 F77_SETA(default_initial_step, DEFAULT_INITIAL_STEP, double) F77_SETA(initial_step, INITIAL_STEP, double) F77_SET(initial_step1, INITIAL_STEP1, double)
164 void F77_(nlo_get_initial_step, NLO_GET_INITIAL_STEP) (int *ret, nlopt_opt * opt, const double *x, double *dx)
166 *ret = (int) nlopt_get_initial_step(*opt, x, dx);