Commits

Anonymous committed ebd2a80

Adding missing files. Nlopt compatibility with visual studio. Fixed problem for intial point for nlopt optimization.

Comments (0)

Files changed (22)

nlopt2/cdirect/Makefile.am

+AM_CPPFLAGS = -I$(top_srcdir)/util -I$(top_srcdir)/api
+
+noinst_LTLIBRARIES = libcdirect.la
+libcdirect_la_SOURCES = cdirect.c hybrid.c cdirect.h
+
+EXTRA_DIST = README

nlopt2/cdirect/Makefile.in

+# Makefile.in generated by automake 1.14 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994-2013 Free Software Foundation, Inc.
+
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+@SET_MAKE@
+
+VPATH = @srcdir@
+am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)'
+am__make_running_with_option = \
+  case $${target_option-} in \
+      ?) ;; \
+      *) echo "am__make_running_with_option: internal error: invalid" \
+              "target option '$${target_option-}' specified" >&2; \
+         exit 1;; \
+  esac; \
+  has_opt=no; \
+  sane_makeflags=$$MAKEFLAGS; \
+  if $(am__is_gnu_make); then \
+    sane_makeflags=$$MFLAGS; \
+  else \
+    case $$MAKEFLAGS in \
+      *\\[\ \	]*) \
+        bs=\\; \
+        sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \
+          | sed "s/$$bs$$bs[$$bs $$bs	]*//g"`;; \
+    esac; \
+  fi; \
+  skip_next=no; \
+  strip_trailopt () \
+  { \
+    flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \
+  }; \
+  for flg in $$sane_makeflags; do \
+    test $$skip_next = yes && { skip_next=no; continue; }; \
+    case $$flg in \
+      *=*|--*) continue;; \
+        -*I) strip_trailopt 'I'; skip_next=yes;; \
+      -*I?*) strip_trailopt 'I';; \
+        -*O) strip_trailopt 'O'; skip_next=yes;; \
+      -*O?*) strip_trailopt 'O';; \
+        -*l) strip_trailopt 'l'; skip_next=yes;; \
+      -*l?*) strip_trailopt 'l';; \
+      -[dEDm]) skip_next=yes;; \
+      -[JT]) skip_next=yes;; \
+    esac; \
+    case $$flg in \
+      *$$target_option*) has_opt=yes; break;; \
+    esac; \
+  done; \
+  test $$has_opt = yes
+am__make_dryrun = (target_option=n; $(am__make_running_with_option))
+am__make_keepgoing = (target_option=k; $(am__make_running_with_option))
+pkgdatadir = $(datadir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkglibexecdir = $(libexecdir)/@PACKAGE@
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+build_triplet = @build@
+host_triplet = @host@
+subdir = cdirect
+DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \
+	$(top_srcdir)/depcomp README
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/m4/ax_c_threadlocal.m4 \
+	$(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \
+	$(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \
+	$(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/configure.ac
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+	$(ACLOCAL_M4)
+mkinstalldirs = $(install_sh) -d
+CONFIG_HEADER = $(top_builddir)/config.h
+CONFIG_CLEAN_FILES =
+CONFIG_CLEAN_VPATH_FILES =
+LTLIBRARIES = $(noinst_LTLIBRARIES)
+libcdirect_la_LIBADD =
+am_libcdirect_la_OBJECTS = cdirect.lo hybrid.lo
+libcdirect_la_OBJECTS = $(am_libcdirect_la_OBJECTS)
+AM_V_lt = $(am__v_lt_@AM_V@)
+am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
+am__v_lt_0 = --silent
+am__v_lt_1 = 
+AM_V_P = $(am__v_P_@AM_V@)
+am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
+am__v_P_0 = false
+am__v_P_1 = :
+AM_V_GEN = $(am__v_GEN_@AM_V@)
+am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
+am__v_GEN_0 = @echo "  GEN     " $@;
+am__v_GEN_1 = 
+AM_V_at = $(am__v_at_@AM_V@)
+am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
+am__v_at_0 = @
+am__v_at_1 = 
+DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
+depcomp = $(SHELL) $(top_srcdir)/depcomp
+am__depfiles_maybe = depfiles
+am__mv = mv -f
+COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+	$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
+	$(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \
+	$(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
+	$(AM_CFLAGS) $(CFLAGS)
+AM_V_CC = $(am__v_CC_@AM_V@)
+am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@)
+am__v_CC_0 = @echo "  CC      " $@;
+am__v_CC_1 = 
+CCLD = $(CC)
+LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
+	$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+	$(AM_LDFLAGS) $(LDFLAGS) -o $@
+AM_V_CCLD = $(am__v_CCLD_@AM_V@)
+am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
+am__v_CCLD_0 = @echo "  CCLD    " $@;
+am__v_CCLD_1 = 
+SOURCES = $(libcdirect_la_SOURCES)
+DIST_SOURCES = $(libcdirect_la_SOURCES)
+am__can_run_installinfo = \
+  case $$AM_UPDATE_INFO_DIR in \
+    n|no|NO) false;; \
+    *) (install-info --version) >/dev/null 2>&1;; \
+  esac
+am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP)
+# Read a list of newline-separated strings from the standard input,
+# and print each of them once, without duplicates.  Input order is
+# *not* preserved.
+am__uniquify_input = $(AWK) '\
+  BEGIN { nonempty = 0; } \
+  { items[$$0] = 1; nonempty = 1; } \
+  END { if (nonempty) { for (i in items) print i; }; } \
+'
+# Make sure the list of sources is unique.  This is necessary because,
+# e.g., the same source file might be shared among _SOURCES variables
+# for different programs/libraries.
+am__define_uniq_tagged_files = \
+  list='$(am__tagged_files)'; \
+  unique=`for i in $$list; do \
+    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+  done | $(am__uniquify_input)`
+ETAGS = etags
+CTAGS = ctags
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+ACLOCAL = @ACLOCAL@
+AMTAR = @AMTAR@
+AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
+AR = @AR@
+AS = @AS@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+CC = @CC@
+CCDEPMODE = @CCDEPMODE@
+CFLAGS = @CFLAGS@
+CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
+CXX = @CXX@
+CXXCPP = @CXXCPP@
+CXXDEPMODE = @CXXDEPMODE@
+CXXFLAGS = @CXXFLAGS@
+CYGPATH_W = @CYGPATH_W@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+DLLTOOL = @DLLTOOL@
+DSYMUTIL = @DSYMUTIL@
+DUMPBIN = @DUMPBIN@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EGREP = @EGREP@
+EXEEXT = @EXEEXT@
+FGREP = @FGREP@
+GREP = @GREP@
+GUILE = @GUILE@
+GUILE_CONFIG = @GUILE_CONFIG@
+GUILE_CPPFLAGS = @GUILE_CPPFLAGS@
+GUILE_INSTALL_DIR = @GUILE_INSTALL_DIR@
+GUILE_LIBS = @GUILE_LIBS@
+INSTALL = @INSTALL@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+LD = @LD@
+LDFLAGS = @LDFLAGS@
+LIBOBJS = @LIBOBJS@
+LIBS = @LIBS@
+LIBTOOL = @LIBTOOL@
+LIPO = @LIPO@
+LN_S = @LN_S@
+LTLIBOBJS = @LTLIBOBJS@
+MAINT = @MAINT@
+MAKEINFO = @MAKEINFO@
+MANIFEST_TOOL = @MANIFEST_TOOL@
+MATLAB = @MATLAB@
+MEX = @MEX@
+MEXSUFF = @MEXSUFF@
+MEX_INSTALL_DIR = @MEX_INSTALL_DIR@
+MKDIR_P = @MKDIR_P@
+MKOCTFILE = @MKOCTFILE@
+M_INSTALL_DIR = @M_INSTALL_DIR@
+NLOPT_SUFFIX = @NLOPT_SUFFIX@
+NM = @NM@
+NMEDIT = @NMEDIT@
+OBJDUMP = @OBJDUMP@
+OBJEXT = @OBJEXT@
+OCTAVE = @OCTAVE@
+OCTAVE_CONFIG = @OCTAVE_CONFIG@
+OCT_INSTALL_DIR = @OCT_INSTALL_DIR@
+OTOOL = @OTOOL@
+OTOOL64 = @OTOOL64@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_URL = @PACKAGE_URL@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+PYTHON = @PYTHON@
+PYTHON_CONFIG = @PYTHON_CONFIG@
+PYTHON_EXEC_PREFIX = @PYTHON_EXEC_PREFIX@
+PYTHON_INCLUDES = @PYTHON_INCLUDES@
+PYTHON_PLATFORM = @PYTHON_PLATFORM@
+PYTHON_PREFIX = @PYTHON_PREFIX@
+PYTHON_VERSION = @PYTHON_VERSION@
+RANLIB = @RANLIB@
+SED = @SED@
+SET_MAKE = @SET_MAKE@
+SHARED_VERSION_INFO = @SHARED_VERSION_INFO@
+SHELL = @SHELL@
+STRIP = @STRIP@
+VERSION = @VERSION@
+abs_builddir = @abs_builddir@
+abs_srcdir = @abs_srcdir@
+abs_top_builddir = @abs_top_builddir@
+abs_top_srcdir = @abs_top_srcdir@
+ac_ct_AR = @ac_ct_AR@
+ac_ct_CC = @ac_ct_CC@
+ac_ct_CXX = @ac_ct_CXX@
+ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
+am__include = @am__include@
+am__leading_dot = @am__leading_dot@
+am__quote = @am__quote@
+am__tar = @am__tar@
+am__untar = @am__untar@
+bindir = @bindir@
+build = @build@
+build_alias = @build_alias@
+build_cpu = @build_cpu@
+build_os = @build_os@
+build_vendor = @build_vendor@
+builddir = @builddir@
+datadir = @datadir@
+datarootdir = @datarootdir@
+docdir = @docdir@
+dvidir = @dvidir@
+exec_prefix = @exec_prefix@
+host = @host@
+host_alias = @host_alias@
+host_cpu = @host_cpu@
+host_os = @host_os@
+host_vendor = @host_vendor@
+htmldir = @htmldir@
+includedir = @includedir@
+infodir = @infodir@
+install_sh = @install_sh@
+libdir = @libdir@
+libexecdir = @libexecdir@
+localedir = @localedir@
+localstatedir = @localstatedir@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+oldincludedir = @oldincludedir@
+pdfdir = @pdfdir@
+pkgpyexecdir = @pkgpyexecdir@
+pkgpythondir = @pkgpythondir@
+prefix = @prefix@
+program_transform_name = @program_transform_name@
+psdir = @psdir@
+pyexecdir = @pyexecdir@
+pythondir = @pythondir@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+srcdir = @srcdir@
+sysconfdir = @sysconfdir@
+target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
+top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
+AM_CPPFLAGS = -I$(top_srcdir)/util -I$(top_srcdir)/api
+noinst_LTLIBRARIES = libcdirect.la
+libcdirect_la_SOURCES = cdirect.c hybrid.c cdirect.h
+EXTRA_DIST = README
+all: all-am
+
+.SUFFIXES:
+.SUFFIXES: .c .lo .o .obj
+$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am  $(am__configure_deps)
+	@for dep in $?; do \
+	  case '$(am__configure_deps)' in \
+	    *$$dep*) \
+	      ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+	        && { if test -f $@; then exit 0; else break; fi; }; \
+	      exit 1;; \
+	  esac; \
+	done; \
+	echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu cdirect/Makefile'; \
+	$(am__cd) $(top_srcdir) && \
+	  $(AUTOMAKE) --gnu cdirect/Makefile
+.PRECIOUS: Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+	@case '$?' in \
+	  *config.status*) \
+	    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
+	  *) \
+	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
+	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
+	esac;
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(am__aclocal_m4_deps):
+
+clean-noinstLTLIBRARIES:
+	-test -z "$(noinst_LTLIBRARIES)" || rm -f $(noinst_LTLIBRARIES)
+	@list='$(noinst_LTLIBRARIES)'; \
+	locs=`for p in $$list; do echo $$p; done | \
+	      sed 's|^[^/]*$$|.|; s|/[^/]*$$||; s|$$|/so_locations|' | \
+	      sort -u`; \
+	test -z "$$locs" || { \
+	  echo rm -f $${locs}; \
+	  rm -f $${locs}; \
+	}
+
+libcdirect.la: $(libcdirect_la_OBJECTS) $(libcdirect_la_DEPENDENCIES) $(EXTRA_libcdirect_la_DEPENDENCIES) 
+	$(AM_V_CCLD)$(LINK)  $(libcdirect_la_OBJECTS) $(libcdirect_la_LIBADD) $(LIBS)
+
+mostlyclean-compile:
+	-rm -f *.$(OBJEXT)
+
+distclean-compile:
+	-rm -f *.tab.c
+
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cdirect.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hybrid.Plo@am__quote@
+
+.c.o:
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ $<
+
+.c.obj:
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
+
+.c.lo:
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $<
+
+mostlyclean-libtool:
+	-rm -f *.lo
+
+clean-libtool:
+	-rm -rf .libs _libs
+
+ID: $(am__tagged_files)
+	$(am__define_uniq_tagged_files); mkid -fID $$unique
+tags: tags-am
+TAGS: tags
+
+tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files)
+	set x; \
+	here=`pwd`; \
+	$(am__define_uniq_tagged_files); \
+	shift; \
+	if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
+	  test -n "$$unique" || unique=$$empty_fix; \
+	  if test $$# -gt 0; then \
+	    $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+	      "$$@" $$unique; \
+	  else \
+	    $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+	      $$unique; \
+	  fi; \
+	fi
+ctags: ctags-am
+
+CTAGS: ctags
+ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files)
+	$(am__define_uniq_tagged_files); \
+	test -z "$(CTAGS_ARGS)$$unique" \
+	  || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
+	     $$unique
+
+GTAGS:
+	here=`$(am__cd) $(top_builddir) && pwd` \
+	  && $(am__cd) $(top_srcdir) \
+	  && gtags -i $(GTAGS_ARGS) "$$here"
+cscopelist: cscopelist-am
+
+cscopelist-am: $(am__tagged_files)
+	list='$(am__tagged_files)'; \
+	case "$(srcdir)" in \
+	  [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \
+	  *) sdir=$(subdir)/$(srcdir) ;; \
+	esac; \
+	for i in $$list; do \
+	  if test -f "$$i"; then \
+	    echo "$(subdir)/$$i"; \
+	  else \
+	    echo "$$sdir/$$i"; \
+	  fi; \
+	done >> $(top_builddir)/cscope.files
+
+distclean-tags:
+	-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
+
+distdir: $(DISTFILES)
+	@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+	topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+	list='$(DISTFILES)'; \
+	  dist_files=`for file in $$list; do echo $$file; done | \
+	  sed -e "s|^$$srcdirstrip/||;t" \
+	      -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
+	case $$dist_files in \
+	  */*) $(MKDIR_P) `echo "$$dist_files" | \
+			   sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
+			   sort -u` ;; \
+	esac; \
+	for file in $$dist_files; do \
+	  if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+	  if test -d $$d/$$file; then \
+	    dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
+	    if test -d "$(distdir)/$$file"; then \
+	      find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+	    fi; \
+	    if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+	      cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
+	      find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+	    fi; \
+	    cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
+	  else \
+	    test -f "$(distdir)/$$file" \
+	    || cp -p $$d/$$file "$(distdir)/$$file" \
+	    || exit 1; \
+	  fi; \
+	done
+check-am: all-am
+check: check-am
+all-am: Makefile $(LTLIBRARIES)
+installdirs:
+install: install-am
+install-exec: install-exec-am
+install-data: install-data-am
+uninstall: uninstall-am
+
+install-am: all-am
+	@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-am
+install-strip:
+	if test -z '$(STRIP)'; then \
+	  $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+	    install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+	      install; \
+	else \
+	  $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+	    install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+	    "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
+	fi
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+	-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+	-test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
+
+maintainer-clean-generic:
+	@echo "This command is intended for maintainers to use"
+	@echo "it deletes files that may require special tools to rebuild."
+clean: clean-am
+
+clean-am: clean-generic clean-libtool clean-noinstLTLIBRARIES \
+	mostlyclean-am
+
+distclean: distclean-am
+	-rm -rf ./$(DEPDIR)
+	-rm -f Makefile
+distclean-am: clean-am distclean-compile distclean-generic \
+	distclean-tags
+
+dvi: dvi-am
+
+dvi-am:
+
+html: html-am
+
+html-am:
+
+info: info-am
+
+info-am:
+
+install-data-am:
+
+install-dvi: install-dvi-am
+
+install-dvi-am:
+
+install-exec-am:
+
+install-html: install-html-am
+
+install-html-am:
+
+install-info: install-info-am
+
+install-info-am:
+
+install-man:
+
+install-pdf: install-pdf-am
+
+install-pdf-am:
+
+install-ps: install-ps-am
+
+install-ps-am:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-am
+	-rm -rf ./$(DEPDIR)
+	-rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-am
+
+mostlyclean-am: mostlyclean-compile mostlyclean-generic \
+	mostlyclean-libtool
+
+pdf: pdf-am
+
+pdf-am:
+
+ps: ps-am
+
+ps-am:
+
+uninstall-am:
+
+.MAKE: install-am install-strip
+
+.PHONY: CTAGS GTAGS TAGS all all-am check check-am clean clean-generic \
+	clean-libtool clean-noinstLTLIBRARIES cscopelist-am ctags \
+	ctags-am distclean distclean-compile distclean-generic \
+	distclean-libtool distclean-tags distdir dvi dvi-am html \
+	html-am info info-am install install-am install-data \
+	install-data-am install-dvi install-dvi-am install-exec \
+	install-exec-am install-html install-html-am install-info \
+	install-info-am install-man install-pdf install-pdf-am \
+	install-ps install-ps-am install-strip installcheck \
+	installcheck-am installdirs maintainer-clean \
+	maintainer-clean-generic mostlyclean mostlyclean-compile \
+	mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
+	tags tags-am uninstall uninstall-am
+
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:

nlopt2/cdirect/README

+From-scratch re-implementation of the DIRECT and DIRECT-L algorithms
+described in:
+
+	D. R. Jones, C. D. Perttunen, and B. E. Stuckmann,
+	"Lipschitzian optimization without the lipschitz constant,"
+	J. Optimization Theory and Applications, vol. 79, p. 157 (1993).
+
+	J. M. Gablonsky and C. T. Kelley, "A locally-biased form
+	of the DIRECT algorithm," J. Global Optimization 21 (1),
+	p. 27-37 (2001).
+
+I re-implemented the algorithms for a couple of reasons.  First,
+because I was interested in the algorithms and wanted to play with
+them by trying some variations (originally, because I wanted to
+experiment with a hybrid approach combining DIRECT with local search
+algorithms, see hybrid.c).  Second, I wanted to remove some arbitrary
+restrictions in the original Fortran code, e.g. a fixed upper bound on
+the number of function evaluations.  Third, because it was fun to
+code.  As far as I can tell, my version converges in about the same
+number of iterations as Gablonsky's code (with occasional slight
+differences due to minor differences in how I break ties, etc.).
+
+The code in this directory is under the same MIT license as the rest
+of my code in NLopt (see ../COPYRIGHT).
+
+Steven G. Johnson

nlopt2/cdirect/cdirect.c

+/* Copyright (c) 2007-2012 Massachusetts Institute of Technology
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ * 
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 
+ */
+
+#include <math.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "nlopt-util.h"
+#include "nlopt.h"
+#include "cdirect.h"
+#include "redblack.h"
+
+#define MIN(a,b) ((a) < (b) ? (a) : (b))
+#define MAX(a,b) ((a) > (b) ? (a) : (b))
+
+/***************************************************************************/
+/* basic data structure:
+ *
+ * a hyper-rectangle is stored as an array of length L = 2n+3, where [1]
+ * is the value (f) of the function at the center, [0] is the "size"
+ * measure (d) of the rectangle, [3..n+2] are the coordinates of the
+ * center (c), [n+3..2n+2] are the widths of the sides (w), and [2]
+ * is an "age" measure for tie-breaking purposes.
+ *
+ * we store the hyper-rectangles in a red-black tree, sorted by (d,f)
+ * in lexographic order, to allow us to perform quick convex-hull
+ * calculations (in the future, we might make this data structure
+ * more sophisticated based on the dynamic convex-hull literature).
+ *
+ * n > 0 always, of course.
+ */
+
+/* parameters of the search algorithm and various information that
+   needs to be passed around */
+typedef struct {
+     int n; /* dimension */
+     int L; /* size of each rectangle (2n+3) */
+     double magic_eps; /* Jones' epsilon parameter (1e-4 is recommended) */
+     int which_diam; /* which measure of hyper-rectangle diam to use:
+			0 = Jones, 1 = Gablonsky */
+     int which_div; /* which way to divide rects:
+		       0: orig. Jones (divide all longest sides)
+		       1: Gablonsky (cubes divide all, rects longest)
+		       2: Jones Encyc. Opt.: pick random longest side */
+     int which_opt; /* which rects are considered "potentially optimal"
+		       0: Jones (all pts on cvx hull, even equal pts)
+		       1: Gablonsky DIRECT-L (pick one pt, if equal pts)
+		       2: ~ 1, but pick points randomly if equal pts 
+		    ... 2 seems to suck compared to just picking oldest pt */
+  
+     const double *lb, *ub;
+     nlopt_stopping *stop; /* stopping criteria */
+     nlopt_func f; void *f_data;
+     double *work; /* workspace, of length >= 2*n */
+     int *iwork; /* workspace, length >= n */
+     double minf, *xmin; /* minimum so far */
+     
+     /* red-black tree of hyperrects, sorted by (d,f,age) in
+	lexographical order */
+     rb_tree rtree;
+     int age; /* age for next new rect */
+     double **hull; /* array to store convex hull */
+     int hull_len; /* allocated length of hull array */
+} params;
+
+/***************************************************************************/
+
+/* Evaluate the "diameter" (d) of a rectangle of widths w[n] 
+
+   We round the result to single precision, which should be plenty for
+   the use we put the diameter to (rect sorting), to allow our
+   performance hack in convex_hull to work (in the Jones and Gablonsky
+   DIRECT algorithms, all of the rects fall into a few diameter
+   values, and we don't want rounding error to spoil this) */
+static double rect_diameter(int n, const double *w, const params *p)
+{
+     int i;
+     if (p->which_diam == 0) { /* Jones measure */
+	  double sum = 0;
+	  for (i = 0; i < n; ++i)
+	       sum += w[i] * w[i];
+	  /* distance from center to a vertex */
+	  return ((float) (sqrt(sum) * 0.5)); 
+     }
+     else { /* Gablonsky measure */
+	  double maxw = 0;
+	  for (i = 0; i < n; ++i)
+	       if (w[i] > maxw)
+		    maxw = w[i];
+	  /* half-width of longest side */
+	  return ((float) (maxw * 0.5));
+     }
+}
+
+#define ALLOC_RECT(rect, L) if (!(rect = (double*) malloc(sizeof(double)*(L)))) return NLOPT_OUT_OF_MEMORY
+
+static int sort_fv_compare(void *fv_, const void *a_, const void *b_)
+{
+     const double *fv = (const double *) fv_;
+     int a = *((const int *) a_), b = *((const int *) b_);
+     double fa = MIN(fv[2*a], fv[2*a+1]);
+     double fb = MIN(fv[2*b], fv[2*b+1]);
+     if (fa < fb)
+	  return -1;
+     else if (fa > fb)
+	  return +1;
+     else
+	  return 0;
+}
+static void sort_fv(int n, double *fv, int *isort)
+{
+     int i;
+     for (i = 0; i < n; ++i) isort[i] = i;
+     nlopt_qsort_r(isort, (unsigned) n, sizeof(int), fv, sort_fv_compare);
+}
+
+static double function_eval(const double *x, params *p) {
+     double f = p->f(p->n, x, NULL, p->f_data);
+     if (f < p->minf) {
+	  p->minf = f;
+	  memcpy(p->xmin, x, sizeof(double) * p->n);
+     }
+     p->stop->nevals++;
+     return f;
+}
+#define FUNCTION_EVAL(fv,x,p,freeonerr) fv = function_eval(x, p); if (nlopt_stop_forced((p)->stop)) { free(freeonerr); return NLOPT_FORCED_STOP; } else if (p->minf < p->stop->minf_max) { free(freeonerr); return NLOPT_MINF_MAX_REACHED; } else if (nlopt_stop_evals((p)->stop)) { free(freeonerr); return NLOPT_MAXEVAL_REACHED; } else if (nlopt_stop_time((p)->stop)) { free(freeonerr); return NLOPT_MAXTIME_REACHED; }
+
+#define THIRD (0.3333333333333333333333)
+
+#define EQUAL_SIDE_TOL 5e-2 /* tolerance to equate side sizes */
+
+/* divide rectangle idiv in the list p->rects */
+static nlopt_result divide_rect(double *rdiv, params *p)
+{
+     int i;
+     const int n = p->n;
+     const int L = p->L;
+     double *c = rdiv + 3; /* center of rect to divide */
+     double *w = c + n; /* widths of rect to divide */
+     double wmax = w[0];
+     int imax = 0, nlongest = 0;
+     rb_node *node;
+
+     for (i = 1; i < n; ++i)
+	  if (w[i] > wmax)
+	       wmax = w[imax = i];
+     for (i = 0; i < n; ++i)
+	  if (wmax - w[i] <= wmax * EQUAL_SIDE_TOL)
+	       ++nlongest;
+     if (p->which_div == 1 || (p->which_div == 0 && nlongest == n)) {
+	  /* trisect all longest sides, in increasing order of the average
+	     function value along that direction */
+	  double *fv = p->work;
+	  int *isort = p->iwork;
+	  for (i = 0; i < n; ++i) {
+	       if (wmax - w[i] <= wmax * EQUAL_SIDE_TOL) {
+		    double csave = c[i];
+		    c[i] = csave - w[i] * THIRD;
+		    FUNCTION_EVAL(fv[2*i], c, p, 0);
+		    c[i] = csave + w[i] * THIRD;
+		    FUNCTION_EVAL(fv[2*i+1], c, p, 0);
+		    c[i] = csave;
+	       }
+	       else {
+		    fv[2*i] = fv[2*i+1] = HUGE_VAL;
+	       }
+	  }
+	  sort_fv(n, fv, isort);
+	  if (!(node = rb_tree_find(&p->rtree, rdiv)))
+	       return NLOPT_FAILURE;
+	  for (i = 0; i < nlongest; ++i) {
+	       int k;
+	       w[isort[i]] *= THIRD;
+	       rdiv[0] = rect_diameter(n, w, p);
+	       rdiv[2] = p->age++;
+	       node = rb_tree_resort(&p->rtree, node);
+	       for (k = 0; k <= 1; ++k) {
+		    double *rnew;
+		    ALLOC_RECT(rnew, L);
+		    memcpy(rnew, rdiv, sizeof(double) * L);
+		    rnew[3 + isort[i]] += w[isort[i]] * (2*k-1);
+		    rnew[1] = fv[2*isort[i]+k];
+		    rnew[2] = p->age++;
+		    if (!rb_tree_insert(&p->rtree, rnew)) {
+			 free(rnew);
+			 return NLOPT_OUT_OF_MEMORY;
+		    }
+	       }
+	  }
+     }
+     else {
+	  int k;
+	  if (nlongest > 1 && p->which_div == 2) { 
+               /* randomly choose longest side */
+	       i = nlopt_iurand(nlongest);
+	       for (k = 0; k < n; ++k)
+		    if (wmax - w[k] <= wmax * EQUAL_SIDE_TOL) {
+			 if (!i) { i = k; break; }
+			 --i;
+		    }
+	  }
+	  else
+	       i = imax; /* trisect longest side */
+	  if (!(node = rb_tree_find(&p->rtree, rdiv)))
+	       return NLOPT_FAILURE;
+	  w[i] *= THIRD;
+	  rdiv[0] = rect_diameter(n, w, p);
+	  rdiv[2] = p->age++;
+	  node = rb_tree_resort(&p->rtree, node);
+	  for (k = 0; k <= 1; ++k) {
+	       double *rnew;
+	       ALLOC_RECT(rnew, L);
+	       memcpy(rnew, rdiv, sizeof(double) * L);
+	       rnew[3 + i] += w[i] * (2*k-1);
+	       FUNCTION_EVAL(rnew[1], rnew + 3, p, rnew);
+	       rnew[2] = p->age++;
+	       if (!rb_tree_insert(&p->rtree, rnew)) {
+		    free(rnew);
+		    return NLOPT_OUT_OF_MEMORY;
+	       }
+	  }
+     }
+     return NLOPT_SUCCESS;
+}
+
+/***************************************************************************/
+/* Convex hull algorithm, used later to find the potentially optimal
+   points.  What we really have in DIRECT is a "dynamic convex hull"
+   problem, since we are dynamically adding/removing points and
+   updating the hull, but I haven't implemented any of the fancy
+   algorithms for this problem yet. */
+
+/* Find the lower convex hull of a set of points (x,y) stored in a rb-tree
+   of pointers to {x,y} arrays sorted in lexographic order by (x,y).
+
+   Unlike standard convex hulls, we allow redundant points on the hull,
+   and even allow duplicate points if allow_dups is nonzero.
+
+   The return value is the number of points in the hull, with pointers
+   stored in hull[i] (should be an array of length >= t->N).
+*/
+static int convex_hull(rb_tree *t, double **hull, int allow_dups)
+{
+     int nhull = 0;
+     double minslope;
+     double xmin, xmax, yminmin, ymaxmin;
+     rb_node *n, *nmax;
+
+     /* Monotone chain algorithm [Andrew, 1979]. */
+
+     n = rb_tree_min(t);
+     if (!n) return 0;
+     nmax = rb_tree_max(t);
+
+     xmin = n->k[0];
+     yminmin = n->k[1];
+     xmax = nmax->k[0];
+
+     if (allow_dups)
+	  do { /* include any duplicate points at (xmin,yminmin) */
+	       hull[nhull++] = n->k;
+	       n = rb_tree_succ(n);
+	  } while (n && n->k[0] == xmin && n->k[1] == yminmin);
+     else
+	  hull[nhull++] = n->k;
+
+     if (xmin == xmax) return nhull;
+
+     /* set nmax = min mode with x == xmax */
+#if 0
+     while (nmax->k[0] == xmax)
+	  nmax = rb_tree_pred(nmax); /* non-NULL since xmin != xmax */
+     nmax = rb_tree_succ(nmax);
+#else
+     /* performance hack (see also below) */
+     {
+	  double kshift[2];
+	  kshift[0] = xmax * (1 - 1e-13);
+	  kshift[1] = -HUGE_VAL;
+	  nmax = rb_tree_find_gt(t, kshift); /* non-NULL since xmin != xmax */
+     }
+#endif
+
+     ymaxmin = nmax->k[1];
+     minslope = (ymaxmin - yminmin) / (xmax - xmin);
+
+     /* set n = first node with x != xmin */
+#if 0
+     while (n->k[0] == xmin)
+	  n = rb_tree_succ(n); /* non-NULL since xmin != xmax */
+#else
+     /* performance hack (see also below) */
+     {
+	  double kshift[2];
+	  kshift[0] = xmin * (1 + 1e-13);
+	  kshift[1] = -HUGE_VAL;
+	  n = rb_tree_find_gt(t, kshift); /* non-NULL since xmin != xmax */
+     }
+#endif
+
+     for (; n != nmax; n = rb_tree_succ(n)) { 
+	  double *k = n->k;
+	  if (k[1] > yminmin + (k[0] - xmin) * minslope)
+	       continue;
+
+	  /* performance hack: most of the points in DIRECT lie along
+	     vertical lines at a few x values, and we can exploit this */
+	  if (nhull && k[0] == hull[nhull - 1][0]) { /* x == previous x */
+	       if (k[1] > hull[nhull - 1][1]) {
+		    double kshift[2];
+		    /* because of the round to float in rect_diameter, above,
+		       it shouldn't be possible for two diameters (x values)
+		       to have a fractional difference < 1e-13.  Note
+		       that k[0] > 0 always in DIRECT */
+		    kshift[0] = k[0] * (1 + 1e-13);
+		    kshift[1] = -HUGE_VAL;
+		    n = rb_tree_pred(rb_tree_find_gt(t, kshift));
+		    continue;
+	       }
+	       else { /* equal y values, add to hull */
+		    if (allow_dups)
+			 hull[nhull++] = k;
+		    continue;
+	       }
+	  }
+
+	  /* remove points until we are making a "left turn" to k */
+	  while (nhull > 1) {
+	       double *t1 = hull[nhull - 1], *t2;
+
+	       /* because we allow equal points in our hull, we have
+		  to modify the standard convex-hull algorithm slightly:
+		  we need to look backwards in the hull list until we
+		  find a point t2 != t1 */
+	       int it2 = nhull - 2;
+	       do {
+		    t2 = hull[it2--];
+	       } while (it2 >= 0 && t2[0] == t1[0] && t2[1] == t1[1]);
+	       if (it2 < 0) break;
+
+	       /* cross product (t1-t2) x (k-t2) > 0 for a left turn: */
+	       if ((t1[0]-t2[0]) * (k[1]-t2[1])
+		   - (t1[1]-t2[1]) * (k[0]-t2[0]) >= 0)
+		    break;
+	       --nhull;
+	  }
+	  hull[nhull++] = k;
+     }
+
+     if (allow_dups)
+	  do { /* include any duplicate points at (xmax,ymaxmin) */
+	       hull[nhull++] = nmax->k;
+	       nmax = rb_tree_succ(nmax);
+	  } while (nmax && nmax->k[0] == xmax && nmax->k[1] == ymaxmin);
+     else
+	  hull[nhull++] = nmax->k;
+
+     return nhull;
+}
+
+/***************************************************************************/
+
+static int small(double *w, params *p)
+{
+     int i;
+     for (i = 0; i < p->n; ++i)
+	  if (w[i] > p->stop->xtol_abs[i] &&
+	      w[i] > (p->ub[i] - p->lb[i]) * p->stop->xtol_rel)
+	       return 0;
+     return 1;
+}
+
+static nlopt_result divide_good_rects(params *p)
+{
+     const int n = p->n;
+     double **hull;
+     int nhull, i, xtol_reached = 1, divided_some = 0;
+     double magic_eps = p->magic_eps;
+
+     if (p->hull_len < p->rtree.N) {
+	  p->hull_len += p->rtree.N;
+	  p->hull = (double **) realloc(p->hull, sizeof(double*)*p->hull_len);
+	  if (!p->hull) return NLOPT_OUT_OF_MEMORY;
+     }
+     nhull = convex_hull(&p->rtree, hull = p->hull, p->which_opt != 1);
+ divisions:
+     for (i = 0; i < nhull; ++i) {
+	  double K1 = -HUGE_VAL, K2 = -HUGE_VAL, K;
+	  int im, ip;
+
+	  /* find unequal points before (im) and after (ip) to get slope */
+	  for (im = i-1; im >= 0 && hull[im][0] == hull[i][0]; --im) ;
+	  for (ip = i+1; ip < nhull && hull[ip][0] == hull[i][0]; ++ip) ;
+
+	  if (im >= 0)
+	       K1 = (hull[i][1] - hull[im][1]) / (hull[i][0] - hull[im][0]);
+	  if (ip < nhull)
+	       K2 = (hull[i][1] - hull[ip][1]) / (hull[i][0] - hull[ip][0]);
+	  K = MAX(K1, K2);
+	  if (hull[i][1] - K * hull[i][0]
+	      <= p->minf - magic_eps * fabs(p->minf) || ip == nhull) {
+	       /* "potentially optimal" rectangle, so subdivide */
+	       nlopt_result ret = divide_rect(hull[i], p);
+	       divided_some = 1;
+	       if (ret != NLOPT_SUCCESS) return ret;
+	       xtol_reached = xtol_reached && small(hull[i] + 3+n, p);
+	  }
+
+	  /* for the DIRECT-L variant, we only divide one rectangle out
+	     of all points with equal diameter and function values
+	     ... note that for p->which_opt == 1, i == ip-1 should be a no-op
+	         anyway, since we set allow_dups=0 in convex_hull above */
+	  if (p->which_opt == 1)
+	       i = ip - 1; /* skip to next unequal point for next iteration */
+	  else if (p->which_opt == 2) /* like DIRECT-L but randomized */
+	       i += nlopt_iurand(ip - i); /* possibly do another equal pt */
+     }
+     if (!divided_some) {
+	  if (magic_eps != 0) {
+	       magic_eps = 0;
+	       goto divisions; /* try again */
+	  }
+	  else { /* WTF? divide largest rectangle with smallest f */
+	       /* (note that this code actually gets called from time
+		  to time, and the heuristic here seems to work well,
+		  but I don't recall this situation being discussed in
+		  the references?) */
+	       rb_node *max = rb_tree_max(&p->rtree);
+	       rb_node *pred = max;
+	       double wmax = max->k[0];
+	       do { /* note: this loop is O(N) worst-case time */
+		    max = pred;
+		    pred = rb_tree_pred(max);
+	       } while (pred && pred->k[0] == wmax);
+	       return divide_rect(max->k, p);
+	  }
+     }
+     return xtol_reached ? NLOPT_XTOL_REACHED : NLOPT_SUCCESS;
+}
+
+/***************************************************************************/
+
+/* lexographic sort order (d,f,age) of hyper-rects, for red-black tree */
+int cdirect_hyperrect_compare(double *a, double *b)
+{
+     if (a[0] < b[0]) return -1;
+     if (a[0] > b[0]) return +1;
+     if (a[1] < b[1]) return -1;
+     if (a[1] > b[1]) return +1;
+     if (a[2] < b[2]) return -1;
+     if (a[2] > b[2]) return +1;
+     return (int) (a - b); /* tie-breaker, shouldn't be needed */
+}
+
+/***************************************************************************/
+
+nlopt_result cdirect_unscaled(int n, nlopt_func f, void *f_data,
+			      const double *lb, const double *ub,
+			      double *x,
+			      double *minf,
+			      nlopt_stopping *stop,
+			      double magic_eps, int which_alg)
+{
+     params p;
+     int i;
+     double *rnew;
+     nlopt_result ret = NLOPT_OUT_OF_MEMORY;
+
+     p.magic_eps = magic_eps;
+     p.which_diam = which_alg % 3;
+     p.which_div = (which_alg / 3) % 3;
+     p.which_opt = (which_alg / (3*3)) % 3;
+     p.lb = lb; p.ub = ub;
+     p.stop = stop;
+     p.n = n;
+     p.L = 2*n+3;
+     p.f = f;
+     p.f_data = f_data;
+     p.xmin = x;
+     p.minf = HUGE_VAL;
+     p.work = 0;
+     p.iwork = 0;
+     p.hull = 0;
+     p.age = 0;
+
+     rb_tree_init(&p.rtree, cdirect_hyperrect_compare);
+
+     p.work = (double *) malloc(sizeof(double) * (2*n));
+     if (!p.work) goto done;
+     p.iwork = (int *) malloc(sizeof(int) * n);
+     if (!p.iwork) goto done;
+     p.hull_len = 128; /* start with a reasonable number */
+     p.hull = (double **) malloc(sizeof(double *) * p.hull_len);
+     if (!p.hull) goto done;
+
+     if (!(rnew = (double *) malloc(sizeof(double) * p.L))) goto done;
+     for (i = 0; i < n; ++i) {
+	  rnew[3+i] = 0.5 * (lb[i] + ub[i]);
+	  rnew[3+n+i] = ub[i] - lb[i];
+     }
+     rnew[0] = rect_diameter(n, rnew+3+n, &p);
+     rnew[1] = function_eval(rnew+3, &p);
+     rnew[2] = p.age++;
+     if (!rb_tree_insert(&p.rtree, rnew)) {
+	  free(rnew);
+	  goto done;
+     }
+
+     ret = divide_rect(rnew, &p);
+     if (ret != NLOPT_SUCCESS) goto done;
+
+     while (1) {
+	  double minf0 = p.minf;
+	  ret = divide_good_rects(&p);
+	  if (ret != NLOPT_SUCCESS) goto done;
+	  if (p.minf < minf0 && nlopt_stop_f(p.stop, p.minf, minf0)) {
+	       ret = NLOPT_FTOL_REACHED;
+	       goto done;
+	  }
+     }
+
+ done:
+     rb_tree_destroy_with_keys(&p.rtree);
+     free(p.hull);
+     free(p.iwork);
+     free(p.work);
+	      
+     *minf = p.minf;
+     return ret;
+}
+
+/* in the conventional DIRECT-type algorithm, we first rescale our
+   coordinates to a unit hypercube ... we do this simply by
+   wrapping cdirect() around cdirect_unscaled(). */
+
+double cdirect_uf(unsigned n, const double *xu, double *grad, void *d_)
+{
+     cdirect_uf_data *d = (cdirect_uf_data *) d_;
+     double f;
+     unsigned i;
+     for (i = 0; i < n; ++i)
+	  d->x[i] = d->lb[i] + xu[i] * (d->ub[i] - d->lb[i]);
+     f = d->f(n, d->x, grad, d->f_data);
+     if (grad)
+	  for (i = 0; i < n; ++i)
+	       grad[i] *= d->ub[i] - d->lb[i];
+     return f;
+}
+
+nlopt_result cdirect(int n, nlopt_func f, void *f_data,
+                     const double *lb, const double *ub,
+                     double *x,
+                     double *minf,
+                     nlopt_stopping *stop,
+                     double magic_eps, int which_alg)
+{
+     cdirect_uf_data d;
+     nlopt_result ret;
+     const double *xtol_abs_save;
+     int i;
+
+     d.f = f; d.f_data = f_data; d.lb = lb; d.ub = ub;
+     d.x = (double *) malloc(sizeof(double) * n*4);
+     if (!d.x) return NLOPT_OUT_OF_MEMORY;
+     
+     for (i = 0; i < n; ++i) {
+	  x[i] = (x[i] - lb[i]) / (ub[i] - lb[i]);
+	  d.x[n+i] = 0;
+	  d.x[2*n+i] = 1;
+	  d.x[3*n+i] = stop->xtol_abs[i] / (ub[i] - lb[i]);
+     }
+     xtol_abs_save = stop->xtol_abs;
+     stop->xtol_abs = d.x + 3*n;
+     ret = cdirect_unscaled(n, cdirect_uf, &d, d.x+n, d.x+2*n, x, minf, stop,
+			    magic_eps, which_alg);
+     stop->xtol_abs = xtol_abs_save;
+     for (i = 0; i < n; ++i)
+	  x[i] = lb[i]+ x[i] * (ub[i] - lb[i]);
+     free(d.x);
+     return ret;
+}

