chiark / gitweb /
46e2ca6a16bab123074182b8eb30ec25fc842568
[nlopt.git] / util / nlopt-util.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_UTIL_H
24 #define NLOPT_UTIL_H
25
26 #include <stdlib.h>
27
28 #ifdef __cplusplus
29 extern "C"
30 {
31 #endif /* __cplusplus */
32
33 int nlopt_isinf(double x);
34
35 /* re-entrant qsort */
36 extern void nlopt_qsort_r(void *base_, size_t nmemb, size_t size, void *thunk,
37                           int (*compar)(void *, const void *, const void *));
38
39 /* seconds timer */
40 extern double nlopt_seconds(void);
41 extern unsigned long nlopt_time_seed(void);
42
43 /* pseudorandom number generation by Mersenne twister algorithm */
44 extern void nlopt_init_genrand(unsigned long s);
45 extern double nlopt_urand(double a, double b);
46 extern int nlopt_iurand(int n);
47
48 /* Sobol' low-discrepancy-sequence generation */
49 typedef struct nlopt_soboldata_s *nlopt_sobol;
50 extern nlopt_sobol nlopt_sobol_create(unsigned sdim);
51 extern void nlopt_sobol_destroy(nlopt_sobol s);
52 extern void nlopt_sobol_next01(nlopt_sobol s, double *x);
53 extern void nlopt_sobol_next(nlopt_sobol s, double *x,
54                             const double *lb, const double *ub);
55 extern void nlopt_sobol_skip(nlopt_sobol s, unsigned n, double *x);
56
57 /* stopping criteria */
58 typedef struct {
59      int n;
60      double minf_max;
61      double ftol_rel;
62      double ftol_abs;
63      double xtol_rel;
64      const double *xtol_abs;
65      int nevals, maxeval;
66      double maxtime, start;
67 } nlopt_stopping;
68 extern int nlopt_stop_f(const nlopt_stopping *stop, double f, double oldf);
69 extern int nlopt_stop_ftol(const nlopt_stopping *stop, double f, double oldf);
70 extern int nlopt_stop_x(const nlopt_stopping *stop, 
71                         const double *x, const double *oldx);
72 extern int nlopt_stop_xs(const nlopt_stopping *stop, 
73                          const double *xs, const double *oldxs,
74                          const double *scale_min, const double *scale_max);
75 extern int nlopt_stop_evals(const nlopt_stopping *stop);
76 extern int nlopt_stop_time(const nlopt_stopping *stop);
77 extern int nlopt_stop_evalstime(const nlopt_stopping *stop);
78
79 #ifdef __cplusplus
80 }  /* extern "C" */
81 #endif /* __cplusplus */
82
83 #endif