chiark / gitweb /
compile with non-free Nocedal L-BFGS if it is present (mainly for debugging/developme...
authorstevenj <stevenj@alum.mit.edu>
Tue, 29 Jul 2008 02:46:13 +0000 (22:46 -0400)
committerstevenj <stevenj@alum.mit.edu>
Tue, 29 Jul 2008 02:46:13 +0000 (22:46 -0400)
darcs-hash:20080729024613-c8de0-86103f4ebdaed2fc4e18756fb328f046920102a8.gz

Makefile.am
api/Makefile.am
api/nlopt.c
api/nlopt.h
configure.ac
lbfgs/Makefile.am

index 9563690fc8b0e5052f28a40195e2e3a912cf659c..1a3d1b457a3db2f9da7acda9109414971bf2be14 100644 (file)
@@ -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
 
index 4bec3cdb863917ecd30f1f1105e2e19bce3c6183..0823aaa40ad767c6bc2604a0c058666c60d9a392 100644 (file)
@@ -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
index adb5a403b0cbdfa1ad2ddc7c2cc9abfff7587750..a39010c3fdd52856b546e3dc7ce2b3987e9eb062 100644 (file)
@@ -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);
 
index a6f129b0702b417fd05fd346e490bc6b2544e250..b6e19a5bd8e4ddf3dc9ae3ef0cb7b58a490c3070 100644 (file)
@@ -38,6 +38,8 @@ typedef enum {
      NLOPT_GD_STOGO,
      NLOPT_GD_STOGO_RAND,
 
+     NLOPT_LD_LBFGS_NOCEDAL,
+
      NLOPT_LD_LBFGS,
 
      NLOPT_LN_PRAXIS,
index 92f1859d60fd33fa223c19d0dfb1cdc2dbd1a39d..8a3b8a196a18c2f0f69b7410657d704800ef7d38 100644 (file)
@@ -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
index a8db96387f1356b2bcbb2ee5d9a8602ba68ee045..42055bb44ae64137c6475fbd36552f5830bef64a 100644 (file)
@@ -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