nlopt2/cdirect/cdirect.h

+/* Copyright (c) 2007-2012 Massachusetts Institute of Technology
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ * 
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 
+ */
+
+#ifndef CDIRECT_H
+#define CDIRECT_H
+
+#include "nlopt-util.h"
+#include "nlopt.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif /* __cplusplus */
+
+extern nlopt_result cdirect_unscaled(int n, nlopt_func f, void *f_data,
+				     const double *lb, const double *ub,
+				     double *x,
+				     double *minf,
+				     nlopt_stopping *stop,
+				     double magic_eps, int which_alg);
+
+extern nlopt_result cdirect(int n, nlopt_func f, void *f_data,
+			    const double *lb, const double *ub,
+			    double *x,
+			    double *minf,
+			    nlopt_stopping *stop,
+			    double magic_eps, int which_alg);
+
+extern nlopt_result cdirect_hybrid(int n, nlopt_func f, void *f_data,
+			    const double *lb, const double *ub,
+			    double *x,
+			    double *minf,
+			    nlopt_stopping *stop,
+			    nlopt_algorithm local_alg,
+			    int local_maxeval,
+			    int randomized_div);
+
+extern nlopt_result cdirect_hybrid_unscaled(int n, nlopt_func f, void *f_data,
+			    const double *lb, const double *ub,
+			    double *x,
+			    double *minf,
+			    nlopt_stopping *stop,
+			    nlopt_algorithm local_alg,
+			    int local_maxeval,
+			    int randomized_div);
+
+/* internal routines and data structures: */
+extern int cdirect_hyperrect_compare(double *a, double *b);
+typedef struct {
+     nlopt_func f;
+     void *f_data;
+     double *x;
+     const double *lb, *ub;
+} cdirect_uf_data;
+extern double cdirect_uf(unsigned n, const double *xu, double *grad, void *d_);
+
+#ifdef __cplusplus
+}  /* extern "C" */
+#endif /* __cplusplus */
+
+#endif /* DIRECT_H */

