-/* Copyright (c) 2007-2008 Massachusetts Institute of Technology
+/* Copyright (c) 2007-2014 Massachusetts Institute of Technology
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-#include <math.h>
-#include <float.h>
-
-#include "nlopt.h"
-#include "nlopt-util.h"
+#include "nlopt-internal.h"
/*************************************************************************/
-int nlopt_isinf(double x) {
- return fabs(x) >= HUGE_VAL * 0.99
-#ifdef HAVE_ISINF
- || isinf(x)
-#endif
- ;
-}
-/*************************************************************************/
-
-void nlopt_version(int *major, int *minor, int *bugfix)
+void NLOPT_STDCALL nlopt_version(int *major, int *minor, int *bugfix)
{
*major = MAJOR_VERSION;
*minor = MINOR_VERSION;
"StoGO (NOT COMPILED)",
"StoGO randomized (NOT COMPILED)",
#endif
-#ifdef WITH_NOCEDAL_LBFGS
- "original NON-FREE L-BFGS code by Nocedal et al. (local, deriv.-based)",
-#else
- "original NON-FREE L-BFGS code by Nocedal et al. (NOT COMPILED)",
-#endif
+ "original L-BFGS code by Nocedal et al. (NOT COMPILED)",
"Limited-memory BFGS (L-BFGS) (local, derivative-based)",
"Principal-axis, praxis (local, no-derivative)",
"Limited-memory variable-metric, rank 1 (local, derivative-based)",
"Augmented Lagrangian method for equality constraints (local, derivative)",
"BOBYQA bound-constrained optimization via quadratic models (local, no-derivative)",
"ISRES evolutionary constrained optimization (global, no-derivative)",
+ "Augmented Lagrangian method (needs sub-algorithm)",
+ "Augmented Lagrangian method for equality constraints (needs sub-algorithm)",
+ "Multi-level single-linkage (MLSL), random (global, needs sub-algorithm)",
+ "Multi-level single-linkage (MLSL), quasi-random (global, needs sub-algorithm)",
+ "Sequential Quadratic Programming (SQP) (local, derivative)",
+ "CCSA (Conservative Convex Separable Approximations) with simple quadratic approximations (local, derivative)",
+ "ESCH evolutionary strategy"
};
-const char *nlopt_algorithm_name(nlopt_algorithm a)
+const char * NLOPT_STDCALL nlopt_algorithm_name(nlopt_algorithm a)
{
if (((int) a) < 0 || a >= NLOPT_NUM_ALGORITHMS) return "UNKNOWN";
return nlopt_algorithm_names[a];
}
/*************************************************************************/
+/* get thread id, if possible, for use in nlopt_srand_time to ensure that
+ different threads have a different default seed even if they are called
+ simultaneously */
-int nlopt_srand_called = 0;
-void nlopt_srand(unsigned long seed) {
+#if defined(_WIN32) || defined(__WIN32__)
+# include <windows.h>
+# define my_gettid GetCurrentThreadId
+#elif defined(HAVE_GETTID_SYSCALL)
+# include <unistd.h>
+# include <sys/syscall.h>
+# define my_gettid() syscall(SYS_gettid)
+#elif defined(HAVE_GETPID)
+# include <sys/types.h>
+# include <unistd.h>
+# define my_gettid getpid
+#else
+# define my_gettid() (0)
+#endif
+
+/*************************************************************************/
+
+static THREADLOCAL int nlopt_srand_called = 0;
+void NLOPT_STDCALL nlopt_srand(unsigned long seed) {
nlopt_srand_called = 1;
nlopt_init_genrand(seed);
}
-void nlopt_srand_time() {
- nlopt_srand(nlopt_time_seed());
+void NLOPT_STDCALL nlopt_srand_time(void) {
+ nlopt_srand(nlopt_time_seed() + (unsigned long)my_gettid() * 314159);
+}
+
+void nlopt_srand_time_default(void) {
+ if (!nlopt_srand_called) nlopt_srand_time();
}
/*************************************************************************/