nlopt.h 2.3 KB
Newer Older
S
stevenj 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13
#ifndef NLOPT_H
#define NLOPT_H

#ifdef __cplusplus
extern "C"
{
#endif /* __cplusplus */

typedef double (*nlopt_func)(int n, const double *x,
			     double *gradient, /* NULL if not needed */
			     void *func_data);

typedef enum {
14
     /* Naming conventions:
15

16 17 18 19 20
        NLOPT_{G/L}{D/N}_* 
	    = global/local derivative/no-derivative optimization, 
              respectively 
 
	*_RAND algorithms involve some randomization.
21

22 23 24
	*_NOSCAL algorithms are *not* scaled to a unit hypercube
	         (i.e. they are sensitive to the units of x)
	*/
S
stevenj 已提交
25

26 27 28 29 30 31
     NLOPT_GN_DIRECT = 0,
     NLOPT_GN_DIRECT_L,
     NLOPT_GN_DIRECT_L_RAND,
     NLOPT_GN_DIRECT_NOSCAL,
     NLOPT_GN_DIRECT_L_NOSCAL,
     NLOPT_GN_DIRECT_L_RAND_NOSCAL,
32

33 34
     NLOPT_GN_ORIG_DIRECT,
     NLOPT_GN_ORIG_DIRECT_L,
35

36 37 38 39 40 41 42 43
     NLOPT_LN_SUBPLEX,

     NLOPT_GD_STOGO,
     NLOPT_GD_STOGO_RAND,

     NLOPT_LD_LBFGS,

     NLOPT_LN_PRAXIS,
44

S
stevenj 已提交
45 46 47
     NLOPT_LD_VAR1,
     NLOPT_LD_VAR2,

48 49 50 51
     NLOPT_NUM_ALGORITHMS /* not an algorithm, just the number of them */
} nlopt_algorithm;

extern const char *nlopt_algorithm_name(nlopt_algorithm a);
S
stevenj 已提交
52 53 54 55 56 57 58

typedef enum {
     NLOPT_FAILURE = -1, /* generic failure code */
     NLOPT_INVALID_ARGS = -2,
     NLOPT_OUT_OF_MEMORY = -3,

     NLOPT_SUCCESS = 1, /* generic success code */
59
     NLOPT_MINF_MAX_REACHED = 2,
S
stevenj 已提交
60 61 62 63 64 65 66
     NLOPT_FTOL_REACHED = 3,
     NLOPT_XTOL_REACHED = 4,
     NLOPT_MAXEVAL_REACHED = 5,
     NLOPT_MAXTIME_REACHED = 6
} nlopt_result;

extern nlopt_result nlopt_minimize(
67
     nlopt_algorithm algorithm,
S
stevenj 已提交
68 69 70
     int n, nlopt_func f, void *f_data,
     const double *lb, const double *ub, /* bounds */
     double *x, /* in: initial guess, out: minimizer */
71 72
     double *minf, /* out: minimum */
     double minf_max, double ftol_rel, double ftol_abs,
S
stevenj 已提交
73 74 75
     double xtol_rel, const double *xtol_abs,
     int maxeval, double maxtime);

76 77 78
extern void nlopt_srand(unsigned long seed);
extern void nlopt_srand_time(void);

S
stevenj 已提交
79 80
extern void nlopt_version(int *major, int *minor, int *bugfix);

81 82 83 84 85 86 87
extern void nlopt_get_local_search_algorithm(nlopt_algorithm *deriv,
					     nlopt_algorithm *nonderiv,
					     int *maxeval);
extern void nlopt_set_local_search_algorithm(nlopt_algorithm deriv,
					     nlopt_algorithm nonderiv,
					     int maxeval);

S
stevenj 已提交
88 89 90 91 92
#ifdef __cplusplus
}  /* extern "C" */
#endif /* __cplusplus */

#endif