chiark / gitweb /
changed nlopt_minimize_c to nlopt_minimize_constrained, added man page
[nlopt.git] / api / nlopt.h
1 #ifndef NLOPT_H
2 #define NLOPT_H
3
4 #include <stddef.h> /* for ptrdiff_t */
5
6 #ifdef __cplusplus
7 extern "C"
8 {
9 #endif /* __cplusplus */
10
11 typedef double (*nlopt_func)(int n, const double *x,
12                              double *gradient, /* NULL if not needed */
13                              void *func_data);
14
15 typedef enum {
16      /* Naming conventions:
17
18         NLOPT_{G/L}{D/N}_* 
19             = global/local derivative/no-derivative optimization, 
20               respectively 
21  
22         *_RAND algorithms involve some randomization.
23
24         *_NOSCAL algorithms are *not* scaled to a unit hypercube
25                  (i.e. they are sensitive to the units of x)
26         */
27
28      NLOPT_GN_DIRECT = 0,
29      NLOPT_GN_DIRECT_L,
30      NLOPT_GN_DIRECT_L_RAND,
31      NLOPT_GN_DIRECT_NOSCAL,
32      NLOPT_GN_DIRECT_L_NOSCAL,
33      NLOPT_GN_DIRECT_L_RAND_NOSCAL,
34
35      NLOPT_GN_ORIG_DIRECT,
36      NLOPT_GN_ORIG_DIRECT_L,
37
38      NLOPT_LN_SUBPLEX,
39
40      NLOPT_GD_STOGO,
41      NLOPT_GD_STOGO_RAND,
42
43      NLOPT_LD_LBFGS_NOCEDAL,
44
45      NLOPT_LD_LBFGS,
46
47      NLOPT_LN_PRAXIS,
48
49      NLOPT_LD_VAR1,
50      NLOPT_LD_VAR2,
51
52      NLOPT_LD_TNEWTON,
53      NLOPT_LD_TNEWTON_RESTART,
54      NLOPT_LD_TNEWTON_PRECOND,
55      NLOPT_LD_TNEWTON_PRECOND_RESTART,
56
57      NLOPT_GN_CRS2_LM,
58
59      NLOPT_GN_MLSL,
60      NLOPT_GD_MLSL,
61      NLOPT_GN_MLSL_LDS,
62      NLOPT_GD_MLSL_LDS,
63
64      NLOPT_LD_MMA,
65
66      NLOPT_NUM_ALGORITHMS /* not an algorithm, just the number of them */
67 } nlopt_algorithm;
68
69 extern const char *nlopt_algorithm_name(nlopt_algorithm a);
70
71 typedef enum {
72      NLOPT_FAILURE = -1, /* generic failure code */
73      NLOPT_INVALID_ARGS = -2,
74      NLOPT_OUT_OF_MEMORY = -3,
75
76      NLOPT_SUCCESS = 1, /* generic success code */
77      NLOPT_MINF_MAX_REACHED = 2,
78      NLOPT_FTOL_REACHED = 3,
79      NLOPT_XTOL_REACHED = 4,
80      NLOPT_MAXEVAL_REACHED = 5,
81      NLOPT_MAXTIME_REACHED = 6
82 } nlopt_result;
83
84 extern nlopt_result nlopt_minimize(
85      nlopt_algorithm algorithm,
86      int n, nlopt_func f, void *f_data,
87      const double *lb, const double *ub, /* bounds */
88      double *x, /* in: initial guess, out: minimizer */
89      double *minf, /* out: minimum */
90      double minf_max, double ftol_rel, double ftol_abs,
91      double xtol_rel, const double *xtol_abs,
92      int maxeval, double maxtime);
93
94 extern nlopt_result nlopt_minimize_constrained(
95      nlopt_algorithm algorithm,
96      int n, nlopt_func f, void *f_data,
97      int m, nlopt_func fc, void *fc_data, ptrdiff_t fc_datum_size,
98      const double *lb, const double *ub, /* bounds */
99      double *x, /* in: initial guess, out: minimizer */
100      double *minf, /* out: minimum */
101      double minf_max, double ftol_rel, double ftol_abs,
102      double xtol_rel, const double *xtol_abs,
103      int maxeval, double maxtime);
104
105 extern void nlopt_srand(unsigned long seed);
106 extern void nlopt_srand_time(void);
107
108 extern void nlopt_version(int *major, int *minor, int *bugfix);
109
110 extern void nlopt_get_local_search_algorithm(nlopt_algorithm *deriv,
111                                              nlopt_algorithm *nonderiv,
112                                              int *maxeval);
113 extern void nlopt_set_local_search_algorithm(nlopt_algorithm deriv,
114                                              nlopt_algorithm nonderiv,
115                                              int maxeval);
116
117 #ifdef __cplusplus
118 }  /* extern "C" */
119 #endif /* __cplusplus */
120
121 #endif