Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement C++ style functors as targets for objectives #457

Merged
merged 10 commits into from
Aug 17, 2022
37 changes: 25 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,10 @@ endif ()
if (NLOPT_CXX OR NLOPT_PYTHON OR NLOPT_GUILE OR NLOPT_OCTAVE)
check_cxx_symbol_exists (__cplusplus ciso646 SYSTEM_HAS_CXX)
if (SYSTEM_HAS_CXX)
check_cxx_compiler_flag ("-std=c++11" SUPPORTS_STDCXX11)
if (SUPPORTS_STDCXX11)
set (CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")
if (NLOPT_CXX)
set (NLOPT_CXX11 ON)
endif ()
set (CMAKE_CXX_STANDARD 11) # set the standard to C++11 but do not require it

if (NLOPT_CXX)
set (CMAKE_CXX_STANDARD_REQUIRED ON) # if we build C++ API, we do need C++11
endif ()
else()
message (FATAL_ERROR "The compiler doesn't support CXX.")
Expand Down Expand Up @@ -221,12 +219,27 @@ set (NLOPT_SOURCES
)

if (NLOPT_CXX)
list (APPEND NLOPT_SOURCES src/algs/stogo/global.cc src/algs/stogo/linalg.cc src/algs/stogo/local.cc src/algs/stogo/stogo.cc src/algs/stogo/tools.cc
src/algs/stogo/global.h src/algs/stogo/linalg.h src/algs/stogo/local.h src/algs/stogo/stogo_config.h src/algs/stogo/stogo.h src/algs/stogo/tools.h)
endif ()
if (NLOPT_CXX11)
list (APPEND NLOPT_SOURCES src/algs/ags/data_types.hpp src/algs/ags/evolvent.hpp src/algs/ags/evolvent.cc src/algs/ags/solver.hpp src/algs/ags/solver.cc
src/algs/ags/local_optimizer.hpp src/algs/ags/local_optimizer.cc src/algs/ags/ags.h src/algs/ags/ags.cc)
list (APPEND NLOPT_SOURCES
src/algs/stogo/global.cc
src/algs/stogo/linalg.cc
src/algs/stogo/local.cc
src/algs/stogo/stogo.cc
src/algs/stogo/tools.cc
src/algs/stogo/global.h
src/algs/stogo/linalg.h
src/algs/stogo/local.h
src/algs/stogo/stogo_config.h
src/algs/stogo/stogo.h
src/algs/stogo/tools.h
src/algs/ags/data_types.hpp
src/algs/ags/evolvent.hpp
src/algs/ags/evolvent.cc
src/algs/ags/solver.hpp
src/algs/ags/solver.cc
src/algs/ags/local_optimizer.hpp
src/algs/ags/local_optimizer.cc
src/algs/ags/ags.h
src/algs/ags/ags.cc)
endif ()

install (FILES ${NLOPT_HEADERS} DESTINATION ${RELATIVE_INSTALL_INCLUDE_DIR})
Expand Down
3 changes: 0 additions & 3 deletions nlopt_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,6 @@
/* Define if compiled including C++-based routines */
#cmakedefine NLOPT_CXX

/* Define if compiled including C++11-based routines */
#cmakedefine NLOPT_CXX11

/* Define to empty if `const' does not conform to ANSI C. */
#undef const

Expand Down
7 changes: 2 additions & 5 deletions src/api/general.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ static const char nlopt_algorithm_names[NLOPT_NUM_ALGORITHMS][256] = {
#ifdef NLOPT_CXX
"StoGO (global, derivative-based)",
"StoGO with randomized search (global, derivative-based)",
"AGS (global, no-derivative)"
#else
"StoGO (NOT COMPILED)",
"StoGO randomized (NOT COMPILED)",
"AGS (NOT COMPILED)"
Comment on lines +49 to +53
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The missing , at the end of these items cause them to be merged with the item after which causes there to be one too few items in this array.

#endif
"original L-BFGS code by Nocedal et al. (NOT COMPILED)",
"Limited-memory BFGS (L-BFGS) (local, derivative-based)",
Expand Down Expand Up @@ -83,11 +85,6 @@ static const char nlopt_algorithm_names[NLOPT_NUM_ALGORITHMS][256] = {
"Sequential Quadratic Programming (SQP) (local, derivative)",
"CCSA (Conservative Convex Separable Approximations) with simple quadratic approximations (local, derivative)",
"ESCH evolutionary strategy",
#ifdef NLOPT_CXX11
"AGS (global, no-derivative)"
#else
"AGS (NOT COMPILED)"
#endif
Comment on lines -86 to -90
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR broke nlopt_algorithm_name as it relied on this ordering that was changed...

};

const char *NLOPT_STDCALL nlopt_algorithm_name(nlopt_algorithm a)
Expand Down
Loading