nlopt2/cdirect/hybrid.c

+/* Copyright (c) 2007-2012 Massachusetts Institute of Technology
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ * 
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 
+ */
+
+#include <math.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "nlopt-util.h"
+#include "nlopt.h"
+#include "cdirect.h"
+#include "redblack.h"
+
+/* Hybrid algorithm, inspired by DIRECT, that uses another local
+ * optimization algorithm within each rectangle, and then looks
+ * in the largest remaining rectangle (breaking ties by minimum
+ * function value and then by age. 
+ *
+ * Each hyperrect is represented by an array of length 3*n+3 consisting
+ * of (d, -f, -a, x, c, w), where d=diameter, f=f(x), a=age, x=local optimum
+ * c=center, w=widths.
+ */
+
+typedef struct {
+     int n; /* dimension */
+     int L; /* 3*n+3 */
+     const double *lb, *ub;
+     nlopt_stopping *stop; /* stopping criteria */
+     nlopt_func f; void *f_data;
+     double minf, *xmin; /* min so far */
+     rb_tree rtree; /* red-black tree of rects, sorted by (d,-f,-a) */
+     int age; /* age for next new rect */
+     double *work; /* workspace of length >= 2*n */
+     
+     nlopt_algorithm local_alg; /* local search algorithm */
+     int local_maxeval; /* max # local iterations (0 if unlimited) */
+
+     int randomized_div; /* 1 to use randomized division algorithm */
+} params;
+
+#define MIN(a,b) ((a) < (b) ? (a) : (b))
+
+#define THIRD (0.3333333333333333333333) /* 1/3 */
+
+/************************************************************************/
+
+static double fcount(int n, const double *x, double *grad, void *p_)
+{
+     params *p = (params *) p_;
+     p->stop->nevals++;
+     return p->f(n, x, grad, p->f_data);
+}
+
+static nlopt_result optimize_rect(double *r, params *p)
+{
+     int i, n = p->n;
+     double *lb = p->work, *ub = lb + n;
+     double *x = r + 3, *c = x + n, *w = c + n;
+     double t = nlopt_seconds();
+     double minf;
+     nlopt_stopping *stop = p->stop;
+     nlopt_result ret;
+     
+     if (stop->maxeval > 0 &&
+	 stop->nevals >= stop->maxeval) return NLOPT_MAXEVAL_REACHED;
+     if (stop->maxtime > 0 &&
+	 t - stop->start >= stop->maxtime) return NLOPT_MAXTIME_REACHED;
+
+     for (i = 0; i < n; ++i) {
+	  lb[i] = c[i] - 0.5 * w[i];
+	  ub[i] = c[i] + 0.5 * w[i];
+     }
+     ret = nlopt_minimize(p->local_alg, n, fcount, p, 
+			  lb, ub, x, &minf,
+			  stop->minf_max, stop->ftol_rel, stop->ftol_abs,
+			  stop->xtol_rel, stop->xtol_abs,
+			  p->local_maxeval > 0 ?
+			  MIN(p->local_maxeval, 
+			      stop->maxeval - stop->nevals)
+			  : stop->maxeval - stop->nevals,
+			  stop->maxtime - (t - stop->start));
+     r[1] = -minf;
+     if (ret > 0) {
+	  if (minf < p->minf) {
+	       p->minf = minf;
+	       memcpy(p->xmin, x, sizeof(double) * n);
+	       if (ret == NLOPT_MINF_MAX_REACHED) return ret;
+	  }
+	  return NLOPT_SUCCESS;
+     }
+     return ret;
+}
+
+/* given a hyperrect r, randomize the starting guess within the middle
+   third of the box (don't guess too close to edges) */
+static void randomize_x(int n, double *r)
+{
+     double *x = r + 3, *c = x + n, *w = c + n;
+     int i;
+     for (i = 0; i < n; ++i)
+	  x[i] = nlopt_urand(c[i] - w[i]*(0.5*THIRD),
+			     c[i] + w[i]*(0.5*THIRD));
+}
+
+/************************************************************************/
+
+static double longest(int n, const double *w)
+{
+     double wmax = w[n-1];
+     for (n = n-2; n >= 0; n--) if (w[n] > wmax) wmax = w[n];
+     return wmax;
+}
+
+#define EQUAL_SIDE_TOL 5e-2 /* tolerance to equate side sizes */
+
+static nlopt_result divide_largest(params *p)
+{
+     int L = p->L;
+     int n = p->n;
+     rb_node *node = rb_tree_max(&p->rtree); /* just using it as a heap */
+     double minf_start = p->minf;
+     double *r = node->k, *rnew = NULL;
+     double *x = r + 3, *c = x + n, *w = c + n;
+     const double *lb = p->lb, *ub = p->ub;
+     int i, idiv;
+     double wmax;
+     nlopt_result ret;
+
+     /* printf("rect:, %d, %g, %g, %g, %g\n", p->stop->nevals, c[0], c[1], w[0], w[1]); */
+
+     /* check xtol */
+     for (i = 0; i < n; ++i)
+	  if (w[i] > p->stop->xtol_rel * (ub[i] - lb[i])
+	      && w[i] > p->stop->xtol_abs[i])
+	       break;
+     if (i == n) return NLOPT_XTOL_REACHED;
+
+     if (p->randomized_div) { /* randomly pick among ~largest sides */
+	  int nlongest = 0;
+	  wmax = longest(n, w);
+	  for (i = 0; i < n; ++i)
+	       if (wmax - w[i] < EQUAL_SIDE_TOL * wmax) ++nlongest;
+	  i = 1 + nlopt_iurand(nlongest);
+	  for (idiv = 0; idiv < n; ++idiv) {
+	       if (wmax - w[idiv] < EQUAL_SIDE_TOL * wmax) --i;
+	       if (!i) break;
+	  }
+     }
+     else { /* just pick first largest side */
+	  wmax = w[idiv = 0];
+	  for (i = 1; i < n; ++i) if (w[i] > wmax) wmax = w[idiv = i];
+     }
+
+     if (fabs(x[idiv] - c[idiv]) > (0.5 * THIRD) * w[idiv]) { /* bisect */
+	  double deltac = (x[idiv] > c[idiv] ? 0.25 : -0.25) * w[idiv];
+	  w[idiv] *= 0.5;
+	  c[idiv] += deltac;
+	  r[0] = longest(n, w); /* new diameter */
+	  /* r[1] unchanged since still contains local optimum x */
+	  r[2] = p->age--;
+	  node = rb_tree_resort(&p->rtree, node);
+
+	  rnew = (double *) malloc(sizeof(double) * L);
+	  if (!rnew) return NLOPT_OUT_OF_MEMORY;
+	  memcpy(rnew, r, sizeof(double) * L);
+	  rnew[2] = p->age--;
+	  rnew[3+n+idiv] -= deltac*2;
+	  if (p->randomized_div)
+	       randomize_x(n, rnew);
+	  else
+	       memcpy(rnew+3, rnew+3+n, sizeof(double) * n); /* x = c */
+	  ret = optimize_rect(rnew, p);
+	  if (ret != NLOPT_SUCCESS) { free(rnew); return ret; }
+	  if (!rb_tree_insert(&p->rtree, rnew)) {
+	       free(rnew); return NLOPT_OUT_OF_MEMORY;
+	  }
+     }
+     else { /* trisect */
+	  w[idiv] *= THIRD;
+	  r[0] = longest(n, w);
+	  /* r[1] unchanged since still contains local optimum x */
+	  r[2] = p->age--;
+	  node = rb_tree_resort(&p->rtree, node);
+
+	  for (i = -1; i <= +1; i += 2) {
+	       rnew = (double *) malloc(sizeof(double) * L);
+	       if (!rnew) return NLOPT_OUT_OF_MEMORY;
+	       memcpy(rnew, r, sizeof(double) * L);
+	       rnew[2] = p->age--;
+	       rnew[3+n+idiv] += w[i] * i;
+	       if (p->randomized_div)
+		    randomize_x(n, rnew);
+	       else
+		    memcpy(rnew+3, rnew+3+n, sizeof(double) * n); /* x = c */
+	       ret = optimize_rect(rnew, p);
+	       if (ret != NLOPT_SUCCESS) { free(rnew); return ret; }
+	       if (!rb_tree_insert(&p->rtree, rnew)) {
+		    free(rnew); return NLOPT_OUT_OF_MEMORY;
+	       }
+	  }
+     }
+     if (p->minf < minf_start && nlopt_stop_f(p->stop, p->minf, minf_start))
+	  return NLOPT_FTOL_REACHED;
+     return NLOPT_SUCCESS;
+}
+
+/************************************************************************/
+
+nlopt_result cdirect_hybrid_unscaled(int n, nlopt_func f, void *f_data,
+				     const double *lb, const double *ub,
+				     double *x,
+				     double *minf,
+				     nlopt_stopping *stop,
+				     nlopt_algorithm local_alg,
+				     int local_maxeval,
+				     int randomized_div)
+{
+     params p;
+     int i;
+     double *rnew;
+     nlopt_result ret = NLOPT_OUT_OF_MEMORY;
+
+     p.n = n;
+     p.L = 3*n+3;
+     p.lb = lb; p.ub = ub;
+     p.stop = stop;
+     p.f = f;
+     p.f_data = f_data;
+     p.minf = HUGE_VAL;
+     p.xmin = x;
+     p.age = 0;
+     p.work = 0;
+     p.local_alg = local_alg;
+     p.local_maxeval = local_maxeval;
+     p.randomized_div = randomized_div;
+
+     rb_tree_init(&p.rtree, cdirect_hyperrect_compare);
+     p.work = (double *) malloc(sizeof(double) * (2*n));
+     if (!p.work) goto done;
+     
+     if (!(rnew = (double *) malloc(sizeof(double) * p.L))) goto done;
+     for (i = 0; i < n; ++i) {
+          rnew[3+i] = rnew[3+n+i] = 0.5 * (lb[i] + ub[i]);
+          rnew[3+2*n+i] = ub[i] - lb[i];
+     }
+     rnew[0] = longest(n, rnew+2*n);
+     rnew[2] = p.age--;
+     ret = optimize_rect(rnew, &p);
+     if (ret != NLOPT_SUCCESS) { free(rnew); goto done; }
+     if (!rb_tree_insert(&p.rtree, rnew)) { free(rnew); goto done; }
+
+     do {
+	  ret = divide_largest(&p);
+     } while (ret == NLOPT_SUCCESS);
+
+ done:
+     rb_tree_destroy_with_keys(&p.rtree);
+     free(p.work);
+	      
+     *minf = p.minf;
+     return ret;
+}
+
+/* rescaled to unit hypercube so that all x[i] are weighted equally  */
+nlopt_result cdirect_hybrid(int n, nlopt_func f, void *f_data,
+			    const double *lb, const double *ub,
+			    double *x,
+			    double *minf,
+			    nlopt_stopping *stop,
+			    nlopt_algorithm local_alg,
+			    int local_maxeval,
+			    int randomized_div)
+{
+     cdirect_uf_data d;
+     nlopt_result ret;
+     const double *xtol_abs_save;
+     int i;
+
+     d.f = f; d.f_data = f_data; d.lb = lb; d.ub = ub;
+     d.x = (double *) malloc(sizeof(double) * n*4);
+     if (!d.x) return NLOPT_OUT_OF_MEMORY;
+     
+     for (i = 0; i < n; ++i) {
+	  x[i] = (x[i] - lb[i]) / (ub[i] - lb[i]);
+	  d.x[n+i] = 0;
+	  d.x[2*n+i] = 1;
+	  d.x[3*n+i] = stop->xtol_abs[i] / (ub[i] - lb[i]);
+     }
+     xtol_abs_save = stop->xtol_abs;
+     stop->xtol_abs = d.x + 3*n;
+     ret = cdirect_hybrid_unscaled(n, cdirect_uf, &d, d.x+n, d.x+2*n, 
+				   x, minf, stop, local_alg, local_maxeval,
+				   randomized_div);
+     stop->xtol_abs = xtol_abs_save;
+     for (i = 0; i < n; ++i)
+	  x[i] = lb[i]+ x[i] * (ub[i] - lb[i]);
+     free(d.x);
+     return ret;
+}

