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, const double *xtol_rel, const double *xtol_abs, const int *have_xtol_abs, const int *maxeval, const double *maxtime) {
47 *info = NLOPT_INVALID_ARGS;
50 dc = (f77_func_data *) malloc(sizeof(f77_func_data) * *m);
52 *info = NLOPT_OUT_OF_MEMORY;
55 for (i = 0; i < *m; ++i) {
57 dc[i].f_data = fc_data + i * (fc_second_datum - fc_data);
60 *info = nlopt_minimize_constrained((nlopt_algorithm) * algorithm,
61 *n, f77_func_wrap_old, &d,
62 *m, f77_func_wrap_old,
63 dc, sizeof(f77_func_data), lb, ub, x, minf, *minf_max, *ftol_rel, *ftol_abs, *xtol_rel, *have_xtol_abs ? xtol_abs : 0, *maxeval, *maxtime);
70 void F77(nloptm, NLOPTM) (int *info,
72 const int *n, nlopt_f77_func f, void *f_data,
73 const double *lb, const double *ub,
74 double *x, double *minf,
75 const double *minf_max,
76 const double *ftol_rel, const double *ftol_abs, const double *xtol_rel, const double *xtol_abs, const int *have_xtol_abs, const int *maxeval, const double *maxtime) {
78 F77CALL(nloptc, NLOPTC) (info, algorithm, n, f, f_data, &m, 0, 0, 0, lb, ub, x, minf, minf_max, ftol_rel, ftol_abs, xtol_rel, xtol_abs, have_xtol_abs, maxeval, maxtime);
81 void F77(nlosr, NLOSR) (const int *seed) {
82 nlopt_srand((unsigned long) *seed);
85 void F77(nlosrt, NLOSRT) (void) {
89 void F77(nloptv, NLOPTV) (int *major, int *minor, int *bugfix) {
90 nlopt_version(major, minor, bugfix);
93 void F77(nlogls, NLOGLS) (int *ideriv, int *inonderiv, int *maxeval) {
94 nlopt_algorithm deriv, nonderiv;
95 nlopt_get_local_search_algorithm(&deriv, &nonderiv, maxeval);
97 *inonderiv = nonderiv;
100 void F77(nlosls, NLOSLS) (int *ideriv, int *inonderiv, int *maxeval) {
101 nlopt_algorithm deriv = (nlopt_algorithm) * ideriv;
102 nlopt_algorithm nonderiv = (nlopt_algorithm) * inonderiv;
103 nlopt_set_local_search_algorithm(deriv, nonderiv, *maxeval);
106 void F77(nlogsp, NLOGSP) (int *pop) {
107 *pop = nlopt_get_stochastic_population();
110 void F77(nlossp, NLOSSP) (const int *pop) {
111 nlopt_set_stochastic_population(*pop);
114 #define F77_(name,NAME) F77(name,NAME)
115 # include "f77funcs_.h"