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