From: stevenj Date: Tue, 15 Jun 2010 22:25:04 +0000 (-0400) Subject: add NLOPT_G_MLSL variants that require local_opt to be specified X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=ec4a097e0abf006fc07973d6ac5c4aa0708728a1;p=nlopt.git add NLOPT_G_MLSL variants that require local_opt to be specified darcs-hash:20100615222504-c8de0-5f416d50c5d8431fe641785cc1458a78178b13db.gz --- diff --git a/api/Makefile.am b/api/Makefile.am index 7a9f027..4f169f7 100644 --- a/api/Makefile.am +++ b/api/Makefile.am @@ -15,10 +15,10 @@ if MAINTAINER_MODE nlopt.f: nlopt.h rm -f $@ - (i=0; egrep 'NLOPT_[LG][DN]|NLOPT_AUGLAG' $(srcdir)/nlopt.h | tr -d ' =0,' | while read n; do echo " integer $$n"; echo " parameter ($$n=$$i)"; i=`expr $$i + 1`; done; tail -n +`grep -n enum $(srcdir)/nlopt.h |cut -d: -f1 |tail -n 1` $(srcdir)/nlopt.h | grep NLOPT | egrep -v 'EXTERN|DEPRECATED|MINF_MAX' | cut -d, -f1 | tr -d ' ' | perl -pe 's/([A-Za-z0-9_]+)=([-+0-9]+)/ integer \1\n parameter (\1=\2)/') > $@ + (i=0; egrep 'NLOPT_[LG][DN]|NLOPT_AUGLAG|NLOPT_G_MLSL' $(srcdir)/nlopt.h | tr -d ' =0,' | while read n; do echo " integer $$n"; echo " parameter ($$n=$$i)"; i=`expr $$i + 1`; done; tail -n +`grep -n enum $(srcdir)/nlopt.h |cut -d: -f1 |tail -n 1` $(srcdir)/nlopt.h | grep NLOPT | egrep -v 'EXTERN|DEPRECATED|MINF_MAX' | cut -d, -f1 | tr -d ' ' | perl -pe 's/([A-Za-z0-9_]+)=([-+0-9]+)/ integer \1\n parameter (\1=\2)/') > $@ nlopt.hpp: nlopt.h nlopt-in.hpp rm -f $@ - (n=`grep -n GEN_ENUMS_HERE nlopt-in.hpp | cut -d: -f1`; head -n $$n $(srcdir)/nlopt-in.hpp; echo " enum algorithm {"; egrep 'NLOPT_[LG][DN]|NLOPT_AUGLAG|NLOPT_NUM_ALGORITHMS' $(srcdir)/nlopt.h | sed 's/NLOPT_//g'; echo " };"; echo " enum result {"; egrep 'NLOPT_[A-Z_]* =' $(srcdir)/nlopt.h | egrep -v 'NLOPT_[LG][DN]' | sed 's/NLOPT_//g'; echo " };"; tail -n +$$n $(srcdir)/nlopt-in.hpp) > $@ + (n=`grep -n GEN_ENUMS_HERE nlopt-in.hpp | cut -d: -f1`; head -n $$n $(srcdir)/nlopt-in.hpp; echo " enum algorithm {"; egrep 'NLOPT_[LG][DN]|NLOPT_AUGLAG|NLOPT_G_MLSL|NLOPT_NUM_ALGORITHMS' $(srcdir)/nlopt.h | sed 's/NLOPT_//g'; echo " };"; echo " enum result {"; egrep 'NLOPT_[A-Z_]* =' $(srcdir)/nlopt.h | egrep -v 'NLOPT_[LG][DN]' | sed 's/NLOPT_//g'; echo " };"; tail -n +$$n $(srcdir)/nlopt-in.hpp) > $@ endif diff --git a/api/general.c b/api/general.c index b217a89..e892bd9 100644 --- a/api/general.c +++ b/api/general.c @@ -93,6 +93,8 @@ static const char nlopt_algorithm_names[NLOPT_NUM_ALGORITHMS][256] = { "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)", }; const char *nlopt_algorithm_name(nlopt_algorithm a) diff --git a/api/nlopt.3 b/api/nlopt.3 index 3f5eaaf..ec54738 100644 --- a/api/nlopt.3 +++ b/api/nlopt.3 @@ -422,21 +422,17 @@ Global (G) derivative-free (N) optimization using a genetic algorithm handle nonlinear inequality and equality constraints as suggested by Runarsson and Yao. .TP -\fBNLOPT_GD_MLSL_LDS\fR, \fBNLOPT_GN_MLSL_LDS\fR -Global (G) derivative-based (D) or derivative-free (N) optimization -using the multi-level single-linkage (MLSL) algorithm with a -low-discrepancy sequence (LDS). This algorithm executes a quasi-random -(LDS) sequence of local searches, with a clustering heuristic to -avoid multiple local searches for the same local optimum. The local -search uses the derivative/nonderivative algorithm set by -.I nlopt_set_local_optimizer -(currently defaulting to -.I NLOPT_LD_MMA -and -.I NLOPT_LN_COBYLA -for derivative/nonderivative searches, respectively). There are also -two other variants, \fBNLOPT_GD_MLSL\fR and \fBNLOPT_GN_MLSL\fR, which use -pseudo-random numbers (instead of an LDS) as in the original MLSL algorithm. +\fBNLOPT_G_MLSL_LDS\fR, \fBNLOPT_G_MLSL\fR +Global (G) optimization using the multi-level single-linkage (MLSL) +algorithm with a low-discrepancy sequence (LDS) or pseudorandom +numbers, respectively. This algorithm executes a low-discrepancy +or pseudorandom sequence of local searches, with a clustering +heuristic to avoid multiple local searches for the same local optimum. +The local search algorithm must be specified, along with termination +criteria/tolerances for the local searches, by +\fInlopt_set_local_optimizer\fR. (This subsidiary algorithm can be +with or without derivatives, and determines whether the objective +function needs gradients.) .TP .B NLOPT_LD_MMA Local (L) gradient-based (D) optimization using the method of moving diff --git a/api/nlopt.h b/api/nlopt.h index bfa8e41..41e3991 100644 --- a/api/nlopt.h +++ b/api/nlopt.h @@ -125,9 +125,12 @@ typedef enum { NLOPT_GN_ISRES, - /* not with older AUGLAG constants for backwards compatibility */ + /* new variants that require local_optimizer to be set, + not with older constants for backwards compatibility */ NLOPT_AUGLAG, NLOPT_AUGLAG_EQ, + NLOPT_G_MLSL, + NLOPT_G_MLSL_LDS, NLOPT_NUM_ALGORITHMS /* not an algorithm, just the number of them */ } nlopt_algorithm; diff --git a/api/optimize.c b/api/optimize.c index 11951eb..a298964 100644 --- a/api/optimize.c +++ b/api/optimize.c @@ -348,6 +348,8 @@ static nlopt_result nlopt_optimize_(nlopt_opt opt, double *x, double *minf) return crs_minimize(ni, f, f_data, lb, ub, x, minf, &stop, (int) POP(0), 0); + case NLOPT_G_MLSL: + case NLOPT_G_MLSL_LDS: case NLOPT_GN_MLSL: case NLOPT_GD_MLSL: case NLOPT_GN_MLSL_LDS: @@ -355,6 +357,9 @@ static nlopt_result nlopt_optimize_(nlopt_opt opt, double *x, double *minf) if (!finite_domain(n, lb, ub)) return NLOPT_INVALID_ARGS; nlopt_opt local_opt = opt->local_opt; nlopt_result ret; + if (!local_opt && (algorithm == NLOPT_G_MLSL + || algorithm == NLOPT_G_MLSL_LDS)) + return NLOPT_INVALID_ARGS; if (!local_opt) { /* default */ nlopt_algorithm local_alg = (algorithm == NLOPT_GN_MLSL || algorithm == NLOPT_GN_MLSL_LDS) @@ -386,7 +391,8 @@ static nlopt_result nlopt_optimize_(nlopt_opt opt, double *x, double *minf) opt->force_stop_child = local_opt; ret = mlsl_minimize(ni, f, f_data, lb, ub, x, minf, &stop, local_opt, (int) POP(0), - algorithm >= NLOPT_GN_MLSL_LDS); + algorithm >= NLOPT_GN_MLSL_LDS && + algorithm != NLOPT_G_MLSL); opt->force_stop_child = NULL; if (!opt->local_opt) nlopt_destroy(local_opt); return ret; diff --git a/octave/Makefile.am b/octave/Makefile.am index 3684077..821fe65 100644 --- a/octave/Makefile.am +++ b/octave/Makefile.am @@ -1,6 +1,6 @@ AM_CPPFLAGS = -I$(top_srcdir)/api -I$(top_srcdir)/util -MFILES = NLOPT_GN_DIRECT.m NLOPT_GN_DIRECT_L.m NLOPT_GN_DIRECT_L_RAND.m NLOPT_GN_DIRECT_NOSCAL.m NLOPT_GN_DIRECT_L_NOSCAL.m NLOPT_GN_DIRECT_L_RAND_NOSCAL.m NLOPT_GN_ORIG_DIRECT.m NLOPT_GN_ORIG_DIRECT_L.m NLOPT_GD_STOGO.m NLOPT_GD_STOGO_RAND.m NLOPT_LD_LBFGS_NOCEDAL.m NLOPT_LD_LBFGS.m NLOPT_LN_PRAXIS.m NLOPT_LD_VAR1.m NLOPT_LD_VAR2.m NLOPT_LD_TNEWTON.m NLOPT_LD_TNEWTON_RESTART.m NLOPT_LD_TNEWTON_PRECOND.m NL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_BOBYQA.m NLOPT_GN_ISRES.m NLOPT_AUGLAG.m NLOPT_AUGLAG_EQ.m NLOPT_G_MLSL.m NLOPT_G_MLSL_LDS.m ####################################################################### # dummy C program to fool automake into making sure that CPPFLAGS etc. diff --git a/octave/NLOPT_G_MLSL.m b/octave/NLOPT_G_MLSL.m new file mode 100644 index 0000000..f0c0abc --- /dev/null +++ b/octave/NLOPT_G_MLSL.m @@ -0,0 +1,5 @@ +% NLOPT_G_MLSL: Multi-level single-linkage (MLSL), random (global, needs sub-algorithm) +% +% See nlopt_minimize for more information. +function val = NLOPT_G_MLSL + val = 38; diff --git a/octave/NLOPT_G_MLSL_LDS.m b/octave/NLOPT_G_MLSL_LDS.m new file mode 100644 index 0000000..254023e --- /dev/null +++ b/octave/NLOPT_G_MLSL_LDS.m @@ -0,0 +1,5 @@ +% NLOPT_G_MLSL_LDS: Multi-level single-linkage (MLSL), quasi-random (global, needs sub-algorithm) +% +% See nlopt_minimize for more information. +function val = NLOPT_G_MLSL_LDS + val = 39; diff --git a/octave/mkconstants.sh b/octave/mkconstants.sh index 45ac91d..b27234a 100755 --- a/octave/mkconstants.sh +++ b/octave/mkconstants.sh @@ -1,6 +1,6 @@ #!/bin/sh -names=`egrep 'NLOPT_[LG][ND]|NLOPT_AUGLAG' ../api/nlopt.h |sed 's/ //g' |tr = , |cut -d, -f1` +names=`egrep 'NLOPT_[LG][ND]|NLOPT_AUGLAG|NLOPT_G_MLSL' ../api/nlopt.h |sed 's/ //g' |tr = , |cut -d, -f1` i=0 gcc -I../util -I.. -E ../api/general.c | perl -pe 's/^ *\n//' > foo.c diff --git a/swig/Makefile.am b/swig/Makefile.am index 04bde58..2434d71 100644 --- a/swig/Makefile.am +++ b/swig/Makefile.am @@ -51,6 +51,6 @@ nlopt-python.cpp nlopt.py: $(SWIG_SRC) nlopt-python.i numpy.i $(HDR) swig -I$(top_builddir)/api -outdir $(builddir) -c++ -python -o $@ nlopt.i nlopt-enum-renames.i: $(top_srcdir)/api/nlopt.h - (echo "// AUTOMATICALLY GENERATED -- DO NOT EDIT"; egrep 'NLOPT_[LG][DN]|NLOPT_AUGLAG|NLOPT_NUM_ALGORITHMS' $(top_srcdir)/api/nlopt.h | sed 's/NLOPT_//g' |tr -d ' ' |tr '/' ',' |tr '=' ',' |cut -d, -f1 |while read name; do echo "%rename(NLOPT_$$name) nlopt::$$name;"; done; egrep 'NLOPT_[A-Z_]* =' $(top_srcdir)/api/nlopt.h | egrep -v 'NLOPT_[LG][DN]|NLOPT_AUGLAG' | sed 's/NLOPT_//g' |tr -d ' ' |cut -d'=' -f1 | while read name; do echo "%rename(NLOPT_$$name) nlopt::$$name;"; done) > $@ + (echo "// AUTOMATICALLY GENERATED -- DO NOT EDIT"; egrep 'NLOPT_[LG][DN]|NLOPT_AUGLAG|NLOPT_G_MLSL|NLOPT_NUM_ALGORITHMS' $(top_srcdir)/api/nlopt.h | sed 's/NLOPT_//g' |tr -d ' ' |tr '/' ',' |tr '=' ',' |cut -d, -f1 |while read name; do echo "%rename(NLOPT_$$name) nlopt::$$name;"; done; egrep 'NLOPT_[A-Z_]* =' $(top_srcdir)/api/nlopt.h | egrep -v 'NLOPT_[LG][DN]|NLOPT_AUGLAG|NLOPT_G_MLSL' | sed 's/NLOPT_//g' |tr -d ' ' |cut -d'=' -f1 | while read name; do echo "%rename(NLOPT_$$name) nlopt::$$name;"; done) > $@ endif