From 6e146b4fc627ccc6b3f6ee0d08d197fb4e24baa2 Mon Sep 17 00:00:00 2001 From: "Steven G. Johnson" Date: Tue, 18 Feb 2014 11:51:04 -0500 Subject: [PATCH] fix #12 --- CMakeLists.txt | 153 ++++++++++++++++++++++++++++++++++++++++++++ config.cmake.h.in | 159 ++++++++++++++++++++++++++++++++++++++++++++++ esch/esch.c | 12 ++-- 3 files changed, 318 insertions(+), 6 deletions(-) create mode 100644 CMakeLists.txt create mode 100644 config.cmake.h.in diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..5e667b5 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,153 @@ +PROJECT(NLOPT) + +#============================================================================== +# NLOPT CMake file +# +# NLopt is a free/open-source library for nonlinear optimization, providing +# a common interface for a number of different free optimization routines +# available online as well as original implementations of various other +# algorithms +# WEBSITE: http://ab-initio.mit.edu/wiki/index.php/NLopt +# AUTHOR: Steven G. Johnson +# +# This CMakeLists.txt file was created to compile NLOPT with the CMAKE utility. +# Benoit Scherrer, 2010 CRL, Harvard Medical School +# Copyright (c) 2008-2009 Children's Hospital Boston +#============================================================================== + + +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +INCLUDE(CheckIncludeFiles) +INCLUDE(CheckFunctionExists) +INCLUDE(CheckTypeSize) + + +#============================================================================== +# COMPILATION CHECKINGS and CONFIGURATION GENERATION +#============================================================================== +CHECK_INCLUDE_FILES( unistd.h HAVE_UNISTD_H) +CHECK_INCLUDE_FILES( string.h HAVE_STRING_H) +CHECK_INCLUDE_FILES( strings.h HAVE_STRINGS_H) +CHECK_INCLUDE_FILES( sys/stat.h HAVE_SYS_STAT_H) +CHECK_INCLUDE_FILES( inttypes.h HAVE_INTTYPES_H) +CHECK_INCLUDE_FILES( memory.h HAVE_MEMORY_H) +CHECK_INCLUDE_FILES( stdlib.h HAVE_STDLIB_H) +CHECK_INCLUDE_FILES( stdint.h HAVE_STDINT_H) + +CHECK_INCLUDE_FILES( sys/types.h HAVE_SYS_TYPES_H) +CHECK_INCLUDE_FILES( sys/types.h HAVE_SYS_TYPES_H) +CHECK_INCLUDE_FILES( sys/types.h HAVE_SYS_TYPES_H) + +CHECK_FUNCTION_EXISTS( isinf HAVE_ISINF) +CHECK_FUNCTION_EXISTS( isinf HAVE_ISNAN) +CHECK_FUNCTION_EXISTS( gettimeofday HAVE_GETTIMEOFDAY) +CHECK_FUNCTION_EXISTS( qsort_r HAVE_QSORT_R) +CHECK_FUNCTION_EXISTS( time HAVE_TIME) +CHECK_FUNCTION_EXISTS( copysign HAVE_COPYSIGN) + +CHECK_TYPE_SIZE(uint32_t UINT32_T) +IF(NOT HAVE_UINT32_T) + IF(MSVC) + SET(uint32_t "unsigned int") + SET(SIZEOF_UNSIGNED_INT 4) + ENDIF(MSVC) +ENDIF(NOT HAVE_UINT32_T) + +#============================================================================== +# LOOK FOR THE VERSION NUMBER IN configure.ac +#============================================================================== + +FILE( READ configure.ac CONFIG_AUTOMAKE ) + +STRING( REGEX MATCH "AC_INIT\\(nlopt, ([0-9]+\\.[0-9]+\\.?[0-9]*)" NLOPT_AUTOMAKE_LINE_VERSION "${CONFIG_AUTOMAKE}") + +#--------------------------------- +# If version matches 'X.X.X' +#--------------------------------- +IF(${NLOPT_AUTOMAKE_LINE_VERSION} MATCHES ".*[0-9]+\\.[0-9]+\\.[0-9]+") + STRING( REGEX REPLACE ".*([0-9]+)\\.[0-9]+\\.[0-9]*.*" "\\1" NLOPT_MAJOR_VERSION "${NLOPT_AUTOMAKE_LINE_VERSION}") + STRING( REGEX REPLACE ".*[0-9]+\\.([0-9]+)\\.[0-9]*.*" "\\1" NLOPT_MINOR_VERSION "${NLOPT_AUTOMAKE_LINE_VERSION}") + STRING( REGEX REPLACE ".*[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" NLOPT_BUGFIX_VERSION "${NLOPT_AUTOMAKE_LINE_VERSION}") +#--------------------------------- +# Else (consider that version matches 'X.X') +#--------------------------------- +ELSE(${NLOPT_AUTOMAKE_LINE_VERSION} MATCHES ".*[0-9]+\\.[0-9]+\\.[0-9]+") + STRING( REGEX REPLACE ".*([0-9]+)\\.[0-9]+.*" "\\1" NLOPT_MAJOR_VERSION "${NLOPT_AUTOMAKE_LINE_VERSION}") + STRING( REGEX REPLACE ".*[0-9]+\\.([0-9]+).*" "\\1" NLOPT_MINOR_VERSION "${NLOPT_AUTOMAKE_LINE_VERSION}") + SET (NLOPT_BUGFIX_VERSION "0") +ENDIF(${NLOPT_AUTOMAKE_LINE_VERSION} MATCHES ".*[0-9]+\\.[0-9]+\\.[0-9]+") + +MESSAGE(STATUS "NLOPT: Version number ${NLOPT_MAJOR_VERSION}.${NLOPT_MINOR_VERSION}.${NLOPT_BUGFIX_VERSION} found in configure.ac" ) + + +#============================================================================== +# CREATE config.h +#============================================================================== + +CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/config.cmake.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h IMMEDIATE ) + + +#============================================================================== +# INCLUDE DIRECTORIES +#============================================================================== +SET(${INCLUDE_DIRECTORIES} "") +INCLUDE_DIRECTORIES ( + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_BINARY_DIR} + stogo + util + direct + cdirect + praxis + luksan + crs + mlsl + mma + cobyla + newuoa + neldermead + auglag + bobyqa + isres + slsqp + esch + api ) + + +#============================================================================== +# nlopt LIBRARY TARGET (SHARED OR STATIC) +#============================================================================== + +SET ( NLOPT_SOURCES + direct/DIRect.c direct/direct_wrap.c direct/DIRserial.c direct/DIRsubrout.c direct/direct-internal.h direct/direct.h + cdirect/cdirect.c cdirect/hybrid.c cdirect/cdirect.h + praxis/praxis.c praxis/praxis.h + luksan/plis.c luksan/plip.c luksan/pnet.c luksan/mssubs.c luksan/pssubs.c luksan/luksan.h + crs/crs.c crs/crs.h + mlsl/mlsl.c mlsl/mlsl.h + mma/mma.c mma/mma.h mma/ccsa_quadratic.c + cobyla/cobyla.c cobyla/cobyla.h + newuoa/newuoa.c newuoa/newuoa.h + neldermead/nldrmd.c neldermead/neldermead.h neldermead/sbplx.c + auglag/auglag.c auglag/auglag.h + bobyqa/bobyqa.c bobyqa/bobyqa.h + isres/isres.c isres/isres.h + slsqp/slsqp.c slsqp/slsqp.h + esch/esch.c esch/esch.h + api/general.c api/options.c api/optimize.c api/deprecated.c api/nlopt-internal.h api/nlopt.h api/f77api.c api/f77funcs.h api/f77funcs_.h api/nlopt.hpp api/nlopt-in.hpp + util/mt19937ar.c util/sobolseq.c util/soboldata.h util/timer.c util/stop.c util/nlopt-util.h util/redblack.c util/redblack.h util/qsort_r.c util/rescale.c + stogo/global.cc stogo/linalg.cc stogo/local.cc stogo/stogo.cc stogo/tools.cc stogo/global.h stogo/linalg.h stogo/local.h stogo/stogo_config.h stogo/stogo.h stogo/tools.h + ) + +OPTION(NLOPT_BUILD_SHARED "Build NLOPT as a shared library" OFF ) + +IF(NLOPT_BUILD_SHARED) + ADD_DEFINITIONS(-DNLOPT_DLL) + ADD_DEFINITIONS(-DNLOPT_DLL_EXPORT ) + ADD_LIBRARY (nlopt SHARED ${NLOPT_SOURCES} ) +ELSE(NLOPT_BUILD_SHARED) + ADD_LIBRARY (nlopt STATIC ${NLOPT_SOURCES} ) +ENDIF(NLOPT_BUILD_SHARED) + + + diff --git a/config.cmake.h.in b/config.cmake.h.in new file mode 100644 index 0000000..0dce2db --- /dev/null +++ b/config.cmake.h.in @@ -0,0 +1,159 @@ +/*============================================================================== +# NLOPT CMake configuration file +# +# NLopt is a free/open-source library for nonlinear optimization, providing +# a common interface for a number of different free optimization routines +# available online as well as original implementations of various other +# algorithms +# WEBSITE: http://ab-initio.mit.edu/wiki/index.php/NLopt +# AUTHOR: Steven G. Johnson +# +# This config.cmake.h.in file was created to compile NLOPT with the CMAKE utility. +# Benoit Scherrer, 2010 CRL, Harvard Medical School +# Copyright (c) 2008-2009 Children's Hospital Boston +# +# Minor changes to the source was applied to make possible the compilation with +# Cmake under Linux/Win32 +#============================================================================*/ + +/* Bugfix version number. */ +#define BUGFIX_VERSION @NLOPT_BUGFIX_VERSION@ + +/* Define to enable extra debugging code. */ +#undef DEBUG + +/* Define to 1 if you have the `BSDgettimeofday' function. */ +#undef HAVE_BSDGETTIMEOFDAY + +/* Define to 1 if you have the header file. */ +#undef HAVE_DLFCN_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_GETOPT_H + +/* Define to 1 if you have the `getpid' function. */ +#undef HAVE_GETPID + +/* Define if syscall(SYS_gettid) available. */ +#undef HAVE_GETTID_SYSCALL + +/* Define to 1 if you have the `gettimeofday' function. */ +#cmakedefine HAVE_GETTIMEOFDAY + +/* Define if the copysign function/macro is available. */ +#cmakedefine HAVE_COPYSIGN + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_INTTYPES_H + +/* Define if the isinf() function/macro is available. */ +#cmakedefine HAVE_ISINF + +/* Define if the isnan() function/macro is available. */ +#cmakedefine HAVE_ISNAN + +/* Define to 1 if you have the `m' library (-lm). */ +#undef HAVE_LIBM + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_MEMORY_H + +/* Define to 1 if you have the `qsort_r' function. */ +#cmakedefine HAVE_QSORT_R + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_STDINT_H + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_STDLIB_H + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_STRINGS_H + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_STRING_H + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_STAT_H + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_TYPES_H + +/* Define to 1 if you have the `time' function. */ +#cmakedefine HAVE_TIME + +/* Define to 1 if the system has the type `uint32_t'. */ +#cmakedefine HAVE_UINT32_T + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_UNISTD_H + +/* Define to the sub-directory in which libtool stores uninstalled libraries. + */ +#undef LT_OBJDIR + +/* Major version number. */ +#define MAJOR_VERSION @NLOPT_MAJOR_VERSION@ + +/* Minor version number. */ +#define MINOR_VERSION @NLOPT_MINOR_VERSION@ + +/* Name of package */ +#undef PACKAGE + +/* Define to the address where bug reports for this package should be sent. */ +#undef PACKAGE_BUGREPORT + +/* Define to the full name of this package. */ +#undef PACKAGE_NAME + +/* Define to the full name and version of this package. */ +#undef PACKAGE_STRING + +/* Define to the one symbol short name of this package. */ +#undef PACKAGE_TARNAME + +/* Define to the home page for this package. */ +#undef PACKAGE_URL + +/* Define to the version of this package. */ +#undef PACKAGE_VERSION + +/* replacement for broken HUGE_VAL macro, if needed */ +#undef REPLACEMENT_HUGE_VAL + +/* The size of `unsigned int', as computed by sizeof. */ +#define SIZEOF_UNSIGNED_INT @SIZEOF_UNSIGNED_INT@ + +/* The size of `unsigned long', as computed by sizeof. */ +#undef SIZEOF_UNSIGNED_LONG + +/* Define to 1 if you have the ANSI C header files. */ +#undef STDC_HEADERS + +/* Define to C thread-local keyword, or to nothing if this is not supported in + your compiler. */ +#define THREADLOCAL + +/* Define to 1 if you can safely include both and . */ +#undef TIME_WITH_SYS_TIME + +/* Version number of package */ +#undef VERSION + +/* Define if compiled including C++-based routines */ +#undef WITH_CXX + +/* Define if we have the non-free Nocedal LBFGS code */ +#undef WITH_NOCEDAL + +/* Define to empty if `const' does not conform to ANSI C. */ +#undef const + +/* Define to `__inline__' or `__inline' if that's what the C compiler + calls it, or to nothing if 'inline' is not supported under any name. */ +#ifndef __cplusplus +#undef inline +#endif + + diff --git a/esch/esch.c b/esch/esch.c index cc4952d..e2c01d7 100644 --- a/esch/esch.c +++ b/esch/esch.c @@ -32,18 +32,18 @@ static double randcauchy(const double params[7]) { double valor; double min = params[1], max = params[2], mi = params[3], t = params[4], band = params[5]; - limit_inf = mi - (band/2); - limit_sup = mi + (band/2); + limit_inf = mi - (band*0.5); + limit_sup = mi + (band*0.5); do { na_unif = nlopt_urand(0,1); // ran2(0,1); - cauchy_mit = t*tan((na_unif-(1/2))*M_PI) + mi; + cauchy_mit = t*tan((na_unif-0.5)*3.14159265358979323846) + mi; } while ( (cauchy_mitlimit_sup) ); if (cauchy_mit < 0) cauchy_mit = -cauchy_mit; else - cauchy_mit = cauchy_mit + (band/2); - valor = (cauchy_mit*100/band)/100; + cauchy_mit = cauchy_mit + (band*0.5); + valor = cauchy_mit/band; valor = min+(max-min)*valor; return valor; } @@ -57,7 +57,7 @@ typedef struct IndividualStructure { } Individual; static int CompareIndividuals(void *unused, const void *a_, const void *b_) { - (void) unused; + // (void) unused; const Individual *a = (const Individual *) a_; const Individual *b = (const Individual *) b_; return a->fitness < b->fitness ? -1 : (a->fitness > b->fitness ? +1 : 0); -- 2.30.2