chiark / gitweb /
e2362be2dad202f7b9c7e1433df7fd44e952dd93
[nlopt.git] / api / nlopt.h
1 /* Copyright (c) 2007-2008 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 #ifdef __cplusplus
29 extern "C"
30 {
31 #endif /* __cplusplus */
32
33 typedef double (*nlopt_func)(int n, const double *x,
34                              double *gradient, /* NULL if not needed */
35                              void *func_data);
36
37 typedef enum {
38      /* Naming conventions:
39
40         NLOPT_{G/L}{D/N}_* 
41             = global/local derivative/no-derivative optimization, 
42               respectively 
43  
44         *_RAND algorithms involve some randomization.
45
46         *_NOSCAL algorithms are *not* scaled to a unit hypercube
47                  (i.e. they are sensitive to the units of x)
48         */
49
50      NLOPT_GN_DIRECT = 0,
51      NLOPT_GN_DIRECT_L,
52      NLOPT_GN_DIRECT_L_RAND,
53      NLOPT_GN_DIRECT_NOSCAL,
54      NLOPT_GN_DIRECT_L_NOSCAL,
55      NLOPT_GN_DIRECT_L_RAND_NOSCAL,
56
57      NLOPT_GN_ORIG_DIRECT,
58      NLOPT_GN_ORIG_DIRECT_L,
59
60      NLOPT_GD_STOGO,
61      NLOPT_GD_STOGO_RAND,
62
63      NLOPT_LD_LBFGS_NOCEDAL,
64
65      NLOPT_LD_LBFGS,
66
67      NLOPT_LN_PRAXIS,
68
69      NLOPT_LD_VAR1,
70      NLOPT_LD_VAR2,
71
72      NLOPT_LD_TNEWTON,
73      NLOPT_LD_TNEWTON_RESTART,
74      NLOPT_LD_TNEWTON_PRECOND,
75      NLOPT_LD_TNEWTON_PRECOND_RESTART,
76
77      NLOPT_GN_CRS2_LM,
78
79      NLOPT_GN_MLSL,
80      NLOPT_GD_MLSL,
81      NLOPT_GN_MLSL_LDS,
82      NLOPT_GD_MLSL_LDS,
83
84      NLOPT_LD_MMA,
85
86      NLOPT_LN_COBYLA,
87
88      NLOPT_LN_NEWUOA,
89      NLOPT_LN_NEWUOA_BOUND,
90
91      NLOPT_LN_NELDERMEAD,
92      NLOPT_LN_SBPLX,
93
94      NLOPT_NUM_ALGORITHMS /* not an algorithm, just the number of them */
95 } nlopt_algorithm;
96
97 extern const char *nlopt_algorithm_name(nlopt_algorithm a);
98
99 typedef enum {
100      NLOPT_FAILURE = -1, /* generic failure code */
101      NLOPT_INVALID_ARGS = -2,
102      NLOPT_OUT_OF_MEMORY = -3,
103
104      NLOPT_SUCCESS = 1, /* generic success code */
105      NLOPT_MINF_MAX_REACHED = 2,
106      NLOPT_FTOL_REACHED = 3,
107      NLOPT_XTOL_REACHED = 4,
108      NLOPT_MAXEVAL_REACHED = 5,
109      NLOPT_MAXTIME_REACHED = 6
110 } nlopt_result;
111
112 extern nlopt_result nlopt_minimize(
113      nlopt_algorithm algorithm,
114      int n, nlopt_func f, void *f_data,
115      const double *lb, const double *ub, /* bounds */
116      double *x, /* in: initial guess, out: minimizer */
117      double *minf, /* out: minimum */
118      double minf_max, double ftol_rel, double ftol_abs,
119      double xtol_rel, const double *xtol_abs,
120      int maxeval, double maxtime);
121
122 extern nlopt_result nlopt_minimize_constrained(
123      nlopt_algorithm algorithm,
124      int n, nlopt_func f, void *f_data,
125      int m, nlopt_func fc, void *fc_data, ptrdiff_t fc_datum_size,
126      const double *lb, const double *ub, /* bounds */
127      double *x, /* in: initial guess, out: minimizer */
128      double *minf, /* out: minimum */
129      double minf_max, double ftol_rel, double ftol_abs,
130      double xtol_rel, const double *xtol_abs,
131      int maxeval, double maxtime);
132
133 extern nlopt_result nlopt_minimize_econstrained(
134      nlopt_algorithm algorithm,
135      int n, nlopt_func f, void *f_data,
136      int m, nlopt_func fc, void *fc_data, ptrdiff_t fc_datum_size,
137      int p, nlopt_func h, void *h_data, ptrdiff_t h_datum_size,
138      const double *lb, const double *ub, /* bounds */
139      double *x, /* in: initial guess, out: minimizer */
140      double *minf, /* out: minimum */
141      double minf_max, double ftol_rel, double ftol_abs,
142      double xtol_rel, const double *xtol_abs,
143      int maxeval, double maxtime);
144
145 extern void nlopt_srand(unsigned long seed);
146 extern void nlopt_srand_time(void);
147
148 extern void nlopt_version(int *major, int *minor, int *bugfix);
149
150 extern void nlopt_get_local_search_algorithm(nlopt_algorithm *deriv,
151                                              nlopt_algorithm *nonderiv,
152                                              int *maxeval);
153 extern void nlopt_set_local_search_algorithm(nlopt_algorithm deriv,
154                                              nlopt_algorithm nonderiv,
155                                              int maxeval);
156
157 #ifdef __cplusplus
158 }  /* extern "C" */
159 #endif /* __cplusplus */
160
161 #endif