chiark / gitweb /
Merge branch 'master' of git://github.com/stevengj/nlopt
[nlopt.git] / src / api / nlopt-internal.h
1 /* Copyright (c) 2007-2014 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_INTERNAL_H
24 #define NLOPT_INTERNAL_H
25
26 #include "nlopt.h"
27 #include "nlopt-util.h"
28
29 #ifdef __cplusplus
30 extern "C" {
31 #endif                          /* __cplusplus */
32
33 /*********************************************************************/
34
35     struct nlopt_opt_s {
36         nlopt_algorithm algorithm;      /* the optimization algorithm (immutable) */
37         unsigned n;             /* the dimension of the problem (immutable) */
38
39         nlopt_func f;
40         void *f_data;           /* objective function to minimize */
41         nlopt_precond pre;      /* optional preconditioner for f (NULL if none) */
42         int maximize;           /* nonzero if we are maximizing, not minimizing */
43
44         double *lb, *ub;        /* lower and upper bounds (length n) */
45
46         unsigned m;             /* number of inequality constraints */
47         unsigned m_alloc;       /* number of inequality constraints allocated */
48         nlopt_constraint *fc;   /* inequality constraints, length m_alloc */
49
50         unsigned p;             /* number of equality constraints */
51         unsigned p_alloc;       /* number of inequality constraints allocated */
52         nlopt_constraint *h;    /* equality constraints, length p_alloc */
53
54         nlopt_munge munge_on_destroy, munge_on_copy;    /* hack for wrappers */
55
56         /* stopping criteria */
57         double stopval;         /* stop when f reaches stopval or better */
58         double ftol_rel, ftol_abs;      /* relative/absolute f tolerances */
59         double xtol_rel, *xtol_abs;     /* rel/abs x tolerances */
60         int maxeval;            /* max # evaluations */
61         int numevals;           /* number of evaluations */
62         double maxtime;         /* max time (seconds) */
63
64         int force_stop;         /* if nonzero, force a halt the next time we
65                                    try to evaluate the objective during optimization */
66         /* when local optimization is used, we need a force_stop in the
67            parent object to force a stop in child optimizations */
68         struct nlopt_opt_s *force_stop_child;
69
70         /* algorithm-specific parameters */
71         nlopt_opt local_opt;    /* local optimizer */
72         unsigned stochastic_population; /* population size for stochastic algs */
73         double *dx;             /* initial step sizes (length n) for nonderivative algs */
74         unsigned vector_storage;        /* max subspace dimension (0 for default) */
75
76         void *work;             /* algorithm-specific workspace during optimization */
77
78         char *errmsg;           /* description of most recent error */
79     };
80
81 /*********************************************************************/
82     extern void nlopt_srand_time_default(void); /* init the rand. seed only if unset */
83
84 /*********************************************************************/
85 /* global defaults set by deprecated API: */
86
87     extern nlopt_algorithm nlopt_local_search_alg_deriv;
88     extern nlopt_algorithm nlopt_local_search_alg_nonderiv;
89     extern int nlopt_local_search_maxeval;
90     extern unsigned nlopt_stochastic_population;
91
92 /*********************************************************************/
93
94 #define RETURN_ERR(err, opt, msg) do {          \
95     nlopt_set_errmsg(opt, msg);                 \
96     return err;                                 \
97 } while (0)
98
99     extern const char *nlopt_set_errmsg(nlopt_opt opt, const char *format, ...)
100 #ifdef __GNUC__
101         __attribute__ ((format(printf, 2, 3)))
102 #endif
103         ;
104     extern void nlopt_unset_errmsg(nlopt_opt opt);
105
106 /*********************************************************************/
107
108 #ifdef __cplusplus
109 }                               /* extern "C" */
110 #endif                          /* __cplusplus */
111 #endif                          /* NLOPT_INTERNAL_H */