chiark / gitweb /
added get/set stochastic_population functions for greater control over stochastic...
[nlopt.git] / api / nlopt.h
1 /* Copyright (c) 2007-2009 Massachusetts Institute of Technology
2  *
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:
10  * 
11  * The above copyright notice and this permission notice shall be
12  * included in all copies or substantial portions of the Software.
13  * 
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. 
21  */
22
23 #ifndef NLOPT_H
24 #define NLOPT_H
25
26 #include <stddef.h> /* for ptrdiff_t */
27
28 /* for Windows compilers, you should add a line
29            #define NLOPT_DLL
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)
35 #else
36 #  define NLOPT_EXTERN extern
37 #endif
38
39 #ifdef __cplusplus
40 extern "C"
41 {
42 #endif /* __cplusplus */
43
44 typedef double (*nlopt_func)(int n, const double *x,
45                              double *gradient, /* NULL if not needed */
46                              void *func_data);
47
48 typedef enum {
49      /* Naming conventions:
50
51         NLOPT_{G/L}{D/N}_* 
52             = global/local derivative/no-derivative optimization, 
53               respectively 
54  
55         *_RAND algorithms involve some randomization.
56
57         *_NOSCAL algorithms are *not* scaled to a unit hypercube
58                  (i.e. they are sensitive to the units of x)
59         */
60
61      NLOPT_GN_DIRECT = 0,
62      NLOPT_GN_DIRECT_L,
63      NLOPT_GN_DIRECT_L_RAND,
64      NLOPT_GN_DIRECT_NOSCAL,
65      NLOPT_GN_DIRECT_L_NOSCAL,
66      NLOPT_GN_DIRECT_L_RAND_NOSCAL,
67
68      NLOPT_GN_ORIG_DIRECT,
69      NLOPT_GN_ORIG_DIRECT_L,
70
71      NLOPT_GD_STOGO,
72      NLOPT_GD_STOGO_RAND,
73
74      NLOPT_LD_LBFGS_NOCEDAL,
75
76      NLOPT_LD_LBFGS,
77
78      NLOPT_LN_PRAXIS,
79
80      NLOPT_LD_VAR1,
81      NLOPT_LD_VAR2,
82
83      NLOPT_LD_TNEWTON,
84      NLOPT_LD_TNEWTON_RESTART,
85      NLOPT_LD_TNEWTON_PRECOND,
86      NLOPT_LD_TNEWTON_PRECOND_RESTART,
87
88      NLOPT_GN_CRS2_LM,
89
90      NLOPT_GN_MLSL,
91      NLOPT_GD_MLSL,
92      NLOPT_GN_MLSL_LDS,
93      NLOPT_GD_MLSL_LDS,
94
95      NLOPT_LD_MMA,
96
97      NLOPT_LN_COBYLA,
98
99      NLOPT_LN_NEWUOA,
100      NLOPT_LN_NEWUOA_BOUND,
101
102      NLOPT_LN_NELDERMEAD,
103      NLOPT_LN_SBPLX,
104
105      NLOPT_LN_AUGLAG,
106      NLOPT_LD_AUGLAG,
107      NLOPT_LN_AUGLAG_EQ,
108      NLOPT_LD_AUGLAG_EQ,
109
110      NLOPT_LN_BOBYQA,
111
112      NLOPT_GN_ISRES,
113
114      NLOPT_NUM_ALGORITHMS /* not an algorithm, just the number of them */
115 } nlopt_algorithm;
116
117 extern const char *nlopt_algorithm_name(nlopt_algorithm a);
118
119 typedef enum {
120      NLOPT_FAILURE = -1, /* generic failure code */
121      NLOPT_INVALID_ARGS = -2,
122      NLOPT_OUT_OF_MEMORY = -3,
123      NLOPT_ROUNDOFF_LIMITED = -4,
124
125      NLOPT_SUCCESS = 1, /* generic success code */
126      NLOPT_MINF_MAX_REACHED = 2,
127      NLOPT_FTOL_REACHED = 3,
128      NLOPT_XTOL_REACHED = 4,
129      NLOPT_MAXEVAL_REACHED = 5,
130      NLOPT_MAXTIME_REACHED = 6
131 } nlopt_result;
132
133 NLOPT_EXTERN nlopt_result nlopt_minimize(
134      nlopt_algorithm algorithm,
135      int n, nlopt_func f, void *f_data,
136      const double *lb, const double *ub, /* bounds */
137      double *x, /* in: initial guess, out: minimizer */
138      double *minf, /* out: minimum */
139      double minf_max, double ftol_rel, double ftol_abs,
140      double xtol_rel, const double *xtol_abs,
141      int maxeval, double maxtime);
142
143 NLOPT_EXTERN nlopt_result nlopt_minimize_constrained(
144      nlopt_algorithm algorithm,
145      int n, nlopt_func f, void *f_data,
146      int m, nlopt_func fc, void *fc_data, ptrdiff_t fc_datum_size,
147      const double *lb, const double *ub, /* bounds */
148      double *x, /* in: initial guess, out: minimizer */
149      double *minf, /* out: minimum */
150      double minf_max, double ftol_rel, double ftol_abs,
151      double xtol_rel, const double *xtol_abs,
152      int maxeval, double maxtime);
153
154 NLOPT_EXTERN nlopt_result nlopt_minimize_econstrained(
155      nlopt_algorithm algorithm,
156      int n, nlopt_func f, void *f_data,
157      int m, nlopt_func fc, void *fc_data, ptrdiff_t fc_datum_size,
158      int p, nlopt_func h, void *h_data, ptrdiff_t h_datum_size,
159      const double *lb, const double *ub, /* bounds */
160      double *x, /* in: initial guess, out: minimizer */
161      double *minf, /* out: minimum */
162      double minf_max, double ftol_rel, double ftol_abs,
163      double xtol_rel, const double *xtol_abs,
164      double htol_rel, double htol_abs,
165      int maxeval, double maxtime);
166
167 NLOPT_EXTERN void nlopt_srand(unsigned long seed);
168 NLOPT_EXTERN void nlopt_srand_time(void);
169
170 NLOPT_EXTERN void nlopt_version(int *major, int *minor, int *bugfix);
171
172 NLOPT_EXTERN void nlopt_get_local_search_algorithm(nlopt_algorithm *deriv,
173                                              nlopt_algorithm *nonderiv,
174                                              int *maxeval);
175 NLOPT_EXTERN void nlopt_set_local_search_algorithm(nlopt_algorithm deriv,
176                                              nlopt_algorithm nonderiv,
177                                              int maxeval);
178
179 NLOPT_EXTERN int nlopt_get_stochastic_population(void);
180 NLOPT_EXTERN void nlopt_set_stochastic_population(int pop);
181
182 #ifdef __cplusplus
183 }  /* extern "C" */
184 #endif /* __cplusplus */
185
186 #endif