Skip to contents

The interface of OptimizationNLopt.jl: Algorithm(name) is an NLopt algorithm identifier such as "LD_LBFGS" (also given by its number in the NLopt enumeration, from 0), NLopt holds a constructor for each identifier (NLopt$LN_COBYLA()) and NLopt's srand(seed) and srand_time(), and Opt(algorithm, n) is an optimizer for n unknowns whose settings (xtol_rel, xtol_abs, ftol_rel, ftol_abs, maxeval, maxtime, stopval, initial_step, local_optimizer, lower_bounds, upper_bounds, population, vector_storage and the algorithm parameters params) are fields set with $<-. An algorithm or an Opt is passed to solve().

Usage

Algorithm(name)

NLopt

Opt(algorithm, n)

Arguments

name

An algorithm name (with or without the NLOPT_ prefix) or its number.

algorithm

An Algorithm or its name.

n

The number of unknowns.

Value

Algorithm() an algorithm object, Opt() an optimizer object (an environment).

Details

The algorithms are native R ports of the C code of NLopt 2.11.0, so they take the steps of NLopt: LN_NELDERMEAD (the Nelder Mead simplex with bounds), LN_SBPLX (Rowan's subplex), GN_CRS2_LM (controlled random search), GN_ESCH (an evolutionary strategy), GN_ISRES (stochastic ranking evolution), LD_MMA and LD_CCSAQ (conservative convex separable approximations), the augmented Lagrangian family (AUGLAG, AUGLAG_EQ, LN_AUGLAG, LN_AUGLAG_EQ, LD_AUGLAG, LD_AUGLAG_EQ) and the multi level single linkage family (G_MLSL, G_MLSL_LDS, GN_MLSL, GD_MLSL, GN_MLSL_LDS, GD_MLSL_LDS), the DIRECT family (GN_DIRECT, GN_DIRECT_L, GN_DIRECT_L_RAND and their _NOSCAL variants, and Gablonsky's GN_ORIG_DIRECT and GN_ORIG_DIRECT_L), LN_PRAXIS (Brent's principal axis method), GD_STOGO and GD_STOGO_RAND (branch and bound with trust region BFGS searches), GN_AGS (the index method on a Peano evolvent), Luksan's limited memory and truncated Newton methods (LD_LBFGS, LD_VAR1, LD_VAR2, LD_TNEWTON, LD_TNEWTON_RESTART, LD_TNEWTON_PRECOND, LD_TNEWTON_PRECOND_RESTART), Powell's LN_COBYLA, LN_NEWUOA, LN_NEWUOA_BOUND and LN_BOBYQA, and Kraft's LD_SLSQP. LD_LBFGS_NOCEDAL has no implementation in NLopt and returns INVALID_ARGS (a Failure). The stochastic algorithms draw from NLopt's Mersenne Twister, seeded by NLopt$srand(seed) (from the clock otherwise).

The constraints lcons <= cons(u) <= ucons become NLopt's equality constraints cons(u) - lcons = 0 (when lcons == ucons) and inequality constraints cons(u) - ucons <= 0 and lcons - cons(u) <= 0, with the tolerance cons_tol (default 1e-6). maxiters sets maxeval, maxtime sets maxtime, abstol sets ftol_abs and reltol sets ftol_rel; local_method, local_maxiters, local_maxtime and local_options configure the local optimizer of the AUGLAG and MLSL algorithms, and any other option of solve() becomes an algorithm parameter (NLopt's nlopt_set_param). The stopval of an Opt stops the search at the first point at least that good, and maxtime after that many seconds (return codes STOPVAL_REACHED, a Success, and MAXTIME_REACHED, MaxTime).

Examples

prob <- OptimizationProblem(function(u, p) (u[1] - 1) * (u[1] - 1) + 2 * (u[2] + 1) * (u[2] + 1),
                            c(0, 0), numeric())
solve(prob, NLopt$LN_NELDERMEAD(), maxiters = 400)$u
#> [1]  1 -1
opt <- Opt("LN_SBPLX", 2)
opt$xtol_rel <- 1e-8
solve(prob, opt)$u
#> [1]  1 -1