nlopt2/direct/AUTHORS

+C conversion: Steven G. Johnson (stevenj@alum.mit.edu)
+Original Fortran code: Joerg.M.Gablonsky (jmgablon@mailandnews.com)

nlopt2/direct/COPYING

+This code is based on the DIRECT 2.0.4 Fortran code by Gablonsky et al. at
+	http://www4.ncsu.edu/~ctk/SOFTWARE/DIRECTv204.tar.gz
+The C version was initially converted via f2c and then cleaned up and
+reorganized by Steven G. Johnson (stevenj@alum.mit.edu), August 2007.
+
+******** Copyright and license for the original Fortran DIRECT code ********
+Copyright (c) 1999, 2000, 2001 North Carolina State University
+
+This program is distributed under the MIT License (see
+http://www.opensource.org/licenses/mit-license.php):
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+of the Software, and to permit persons to whom the Software is furnished to do
+so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.

nlopt2/direct/DIRect.c

+/* DIRect-transp.f -- translated by f2c (version 20050501).
+   
+   f2c output hand-cleaned by SGJ (August 2007). 
+*/
+
+#include <math.h>
+#include "direct-internal.h"
+
+/* Common Block Declarations */
+
+/* Table of constant values */
+
+/* +-----------------------------------------------------------------------+ */
+/* | Program       : Direct.f                                              | */
+/* | Last modified : 07-16-2001                                            | */
+/* | Written by    : Joerg Gablonsky (jmgablon@unity.ncsu.edu)             | */
+/* |                 North Carolina State University                       | */
+/* |                 Dept. of Mathematics                                  | */
+/* | DIRECT is a method to solve problems of the form:                     | */
+/* |              min f: Q --> R,                                          | */
+/* | where f is the function to be minimized and Q is an n-dimensional     | */
+/* | hyperrectangle given by the the following equation:                   | */
+/* |                                                                       | */
+/* |       Q={ x : l(i) <= x(i) <= u(i), i = 1,...,n }.                    | */
+/* | Note: This version of DIRECT can also handle hidden constraints. By   | */
+/* |       this we mean that the function may not be defined over the whole| */
+/* |       hyperrectangle Q, but only over a subset, which is not given    | */
+/* |       analytically.                                                   | */
+/* |                                                                       | */
+/* | We now give a brief outline of the algorithm:                         | */
+/* |                                                                       | */
+/* |   The algorithm starts with mapping the hyperrectangle Q to the       | */
+/* |   n-dimensional unit hypercube. DIRECT then samples the function at   | */
+/* |   the center of this hypercube and at 2n more points, 2 in each       | */
+/* |   coordinate direction. Uisng these function values, DIRECT then      | */
+/* |   divides the domain into hyperrectangles, each having exactly one of | */
+/* |   the sampling points as its center. In each iteration, DIRECT chooses| */
+/* |   some of the existing hyperrectangles to be further divided.         | */
+/* |   We provide two different strategies of how to decide which          | */
+/* |   hyperrectangles DIRECT divides and several different convergence    | */
+/* |   criteria.                                                           | */
+/* |                                                                       | */
+/* |   DIRECT was designed to solve problems where the function f is       | */
+/* |   Lipschitz continues. However, DIRECT has proven to be effective on  | */
+/* |   more complex problems than these.                                   | */
+/* +-----------------------------------------------------------------------+ */
+/* Subroutine */ void direct_direct_(fp fcn, doublereal *x, integer *n, doublereal *eps, doublereal epsabs, integer *maxf, integer *maxt, double starttime, double maxtime, int *force_stop, doublereal *minf, doublereal *l, 
+	doublereal *u, integer *algmethod, integer *ierror, FILE *logfile, 
+	doublereal *fglobal, doublereal *fglper, doublereal *volper, 
+	doublereal *sigmaper, void *fcn_data)
+{
+    /* System generated locals */
+    integer i__1, i__2;
+    doublereal d__1;
+
+    /* changed by SGJ to be dynamically allocated ... would be
+       even better to use realloc, below, to grow these as needed */
+    integer MAXFUNC = *maxf <= 0 ? 101000 : (*maxf + 1000 + *maxf / 2);
+    integer MAXDEEP = *maxt <= 0 ? MAXFUNC/5: *maxt + 1000;
+    const integer MAXDIV = 5000;
+
+    /* Local variables */
+    integer increase;
+    doublereal *c__ = 0	/* was [90000][64] */, *f = 0	/* 
+	    was [90000][2] */;
+    integer i__, j, *s = 0	/* was [3000][2] */, t;
+    doublereal *w = 0;
+    doublereal divfactor;
+    integer ifeasiblef, iepschange, actmaxdeep;
+    integer actdeep_div__, iinfesiblef;
+    integer pos1, newtosample;
+    integer ifree, help;
+    doublereal *oldl = 0, fmax;
+    integer maxi;
+    doublereal kmax, *oldu = 0;
+    integer oops, *list2 = 0	/* was [64][2] */, cheat;
+    doublereal delta;
+    integer mdeep, *point = 0, start;
+    integer *anchor = 0, *length = 0	/* was [90000][64] */, *arrayi = 0;
+    doublereal *levels = 0, *thirds = 0;
+    integer writed;
+    doublereal epsfix;
+    integer oldpos, minpos, maxpos, tstart, actdeep, ifreeold, oldmaxf;
+    integer numfunc, version;
+    integer jones;
+
+    /* FIXME: change sizes dynamically? */
+#define MY_ALLOC(p, t, n) p = (t *) malloc(sizeof(t) * (n)); \
+                          if (!(p)) { *ierror = -100; goto cleanup; }
+
+    /* Note that I've transposed c__, length, and f relative to the 
+       original Fortran code.  e.g. length was length(maxfunc,n) 
+       in Fortran [ or actually length(maxfunc, maxdims), but by
+       using malloc I can just allocate n ], corresponding to
+       length[n][maxfunc] in C, but I've changed the code to access
+       it as length[maxfunc][n].  That is, the maxfunc direction
+       is the discontiguous one.  This makes it easier to resize
+       dynamically (by adding contiguous rows) using realloc, without
+       having to move data around manually. */
+    MY_ALLOC(c__, doublereal, MAXFUNC * (*n));
+    MY_ALLOC(length, integer, MAXFUNC * (*n));
+    MY_ALLOC(f, doublereal, MAXFUNC * 2);
+    MY_ALLOC(point, integer, MAXFUNC);
+    if (*maxf <= 0) *maxf = MAXFUNC - 1000;
+
+    MY_ALLOC(s, integer, MAXDIV * 2);
+
+    MY_ALLOC(anchor, integer, MAXDEEP + 2);
+    MY_ALLOC(levels, doublereal, MAXDEEP + 1);
+    MY_ALLOC(thirds, doublereal, MAXDEEP + 1);    
+    if (*maxt <= 0) *maxt = MAXDEEP;
+
+    MY_ALLOC(w, doublereal, (*n));
+    MY_ALLOC(oldl, doublereal, (*n));
+    MY_ALLOC(oldu, doublereal, (*n));
+    MY_ALLOC(list2, integer, (*n) * 2);
+    MY_ALLOC(arrayi, integer, (*n));
+
+/* +-----------------------------------------------------------------------+ */
+/* |    SUBROUTINE Direct                                                  | */
+/* | On entry                                                              | */
+/* |     fcn -- The argument containing the name of the user-supplied      | */
+/* |            SUBROUTINE that returns values for the function to be      | */
+/* |            minimized.                                                 | */
+/* |       n -- The dimension of the problem.                              | */
+/* |     eps -- Exceeding value. If eps > 0, we use the same epsilon for   | */
+/* |            all iterations. If eps < 0, we use the update formula from | */
+/* |            Jones:                                                     | */
+/* |               eps = max(1.D-4*abs(minf),epsfix),                      | */
+/* |            where epsfix = abs(eps), the absolute value of eps which is| */
+/* |            passed to the function.                                    | */
+/* |    maxf -- The maximum number of function evaluations.                | */
+/* |    maxT -- The maximum number of iterations.                          | */
+/* |            Direct stops when either the maximum number of iterations  | */
+/* |            is reached or more than maxf function-evalutions were made.| */
+/* |       l -- The lower bounds of the hyperbox.                          | */
+/* |       u -- The upper bounds of the hyperbox.                          | */
+/* |algmethod-- Choose the method, that is either use the original method  | */
+/* |            as described by Jones et.al. (0) or use our modification(1)| */
+/* | logfile -- File-Handle for the logfile. DIRECT expects this file to be| */
+/* |            opened and closed by the user outside of DIRECT. We moved  | */
+/* |            this to the outside so the user can add extra informations | */
+/* |            to this file before and after the call to DIRECT.          | */
+/* | fglobal -- Function value of the global optimum. If this value is not | */
+/* |            known (that is, we solve a real problem, not a testproblem)| */
+/* |            set this value to -1.D100 and fglper (see below) to 0.D0.  | */
+/* |  fglper -- Terminate the optimization when the percent error          | */
+/* |                100(f_min - fglobal)/max(1,abs(fglobal)) < fglper.     | */
+/* |  volper -- Terminate the optimization when the volume of the          | */
+/* |            hyperrectangle S with f(c(S)) = minf is less then volper   | */
+/* |            percent of the volume of the original hyperrectangle.      | */
+/* |sigmaper -- Terminate the optimization when the measure of the         | */
+/* |            hyperrectangle S with f(c(S)) = minf is less then sigmaper.| */
+/* |                                                                       | */
+/* | User data that is passed through without being changed:               | */
+/* |  fcn_data - opaque pointer to any user data                           | */
+/* |                                                                       | */
+/* | On return                                                             | */
+/* |                                                                       | */
+/* |       x -- The final point obtained in the optimization process.      | */
+/* |            X should be a good approximation to the global minimum     | */
+/* |            for the function within the hyper-box.                     | */
+/* |                                                                       | */
+/* |    minf -- The value of the function at x.                            | */
+/* |  Ierror -- Error flag. If Ierror is lower 0, an error has occured. The| */
+/* |            values of Ierror mean                                      | */
+/* |            Fatal errors :                                             | */
+/* |             -1   u(i) <= l(i) for some i.                             | */
+/* |             -2   maxf is too large.                                   | */
+/* |             -3   Initialization in DIRpreprc failed.                  | */
+/* |             -4   Error in DIRSamplepoints, that is there was an error | */
+/* |                  in the creation of the sample points.                | */
+/* |             -5   Error in DIRSamplef, that is an error occured while  | */
+/* |                  the function was sampled.                            | */
+/* |             -6   Error in DIRDoubleInsert, that is an error occured   | */
+/* |                  DIRECT tried to add all hyperrectangles with the same| */
+/* |                  size and function value at the center. Either        | */
+/* |                  increase maxdiv or use our modification (Jones = 1). | */
+/* |            Termination values :                                       | */
+/* |              1   Number of function evaluations done is larger then   | */
+/* |                  maxf.                                                | */
+/* |              2   Number of iterations is equal to maxT.               | */
+/* |              3   The best function value found is within fglper of    | */
+/* |                  the (known) global optimum, that is                  | */
+/* |                   100(minf - fglobal/max(1,|fglobal|))  < fglper.     | */
+/* |                  Note that this termination signal only occurs when   | */
+/* |                  the global optimal value is known, that is, a test   | */
+/* |                  function is optimized.                               | */
+/* |              4   The volume of the hyperrectangle with minf at its    | */
+/* |                  center is less than volper percent of the volume of  | */
+/* |                  the original hyperrectangle.                         | */
+/* |              5   The measure of the hyperrectangle with minf at its   | */
+/* |                  center is less than sigmaper.                        | */
+/* |                                                                       | */
+/* | SUBROUTINEs used :                                                    | */
+/* |                                                                       | */
+/* | DIRheader, DIRInitSpecific, DIRInitList, DIRpreprc, DIRInit, DIRChoose| */
+/* | DIRDoubleInsert, DIRGet_I, DIRSamplepoints, DIRSamplef, DIRDivide     | */
+/* | DIRInsertList, DIRreplaceInf, DIRWritehistbox, DIRsummary, Findareas  | */
+/* |                                                                       | */
+/* | Functions used :                                                      | */
+/* |                                                                       | */
+/* | DIRgetMaxdeep, DIRgetlevel                                            | */
+/* +-----------------------------------------------------------------------+ */
+/* +-----------------------------------------------------------------------+ */
+/* | Parameters                                                            | */
+/* +-----------------------------------------------------------------------+ */
+/* +-----------------------------------------------------------------------+ */
+/* | The maximum of function evaluations allowed.                          | */
+/* | The maximum dept of the algorithm.                                    | */
+/* | The maximum number of divisions allowed.                              | */
+/* | The maximal dimension of the problem.                                 | */
+/* +-----------------------------------------------------------------------+ */
+/* +-----------------------------------------------------------------------+ */
+/* | Global Variables.                                                     | */
+/* +-----------------------------------------------------------------------+ */
+/* +-----------------------------------------------------------------------+ */
+/* | EXTERNAL Variables.                                                   | */
+/* +-----------------------------------------------------------------------+ */
+/* +-----------------------------------------------------------------------+ */
+/* | User Variables.                                                       | */
+/* | These can be used to pass user defined data to the function to be     | */
+/* | optimized.                                                            | */
+/* +-----------------------------------------------------------------------+ */
+/* +-----------------------------------------------------------------------+ */
+/* | Place to define, if needed, some application-specific variables.      | */
+/* | Note: You should try to use the arrays defined above for this.        | */
+/* +-----------------------------------------------------------------------+ */
+/* +-----------------------------------------------------------------------+ */
+/* | End of application - specific variables !                             | */
+/* +-----------------------------------------------------------------------+ */
+/* +-----------------------------------------------------------------------+ */
+/* | Internal variables :                                                  | */
+/* |       f -- values of functions.                                       | */
+/* |divfactor-- Factor used for termination with known global minimum.     | */
+/* |  anchor -- anchors of lists with deepness i, -1 is anchor for list of | */
+/* |            NaN - values.                                              | */
+/* |       S -- List of potentially optimal points.                        | */
+/* |   point -- lists                                                      | */
+/* |    ifree -- first free position                                        | */
+/* |       c -- midpoints of arrays                                        | */
+/* |  thirds -- Precalculated values of 1/3^i.                             | */
+/* |  levels -- Length of intervals.                                       | */
+/* |  length -- Length of intervall (index)                                | */
+/* |       t -- actual iteration                                           | */
+/* |       j -- loop-variable                                              | */
+/* | actdeep -- the actual minimal interval-length index                   | */
+/* |  Minpos -- position of the actual minimum                             | */
+/* |    file -- The filehandle for a datafile.                             | */
+/* |  maxpos -- The number of intervalls, which are truncated.             | */
+/* |    help -- A help variable.                                           | */
+/* | numfunc -- The actual number of function evaluations.                 | */
+/* |   file2 -- The filehandle for an other datafile.                      | */
+/* |  ArrayI -- Array with the indexes of the sides with maximum length.   | */
+/* |    maxi -- Number of directions with maximal side length.             | */
+/* |    oops -- Flag which shows if anything went wrong in the             | */
+/* |            initialisation.                                            | */
+/* |   cheat -- Obsolete. If equal 1, we don't allow Ktilde > kmax.        | */
+/* |  writed -- If writed=1, store final division to plot with Matlab.     | */
+/* |   List2 -- List of indicies of intervalls, which are to be truncated. | */
+/* |       i -- Another loop-variable.                                     | */
+/* |actmaxdeep-- The actual maximum (minimum) of possible Interval length. | */
+/* |  oldpos -- The old index of the minimum. Used to print only, if there | */
+/* |            is a new minimum found.                                    | */
+/* |  tstart -- The start of the outer loop.                               | */
+/* |   start -- The postion of the starting point in the inner loop.       | */
+/* | Newtosample -- The total number of points to sample in the inner loop.| */
+/* |       w -- Array used to divide the intervalls                        | */
+/* |    kmax -- Obsolete. If cheat = 1, Ktilde was not allowed to be larger| */
+/* |            than kmax. If Ktilde > kmax, we set ktilde = kmax.         | */
+/* |   delta -- The distance to new points from center of old hyperrec.    | */
+/* |    pos1 -- Help variable used as an index.                            | */
+/* | version -- Store the version number of DIRECT.                        | */
+/* | oldmaxf -- Store the original function budget.                        | */
+/* |increase -- Flag used to keep track if function budget was increased   | */
+/* |            because no feasible point was found.                       | */
+/* | ifreeold -- Keep track which index was free before. Used with          | */
+/* |            SUBROUTINE DIRReplaceInf.                                  | */
+/* |actdeep_div-- Keep track of the current depths for divisions.          | */
+/* |    oldl -- Array used to store the original bounds of the domain.     | */
+/* |    oldu -- Array used to store the original bounds of the domain.     | */
+/* |  epsfix -- If eps < 0, we use Jones update formula. epsfix stores the | */
+/* |            absolute value of epsilon.                                 | */
+/* |iepschange-- flag iepschange to store if epsilon stays fixed or is     | */
+/* |             changed.                                                  | */
+/* |DIRgetMaxdeep-- Function to calculate the level of a hyperrectangle.   | */
+/* |DIRgetlevel-- Function to calculate the level and stage of a hyperrec. | */
+/* |    fmax -- Keep track of the maximum value of the function found.     | */
+/* |Ifeasiblef-- Keep track if a feasible point has  been found so far.    | */
+/* |             Ifeasiblef = 0 means a feasible point has been found,     | */
+/* |             Ifeasiblef = 1 no feasible point has been found.          | */
+/* +-----------------------------------------------------------------------+ */
+/* +-----------------------------------------------------------------------+ */
+/* | JG 09/25/00 Version counter.                                          | */
+/* +-----------------------------------------------------------------------+ */
+/* +-----------------------------------------------------------------------+ */
+/* | JG 09/24/00 Add another actdeep to keep track of the current depths   | */
+/* |             for divisions.                                            | */
+/* +-----------------------------------------------------------------------+ */
+/* +-----------------------------------------------------------------------+ */
+/* |JG 01/13/01 Added epsfix for epsilon update. If eps < 0, we use Jones  | */
+/* |            update formula. epsfix stores the absolute value of epsilon| */
+/* |            then. Also added flag iepschange to store if epsilon stays | */
+/* |            fixed or is changed.                                       | */
+/* +-----------------------------------------------------------------------+ */
+/* +-----------------------------------------------------------------------+ */
+/* | JG 01/22/01 fmax is used to keep track of the maximum value found.    | */
+/* +-----------------------------------------------------------------------+ */
+/* +-----------------------------------------------------------------------+ */
+/* | JG 01/22/01 Ifeasiblef is used to keep track if a feasible point has  | */
+/* |             been found so far. Ifeasiblef = 0 means a feasible point  | */
+/* |             has been found, Ifeasiblef = 1 if not.                    | */
+/* | JG 03/09/01 IInfeasible is used to keep track if an infeasible point  | */
+/* |             has been found. IInfeasible > 0 means a infeasible point  | */
+/* |             has been found, IInfeasible = 0 if not.                   | */
+/* +-----------------------------------------------------------------------+ */
+/* +-----------------------------------------------------------------------+ */
+/* +-----------------------------------------------------------------------+ */
+/* |                            Start of code.                             | */
+/* +-----------------------------------------------------------------------+ */
+/* +-----------------------------------------------------------------------+ */
+    /* Parameter adjustments */
+    --u;
+    --l;
+    --x;
+
+    /* Function Body */
+    writed = 0;
+    jones = *algmethod;
+/* +-----------------------------------------------------------------------+ */
+/* | Save the upper and lower bounds.                                      | */
+/* +-----------------------------------------------------------------------+ */
+    i__1 = *n;
+    for (i__ = 1; i__ <= i__1; ++i__) {
+	oldu[i__ - 1] = u[i__];
+	oldl[i__ - 1] = l[i__];
+/* L150: */
+    }
+/* +-----------------------------------------------------------------------+ */
+/* | Set version.                                                          | */
+/* +-----------------------------------------------------------------------+ */
+    version = 204;
+/* +-----------------------------------------------------------------------+ */
+/* | Set parameters.                                                       | */
+/* |    If cheat > 0, we do not allow \tilde{K} to be larger than kmax, and| */
+/* |    set \tilde{K} to set value if necessary. Not used anymore.         | */
+/* +-----------------------------------------------------------------------+ */
+    cheat = 0;
+    kmax = 1e10;
+    mdeep = MAXDEEP;
+/* +-----------------------------------------------------------------------+ */
+/* | Write the header of the logfile.                                      | */
+/* +-----------------------------------------------------------------------+ */
+    direct_dirheader_(logfile, &version, &x[1], n, eps, maxf, maxt, &l[1], &u[1], 
+	    algmethod, &MAXFUNC, &MAXDEEP, fglobal, fglper, ierror, &epsfix, &
+		      iepschange, volper, sigmaper);
+/* +-----------------------------------------------------------------------+ */
+/* | If an error has occured while writing the header (we do some checking | */
+/* | of variables there), return to the main program.                      | */
+/* +-----------------------------------------------------------------------+ */
+    if (*ierror < 0) {
+	goto cleanup;
+    }
+/* +-----------------------------------------------------------------------+ */
+/* | If the known global minimum is equal 0, we cannot divide by it.       | */
+/* | Therefore we set it to 1. If not, we set the divisionfactor to the    | */
+/* | absolute value of the global minimum.                                 | */
+/* +-----------------------------------------------------------------------+ */
+    if (*fglobal == 0.) {
+	divfactor = 1.;
+    } else {
+	divfactor = fabs(*fglobal);
+    }
+/* +-----------------------------------------------------------------------+ */
+/* | Save the budget given by the user. The variable maxf will be changed  | */
+/* | if in the beginning no feasible points are found.                     | */
+/* +-----------------------------------------------------------------------+ */
+    oldmaxf = *maxf;
+    increase = 0;
+/* +-----------------------------------------------------------------------+ */
+/* | Initialiase the lists.                                                | */
+/* +-----------------------------------------------------------------------+ */
+    direct_dirinitlist_(anchor, &ifree, point, f, &MAXFUNC, &MAXDEEP);
+/* +-----------------------------------------------------------------------+ */
+/* | Call the routine to initialise the mapping of x from the n-dimensional| */
+/* | unit cube to the hypercube given by u and l. If an error occured,     | */
+/* | give out a error message and return to the main program with the error| */
+/* | flag set.                                                             | */
+/* | JG 07/16/01 Changed call to remove unused data.                       | */
+/* +-----------------------------------------------------------------------+ */
+    direct_dirpreprc_(&u[1], &l[1], n, &l[1], &u[1], &oops);
+    if (oops > 0) {
+	if (logfile)
+	     fprintf(logfile,"WARNING: Initialization in DIRpreprc failed.\n");
+	*ierror = -3;
+	goto cleanup;
+    }
+    tstart = 2;
+/* +-----------------------------------------------------------------------+ */
+/* | Initialise the algorithm DIRECT.                                      | */
+/* +-----------------------------------------------------------------------+ */
+/* +-----------------------------------------------------------------------+ */
+/* | Added variable to keep track of the maximum value found.              | */
+/* +-----------------------------------------------------------------------+ */
+    direct_dirinit_(f, fcn, c__, length, &actdeep, point, anchor, &ifree,
+	    logfile, arrayi, &maxi, list2, w, &x[1], &l[1], &u[1], 
+	    minf, &minpos, thirds, levels, &MAXFUNC, &MAXDEEP, n, n, &
+	    fmax, &ifeasiblef, &iinfesiblef, ierror, fcn_data, jones,
+		    starttime, maxtime, force_stop);
+/* +-----------------------------------------------------------------------+ */
+/* | Added error checking.                                                 | */
+/* +-----------------------------------------------------------------------+ */
+    if (*ierror < 0) {
+	if (*ierror == -4) {
+	    if (logfile)
+		 fprintf(logfile, "WARNING: Error occured in routine DIRsamplepoints.\n");
+	    goto cleanup;
+	}
+	if (*ierror == -5) {
+	    if (logfile)
+		 fprintf(logfile, "WARNING: Error occured in routine DIRsamplef..\n");
+	    goto cleanup;
+	}
+	if (*ierror == -102) goto L100;
+    }
+    else if (*ierror == DIRECT_MAXTIME_EXCEEDED) goto L100;
+    numfunc = maxi + 1 + maxi;
+    actmaxdeep = 1;
+    oldpos = 0;
+    tstart = 2;
+/* +-----------------------------------------------------------------------+ */
+/* | If no feasible point has been found, give out the iteration, the      | */
+/* | number of function evaluations and a warning. Otherwise, give out     | */
+/* | the iteration, the number of function evaluations done and minf.      | */
+/* +-----------------------------------------------------------------------+ */
+    if (ifeasiblef > 0) {
+	 if (logfile)
+	      fprintf(logfile, "No feasible point found in %d iterations "
+		      "and %d function evaluations.\n", tstart-1, numfunc);
+    } else {
+	 if (logfile)
+	      fprintf(logfile, "%d, %d, %g, %g\n", 
+		      tstart-1, numfunc, *minf, fmax);
+    }
+/* +-----------------------------------------------------------------------+ */
+/* +-----------------------------------------------------------------------+ */
+/* | Main loop!                                                            | */
+/* +-----------------------------------------------------------------------+ */
+/* +-----------------------------------------------------------------------+ */
+    i__1 = *maxt;
+    for (t = tstart; t <= i__1; ++t) {
+/* +-----------------------------------------------------------------------+ */
+/* | Choose the sample points. The indices of the sample points are stored | */
+/* | in the list S.                                                        | */
+/* +-----------------------------------------------------------------------+ */
+	actdeep = actmaxdeep;
+	direct_dirchoose_(anchor, s, &MAXDEEP, f, minf, *eps, epsabs, levels, &maxpos, length,