1 /* Copyright (c) 2007-2010 Massachusetts Institute of Technology
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:
11 * The above copyright notice and this permission notice shall be
12 * included in all copies or substantial portions of the Software.
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.
26 #include "nlopt-internal.h"
28 /*************************************************************************/
30 int nlopt_isinf(double x) {
31 return fabs(x) >= HUGE_VAL * 0.99
37 /*************************************************************************/
39 void NLOPT_STDCALL nlopt_version(int *major, int *minor, int *bugfix)
41 *major = MAJOR_VERSION;
42 *minor = MINOR_VERSION;
43 *bugfix = BUGFIX_VERSION;
46 /*************************************************************************/
48 static const char nlopt_algorithm_names[NLOPT_NUM_ALGORITHMS][256] = {
49 "DIRECT (global, no-derivative)",
50 "DIRECT-L (global, no-derivative)",
51 "Randomized DIRECT-L (global, no-derivative)",
52 "Unscaled DIRECT (global, no-derivative)",
53 "Unscaled DIRECT-L (global, no-derivative)",
54 "Unscaled Randomized DIRECT-L (global, no-derivative)",
55 "Original DIRECT version (global, no-derivative)",
56 "Original DIRECT-L version (global, no-derivative)",
58 "StoGO (global, derivative-based)",
59 "StoGO with randomized search (global, derivative-based)",
61 "StoGO (NOT COMPILED)",
62 "StoGO randomized (NOT COMPILED)",
64 #ifdef WITH_NOCEDAL_LBFGS
65 "original NON-FREE L-BFGS code by Nocedal et al. (local, deriv.-based)",
67 "original NON-FREE L-BFGS code by Nocedal et al. (NOT COMPILED)",
69 "Limited-memory BFGS (L-BFGS) (local, derivative-based)",
70 "Principal-axis, praxis (local, no-derivative)",
71 "Limited-memory variable-metric, rank 1 (local, derivative-based)",
72 "Limited-memory variable-metric, rank 2 (local, derivative-based)",
73 "Truncated Newton (local, derivative-based)",
74 "Truncated Newton with restarting (local, derivative-based)",
75 "Preconditioned truncated Newton (local, derivative-based)",
76 "Preconditioned truncated Newton with restarting (local, derivative-based)",
77 "Controlled random search (CRS2) with local mutation (global, no-derivative)",
78 "Multi-level single-linkage (MLSL), random (global, no-derivative)",
79 "Multi-level single-linkage (MLSL), random (global, derivative)",
80 "Multi-level single-linkage (MLSL), quasi-random (global, no-derivative)",
81 "Multi-level single-linkage (MLSL), quasi-random (global, derivative)",
82 "Method of Moving Asymptotes (MMA) (local, derivative)",
83 "COBYLA (Constrained Optimization BY Linear Approximations) (local, no-derivative)",
84 "NEWUOA unconstrained optimization via quadratic models (local, no-derivative)",
85 "Bound-constrained optimization via NEWUOA-based quadratic models (local, no-derivative)",
86 "Nelder-Mead simplex algorithm (local, no-derivative)",
87 "Sbplx variant of Nelder-Mead (re-implementation of Rowan's Subplex) (local, no-derivative)",
88 "Augmented Lagrangian method (local, no-derivative)",
89 "Augmented Lagrangian method (local, derivative)",
90 "Augmented Lagrangian method for equality constraints (local, no-derivative)",
91 "Augmented Lagrangian method for equality constraints (local, derivative)",
92 "BOBYQA bound-constrained optimization via quadratic models (local, no-derivative)",
93 "ISRES evolutionary constrained optimization (global, no-derivative)",
94 "Augmented Lagrangian method (needs sub-algorithm)",
95 "Augmented Lagrangian method for equality constraints (needs sub-algorithm)",
96 "Multi-level single-linkage (MLSL), random (global, needs sub-algorithm)",
97 "Multi-level single-linkage (MLSL), quasi-random (global, needs sub-algorithm)",
98 "Sequential Quadratic Programming (SQP) (local, derivative)",
101 const char *nlopt_algorithm_name(nlopt_algorithm a)
103 if (((int) a) < 0 || a >= NLOPT_NUM_ALGORITHMS) return "UNKNOWN";
104 return nlopt_algorithm_names[a];
107 /*************************************************************************/
108 /* get thread id, if possible, for use in nlopt_srand_time to ensure that
109 different threads have a different default seed even if they are called
112 #if defined(_WIN32) || defined(__WIN32__)
113 # include <windows.h>
114 # define my_gettid GetCurrentThreadId
115 #elif defined(HAVE_GETTID_SYSCALL)
117 # include <sys/syscall.h>
118 # define my_gettid() syscall(SYS_gettid)
119 #elif defined(HAVE_GETPID)
120 # include <sys/types.h>
122 # define my_gettid getpid
124 # define my_gettid() (0)
127 /*************************************************************************/
129 static THREADLOCAL int nlopt_srand_called = 0;
130 void NLOPT_STDCALL nlopt_srand(unsigned long seed) {
131 nlopt_srand_called = 1;
132 nlopt_init_genrand(seed);
135 void NLOPT_STDCALL nlopt_srand_time(void) {
136 nlopt_srand(nlopt_time_seed() + my_gettid() * 314159);
139 void nlopt_srand_time_default(void) {
140 if (!nlopt_srand_called) nlopt_srand_time();
143 /*************************************************************************/