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 In homage to Fortran 77, we stick with 6-character subroutine names.
28 The return value of the function is converted into the first argument
31 /* nlopt_minimize_constrained */
32 void F77(nloptc,NLOPTC)(int *info,
34 const int *n, nlopt_f77_func f, void *f_data,
35 const int *m, nlopt_f77_func fc,
36 char *fc_data, char *fc_second_datum,
37 const double *lb, const double *ub,
38 double *x, double *minf,
39 const double *minf_max,
40 const double *ftol_rel, const double *ftol_abs,
41 const double *xtol_rel, const double *xtol_abs,
42 const int *have_xtol_abs,
43 const int *maxeval, const double *maxtime)
48 d.f = f; d.f_data = f_data;
49 if (*m < 0) { *info = NLOPT_INVALID_ARGS; return; }
50 dc = (f77_func_data *) malloc(sizeof(f77_func_data) * *m);
51 if (*m > 0 && !dc) { *info = NLOPT_OUT_OF_MEMORY; return; }
52 for (i = 0; i < *m; ++i) {
54 dc[i].f_data = fc_data + i * (fc_second_datum - fc_data);
57 *info = nlopt_minimize_constrained((nlopt_algorithm) *algorithm,
58 *n, f77_func_wrap_old, &d,
59 *m, f77_func_wrap_old,
60 dc, sizeof(f77_func_data),
62 *minf_max, *ftol_rel, *ftol_abs,
64 *have_xtol_abs ? xtol_abs : 0,
71 void F77(nloptm,NLOPTM)(int *info,
73 const int *n, nlopt_f77_func f, void *f_data,
74 const double *lb, const double *ub,
75 double *x, double *minf,
76 const double *minf_max,
77 const double *ftol_rel, const double *ftol_abs,
78 const double *xtol_rel, const double *xtol_abs,
79 const int *have_xtol_abs,
80 const int *maxeval, const double *maxtime)
83 F77CALL(nloptc,NLOPTC)(info, algorithm, n, f, f_data, &m, 0, 0, 0,
84 lb, ub, x, minf, minf_max, ftol_rel, ftol_abs,
85 xtol_rel, xtol_abs, have_xtol_abs, maxeval, maxtime);
88 void F77(nlosr,NLOSR)(const int *seed) { nlopt_srand((unsigned long) *seed); }
89 void F77(nlosrt,NLOSRT)(void) { nlopt_srand_time(); }
90 void F77(nloptv,NLOPTV)(int *major, int *minor, int *bugfix) {
91 nlopt_version(major, minor, bugfix);
93 void F77(nlogls,NLOGLS)(int *ideriv, int *inonderiv, int *maxeval)
95 nlopt_algorithm deriv, nonderiv;
96 nlopt_get_local_search_algorithm(&deriv, &nonderiv, maxeval);
98 *inonderiv = nonderiv;
100 void F77(nlosls,NLOSLS)(int *ideriv, int *inonderiv, int *maxeval)
102 nlopt_algorithm deriv = (nlopt_algorithm) *ideriv;
103 nlopt_algorithm nonderiv = (nlopt_algorithm) *inonderiv;
104 nlopt_set_local_search_algorithm(deriv, nonderiv, *maxeval);
107 void F77(nlogsp,NLOGSP)(int *pop)
109 *pop = nlopt_get_stochastic_population();
111 void F77(nlossp,NLOSSP)(const int *pop)
113 nlopt_set_stochastic_population(*pop);
116 #define F77_(name,NAME) F77(name,NAME)
117 # include "f77funcs_.h"