From bdcc042def44b035d13d9fb2b44fe56cf89a3db4 Mon Sep 17 00:00:00 2001 From: stevenj Date: Mon, 28 Jul 2008 22:46:13 -0400 Subject: [PATCH] compile with non-free Nocedal L-BFGS if it is present (mainly for debugging/development purposes) darcs-hash:20080729024613-c8de0-86103f4ebdaed2fc4e18756fb328f046920102a8.gz --- Makefile.am | 8 ++++++-- api/Makefile.am | 2 +- api/nlopt.c | 42 ++++++++++++++++++++++++++++++++++++++++++ api/nlopt.h | 2 ++ configure.ac | 9 +++++++++ lbfgs/Makefile.am | 7 ++++++- 6 files changed, 66 insertions(+), 4 deletions(-) diff --git a/Makefile.am b/Makefile.am index 9563690..1a3d1b4 100644 --- a/Makefile.am +++ b/Makefile.am @@ -8,12 +8,16 @@ CXX_DIRS = stogo CXX_LIBS = stogo/libstogo.la endif -SUBDIRS= util subplex direct cdirect $(CXX_DIRS) praxis luksan crs mlsl api . octave test +SUBDIRS= util subplex direct cdirect $(CXX_DIRS) praxis luksan crs mlsl lbfgs api . octave test EXTRA_DIST=COPYRIGHT autogen.sh nlopt.pc.in m4 +if WITH_NOCEDAL +NOCEDAL_LBFGS=lbfgs/liblbfgs.la +endif + libnlopt_la_SOURCES = libnlopt_la_LIBADD = subplex/libsubplex.la direct/libdirect.la \ -cdirect/libcdirect.la $(CXX_LIBS) praxis/libpraxis.la \ +cdirect/libcdirect.la $(CXX_LIBS) praxis/libpraxis.la $(NOCEDAL_LBFGS) \ luksan/libluksan.la crs/libcrs.la mlsl/libmlsl.la api/libapi.la \ util/libutil.la diff --git a/api/Makefile.am b/api/Makefile.am index 4bec3cd..0823aaa 100644 --- a/api/Makefile.am +++ b/api/Makefile.am @@ -1,4 +1,4 @@ -AM_CPPFLAGS = -I$(top_srcdir)/cdirect -I$(top_srcdir)/direct -I$(top_srcdir)/stogo -I$(top_srcdir)/subplex -I$(top_srcdir)/praxis -I$(top_srcdir)/luksan -I$(top_srcdir)/crs -I$(top_srcdir)/mlsl -I$(top_srcdir)/util +AM_CPPFLAGS = -I$(top_srcdir)/cdirect -I$(top_srcdir)/direct -I$(top_srcdir)/stogo -I$(top_srcdir)/subplex -I$(top_srcdir)/praxis -I$(top_srcdir)/lbfgs -I$(top_srcdir)/luksan -I$(top_srcdir)/crs -I$(top_srcdir)/mlsl -I$(top_srcdir)/util include_HEADERS = nlopt.h noinst_LTLIBRARIES = libapi.la diff --git a/api/nlopt.c b/api/nlopt.c index adb5a40..a39010c 100644 --- a/api/nlopt.c +++ b/api/nlopt.c @@ -57,6 +57,11 @@ static const char nlopt_algorithm_names[NLOPT_NUM_ALGORITHMS][256] = { #else "StoGO (NOT COMPILED)", "StoGO randomized (NOT COMPILED)", +#endif +#ifdef WITH_NOCEDAL_LBFGS + "original NON-FREE L-BFGS implementation by Nocedal et al. (local, deriv.-based)" +#else + "original NON-FREE L-BFGS implementation by Nocedal et al. (NOT COMPILED)" #endif "Low-storage BFGS (LBFGS) (local, derivative-based)", "Principal-axis, praxis (local, no-derivative)", @@ -135,6 +140,10 @@ static double f_direct(int n, const double *x, int *undefined, void *data_) #include "cdirect.h" +#ifdef WITH_NOCEDAL +# include "l-bfgs-b.h" +#endif + #include "luksan.h" #include "crs.h" @@ -325,6 +334,39 @@ static nlopt_result nlopt_minimize_( &stop, minf); } +#ifdef WITH_NOCEDAL + case NLOPT_LD_LBFGS_NOCEDAL: { + int iret, *nbd = (int *) malloc(sizeof(int) * n); + if (!nbd) return NLOPT_OUT_OF_MEMORY; + for (i = 0; i < n; ++i) { + int linf = my_isinf(lb[i]) && lb[i] < 0; + int uinf = my_isinf(ub[i]) && ub[i] > 0; + nbd[i] = linf && uinf ? 0 : (uinf ? 1 : (linf ? 3 : 2)); + } + iret = lbfgsb_minimize(n, f, f_data, x, nbd, lb, ub, + MIN(n, 5), 0.0, ftol_rel, + xtol_abs ? *xtol_abs : xtol_rel, + maxeval); + free(nbd); + if (iret <= 0) { + switch (iret) { + case -1: return NLOPT_INVALID_ARGS; + case -2: default: return NLOPT_FAILURE; + } + } + else { + *minf = f(n, x, NULL, f_data); + switch (iret) { + case 5: return NLOPT_MAXEVAL_REACHED; + case 2: return NLOPT_XTOL_REACHED; + case 1: return NLOPT_FTOL_REACHED; + default: return NLOPT_SUCCESS; + } + } + break; + } +#endif + case NLOPT_LD_LBFGS: return luksan_plis(n, f, f_data, lb, ub, x, minf, &stop); diff --git a/api/nlopt.h b/api/nlopt.h index a6f129b..b6e19a5 100644 --- a/api/nlopt.h +++ b/api/nlopt.h @@ -38,6 +38,8 @@ typedef enum { NLOPT_GD_STOGO, NLOPT_GD_STOGO_RAND, + NLOPT_LD_LBFGS_NOCEDAL, + NLOPT_LD_LBFGS, NLOPT_LN_PRAXIS, diff --git a/configure.ac b/configure.ac index 92f1859..8a3b8a1 100644 --- a/configure.ac +++ b/configure.ac @@ -62,6 +62,14 @@ if test "$ok" = "yes"; then fi AC_MSG_RESULT(${ok}) +dnl ----------------------------------------------------------------------- + +test -r $srcdir/lbfgs/ap.cpp && test -r $srcdir/lbfgs/ap.h && test -r $srcdir/lbfgs/l-bfgs-b.cpp && test -r $srcdir/lbfgs/l-bfgs-b.h && have_lbfgs=yes +AM_CONDITIONAL(WITH_NOCEDAL, test -n "$have_lbfgs") +if test -n "$have_lbfgs"; then + AC_DEFINE(WITH_NOCEDAL, [1], [Define if we have the non-free Nocedal LBFGS code]) +fi + dnl ----------------------------------------------------------------------- dnl Compiling Octave plug-in @@ -188,6 +196,7 @@ AC_CONFIG_FILES([ stogo/Makefile subplex/Makefile praxis/Makefile + lbfgs/Makefile luksan/Makefile crs/Makefile mlsl/Makefile diff --git a/lbfgs/Makefile.am b/lbfgs/Makefile.am index a8db963..42055bb 100644 --- a/lbfgs/Makefile.am +++ b/lbfgs/Makefile.am @@ -1,4 +1,9 @@ +# non-free, so we cannot distribute with the nlopt library, hence "nodist" + +if WITH_NOCEDAL noinst_LTLIBRARIES = liblbfgs.la -liblbfgs_la_SOURCES = ap.cpp ap.h l-bfgs-b.cpp l-bfgs-b.h +endif + +nodist_liblbfgs_la_SOURCES = ap.cpp ap.h l-bfgs-b.cpp l-bfgs-b.h EXTRA_DIST = README -- 2.30.2