1 /* Copyright (c) 2007-2008 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.
26 #include <stddef.h> /* for ptrdiff_t */
28 /* for Windows compilers, you should add a line
30 when using NLopt from a DLL, in order to do the proper
31 Windows importing nonsense. */
32 #if defined(NLOPT_DLL) && (defined(_WIN32) || defined(__WIN32__))
33 /* annoying Windows syntax for calling functions in a DLL */
34 # define NLOPT_EXTERN extern __declspec(dllimport)
36 # define NLOPT_EXTERN extern
42 #endif /* __cplusplus */
44 typedef double (*nlopt_func)(int n, const double *x,
45 double *gradient, /* NULL if not needed */
49 /* Naming conventions:
52 = global/local derivative/no-derivative optimization,
55 *_RAND algorithms involve some randomization.
57 *_NOSCAL algorithms are *not* scaled to a unit hypercube
58 (i.e. they are sensitive to the units of x)
63 NLOPT_GN_DIRECT_L_RAND,
64 NLOPT_GN_DIRECT_NOSCAL,
65 NLOPT_GN_DIRECT_L_NOSCAL,
66 NLOPT_GN_DIRECT_L_RAND_NOSCAL,
69 NLOPT_GN_ORIG_DIRECT_L,
74 NLOPT_LD_LBFGS_NOCEDAL,
84 NLOPT_LD_TNEWTON_RESTART,
85 NLOPT_LD_TNEWTON_PRECOND,
86 NLOPT_LD_TNEWTON_PRECOND_RESTART,
100 NLOPT_LN_NEWUOA_BOUND,
110 NLOPT_NUM_ALGORITHMS /* not an algorithm, just the number of them */
113 extern const char *nlopt_algorithm_name(nlopt_algorithm a);
116 NLOPT_FAILURE = -1, /* generic failure code */
117 NLOPT_INVALID_ARGS = -2,
118 NLOPT_OUT_OF_MEMORY = -3,
119 NLOPT_ROUNDOFF_LIMITED = -4,
121 NLOPT_SUCCESS = 1, /* generic success code */
122 NLOPT_MINF_MAX_REACHED = 2,
123 NLOPT_FTOL_REACHED = 3,
124 NLOPT_XTOL_REACHED = 4,
125 NLOPT_MAXEVAL_REACHED = 5,
126 NLOPT_MAXTIME_REACHED = 6
129 NLOPT_EXTERN nlopt_result nlopt_minimize(
130 nlopt_algorithm algorithm,
131 int n, nlopt_func f, void *f_data,
132 const double *lb, const double *ub, /* bounds */
133 double *x, /* in: initial guess, out: minimizer */
134 double *minf, /* out: minimum */
135 double minf_max, double ftol_rel, double ftol_abs,
136 double xtol_rel, const double *xtol_abs,
137 int maxeval, double maxtime);
139 NLOPT_EXTERN nlopt_result nlopt_minimize_constrained(
140 nlopt_algorithm algorithm,
141 int n, nlopt_func f, void *f_data,
142 int m, nlopt_func fc, void *fc_data, ptrdiff_t fc_datum_size,
143 const double *lb, const double *ub, /* bounds */
144 double *x, /* in: initial guess, out: minimizer */
145 double *minf, /* out: minimum */
146 double minf_max, double ftol_rel, double ftol_abs,
147 double xtol_rel, const double *xtol_abs,
148 int maxeval, double maxtime);
150 NLOPT_EXTERN nlopt_result nlopt_minimize_econstrained(
151 nlopt_algorithm algorithm,
152 int n, nlopt_func f, void *f_data,
153 int m, nlopt_func fc, void *fc_data, ptrdiff_t fc_datum_size,
154 int p, nlopt_func h, void *h_data, ptrdiff_t h_datum_size,
155 const double *lb, const double *ub, /* bounds */
156 double *x, /* in: initial guess, out: minimizer */
157 double *minf, /* out: minimum */
158 double minf_max, double ftol_rel, double ftol_abs,
159 double xtol_rel, const double *xtol_abs,
160 double htol_rel, double htol_abs,
161 int maxeval, double maxtime);
163 NLOPT_EXTERN void nlopt_srand(unsigned long seed);
164 NLOPT_EXTERN void nlopt_srand_time(void);
166 NLOPT_EXTERN void nlopt_version(int *major, int *minor, int *bugfix);
168 NLOPT_EXTERN void nlopt_get_local_search_algorithm(nlopt_algorithm *deriv,
169 nlopt_algorithm *nonderiv,
171 NLOPT_EXTERN void nlopt_set_local_search_algorithm(nlopt_algorithm deriv,
172 nlopt_algorithm nonderiv,
177 #endif /* __cplusplus */