DEoptimR/0000755000175100001440000000000012612456330011755 5ustar hornikusersDEoptimR/inst/0000755000175100001440000000000012612443654012737 5ustar hornikusersDEoptimR/inst/xtraR/0000755000175100001440000000000012612443654014037 5ustar hornikusersDEoptimR/inst/xtraR/opt-test-funs.R0000644000175100001440000001211112250315111016666 0ustar hornikusersswf <- function(x) { ## Schwefel problem ## ## -500 <= xi <= 500, i = {1, 2, ..., n} ## The number of local minima for a given n is not known, but the global minimum ## f(x*) = -418.9829n is located at x* = (s, s, ..., s), s = 420.97. ## ## Source: ## Ali, M. Montaz, Khompatraporn, Charoenchai, and Zabinsky, Zelda B. (2005). ## A numerical evaluation of several stochastic algorithms on selected ## continuous global optimization test problems. ## Journal of Global Optimization 31, 635-672. -crossprod( x, sin(sqrt(abs(x))) ) } sf1 <- function(x) { ## Schaffer 1 problem ## ## -100 <= x1, x2 <= 100 ## The number of local minima is not known but ## the global minimum is located at x* = (0, 0) with f(x*) = 0. ## ## Source: ## Ali, M. Montaz, Khompatraporn, Charoenchai, and Zabinsky, Zelda B. (2005). ## A numerical evaluation of several stochastic algorithms on selected ## continuous global optimization test problems. ## Journal of Global Optimization 31, 635-672. temp <- x[1]^2 + x[2]^2 0.5 + (sin(sqrt(temp))^2 - 0.5)/(1 + 0.001*temp)^2 } RND <- list(obj = function(x) { ## Reactor network design ## ## 1e-5 <= x5, x6 <= 16 ## It possesses two local solutions at x = (16, 0) with f = -0.37461 ## and at x = (0, 16) with f = -0.38808. ## The global optimum is (x5, x6; f) = (3.036504, 5.096052; -0.388812). ## ## Source: ## Babu, B. V., and Angira, Rakesh (2006). ## Modified differential evolution (MDE) for optimization of nonlinear ## chemical processes. ## Computers and Chemical Engineering 30, 989-1002. x5 <- x[1]; x6 <- x[2] k1 <- 0.09755988; k2 <- 0.99*k1; k3 <- 0.0391908; k4 <- 0.9*k3 -( k2*x6*(1 + k3*x5) + k1*x5*(1 + k2*x6) ) / ( (1 + k1*x5)*(1 + k2*x6)* (1 + k3*x5)*(1 + k4*x6) ) }, con = function(x) sqrt(x[1]) + sqrt(x[2]) - 4 ) HEND <- list(obj = function(x) { ## Heat exchanger network design ## ## 100 <= x1 <= 10000, 1000 <= x2, x3 <= 10000, ## 10 <= x4, x5 <= 1000 ## The global optimum is (x1, x2, x3, x4, x5; f) = (579.19, 1360.13, ## 5109.92, 182.01, 295.60; 7049.25). ## ## Source: ## Babu, B. V., and Angira, Rakesh (2006). ## Modified differential evolution (MDE) for optimization of nonlinear ## chemical processes. ## Computers and Chemical Engineering 30, 989-1002. x[1] + x[2] + x[3] }, con = function(x) { x1 <- x[1]; x2 <- x[2]; x3 <- x[3]; x4 <- x[4]; x5 <- x[5] c(100*x1 - x1*(400 -x4) + 833.33252*x4 -83333.333, x2*x4 - x2*(400 - x5 + x4) - 1250*x4 + 1250*x5, x3*x5 - x3*(100 + x5) - 2500*x5 + 1250000) }) alkylation <- list(obj = function(x) { ## Optimal operation of alkylation unit ## ## Variable Lower Bound Upper Bound ## ------------------------------------ ## x1 1500 2000 ## x2 1 120 ## x3 3000 3500 ## x4 85 93 ## x5 90 95 ## x6 3 12 ## x7 145 162 ## ------------------------------------ ## The maximum profit is $1766.36 per day, and the optimal ## variable values are x1 = 1698.256922, x2 = 54.274463, x3 = 3031.357313, ## x4 = 90.190233, x5 = 95.0, x6 = 10.504119, x7 = 153.535355. ## ## Source: ## Babu, B. V., and Angira, Rakesh (2006). ## Modified differential evolution (MDE) for optimization of nonlinear ## chemical processes. ## Computers and Chemical Engineering 30, 989-1002. x1 <- x[1]; x3 <- x[3] 1.715*x1 + 0.035*x1*x[6] + 4.0565*x3 +10.0*x[2] - 0.063*x3*x[5] }, con = function(x) { x1 <- x[1]; x2 <- x[2]; x3 <- x[3]; x4 <- x[4] x5 <- x[5]; x6 <- x[6]; x7 <- x[7] c(0.0059553571*x6^2*x1 + 0.88392857*x3 - 0.1175625*x6*x1 - x1, 1.1088*x1 + 0.1303533*x1*x6 - 0.0066033*x1*x6^2 - x3, 6.66173269*x6^2 + 172.39878*x5 -56.596669*x4 - 191.20592*x6 - 10000, 1.08702*x6 + 0.32175*x4 - 0.03762*x6^2 - x5 + 56.85075, 0.006198*x7*x4*x3 + 2462.3121*x2 -25.125634*x2*x4 - x3*x4, 161.18996*x3*x4 + 5000.0*x2*x4 - 489510.0*x2 - x3*x4*x7, 0.33*x7 - x5 + 44.333333, 0.022556*x5 - 0.007595*x7 - 1.0, 0.00061*x3 - 0.0005*x1 - 1.0, 0.819672*x1 - x3 + 0.819672, 24500.0*x2 - 250.0*x2*x4 - x3*x4, 1020.4082*x4*x2 - 1.2244898*x3*x4 - 100000*x2, 6.25*x1*x6 + 6.25*x1 - 7.625*x3 - 100000, 1.22*x3 - x6*x1 - x1 + 1.0) }) DEoptimR/tests/0000755000175100001440000000000012612443654013124 5ustar hornikusersDEoptimR/tests/JDEoptim-tst.R0000644000175100001440000000345212274017112015524 0ustar hornikusersrequire("DEoptimR") c.time <- function(...) cat('Time elapsed: ', ..., '\n') S.time <- function(expr) c.time(system.time(expr)) source(system.file("xtraR/opt-test-funs.R", package = "DEoptimR")) ## sf1(), swf() + RND, HEND, and alkylation list of $obj and $con testing functions (doExtras <- DEoptimR:::doExtras()) set.seed(2345) S.time(sf1. <- JDEoptim(c(-100, -100), c(100, 100), sf1, NP = 50, tol = 1e-7, maxiter = 800)) S.time(swf. <- JDEoptim(rep(-500, 10), rep(500, 10), swf, tol = 1e-7)) S.time(RND. <- JDEoptim(c(1e-5, 1e-5), c(16, 16), RND$obj, RND$con, NP = 40, tol = 1e-7)) S.time(HEND. <- JDEoptim(c( 100, 1000, 1000 , 10, 10), c(10000, 10000, 10000, 1000, 1000), fn = HEND$obj, constr = HEND$con, tol = 1e-4, trace = TRUE)) if(doExtras) S.time(alkylation. <- JDEoptim(c(1500, 1, 3000, 85, 90, 3, 145), c(2000, 120, 3500, 93, 95, 12, 162), fn = alkylation$obj, constr = alkylation$con, tol = 0.1, trace = TRUE)) bare.p.v <- function(r) unlist(unname(r[c("par", "value")])) stopifnot( all.equal( bare.p.v(sf1.), c(0, 0, 0), tolerance = 1e-4 ), all.equal( bare.p.v(swf.), c(rep(420.97, 10), -418.9829*10), tolerance = 1e-4 ), all.equal( bare.p.v(RND.), c(3.036504, 5.096052, -0.388812), tolerance = 1e-2 ), all.equal( bare.p.v(HEND.), c(579.19, 1360.13, 5109.92, 182.01, 295.60, 7049.25), tolerance = 1e-3 ), if(doExtras) all.equal( bare.p.v(alkylation.), c(1698.256922, 54.274463, 3031.357313, 90.190233, 95.0, 10.504119, 153.535355, -1766.36), tolerance = 1e-2 ) else TRUE ) c.time(proc.time()) DEoptimR/NAMESPACE0000644000175100001440000000006612552735372013207 0ustar hornikusersimportFrom( stats, runif, median ) export( JDEoptim ) DEoptimR/NEWS0000644000175100001440000000042312262410107012444 0ustar hornikusers CHANGES IN DEoptimR VERSION 1.0-0 NEW FEATURES - First release of DEoptimR: implementation of a variant of the jDE algorithm. - Constraint handling based on biasing feasible over unfeasible solutions by a parameter-less variant of the epsilon-constrained method.DEoptimR/R/0000755000175100001440000000000012612443654012163 5ustar hornikusersDEoptimR/R/JDEoptim.R0000644000175100001440000002642312515122076013762 0ustar hornikusersJDEoptim <- function(lower, upper, fn, constr = NULL, meq = 0, eps = 1e-5, NP = 10*d, Fl = 0.1, Fu = 1, tau1 = 0.1, tau2 = 0.1, tau3 = 0.1, jitter_factor = 0.001, tol = 1e-15, maxiter = 200*d, fnscale = 1, FUN = c("median", "max"), add_to_init_pop = NULL, trace = FALSE, triter = 1, details = FALSE, ...) # Copyright 2013, 2014, Eduardo L. T. Conceicao # Available under the GPL (>= 2) { handle.bounds <- function(x, u) { # Check feasibility of bounds and enforce parameters limits # by a deterministic variant of bounce-back resetting # Price, KV, Storn, RM, and Lampinen, JA (2005) # Differential Evolution: A Practical Approach to Global Optimization. # Springer, p 206 bad <- x > upper x[bad] <- 0.5*(upper[bad] + u[bad]) bad <- x < lower x[bad] <- 0.5*(lower[bad] + u[bad]) x } performReproduction <- function() { ignore <- runif(d) > CRtrial if (all(ignore)) # ensure that trial gets at least ignore[sample(d, 1)] <- FALSE # one mutant parameter # Source for trial is the base vector plus weighted differential trial <- if (runif(1) <= pFtrial) X.base + Ftrial*(X.r1 - X.r2) else X.base + 0.5*(Ftrial + 1)*(X.r1 + X.r2 - 2*X.base) # or trial parameter comes from target vector X.i itself. trial[ignore] <- X.i[ignore] trial } which.best <- if (!is.null(constr)) function(x) { ind <- TAVpop <= mu if (all(ind)) which.min(x) else if (any(ind)) which(ind)[which.min(x[ind])] else which.min(TAVpop) } else which.min # Check input parameters FUN <- match.arg(FUN) d <- length(lower) if (length(upper) != d) stop("'lower' must have same length as 'upper'") stopifnot(is.numeric(lower), is.numeric(upper), is.finite(lower), is.finite(upper), lower <= upper, length(fnscale) == 1, is.finite(fnscale), fnscale > 0, is.function(fn)) if (!is.null(constr)) { stopifnot(is.function(constr)) stopifnot(length(meq) == 1, meq == as.integer(meq), meq >= 0, is.numeric(eps), is.finite(eps), eps > 0) if (length(eps) == 1) eps <- rep.int(eps, meq) else if (length(eps) != meq) stop("eps must be either of length meq, or length 1") } stopifnot(length(NP) == 1, NP == as.integer(NP), length(Fl) == 1, is.numeric(Fl), length(Fu) == 1, is.numeric(Fu), Fl <= Fu) stopifnot(length(tau1) == 1, is.numeric(tau1), 0 <= tau1, tau1 <= 1, length(tau2) == 1, is.numeric(tau2), 0 <= tau2, tau2 <= 1, length(tau3) == 1, is.numeric(tau3), 0 <= tau3, tau3 <= 1) if (!is.null(jitter_factor)) stopifnot(length(jitter_factor) == 1, is.numeric(jitter_factor)) stopifnot(length(tol) == 1, is.numeric(tol), length(maxiter) == 1, maxiter == as.integer(maxiter), length(triter) == 1, triter == as.integer(triter)) if (!is.null(add_to_init_pop)) stopifnot(NROW(add_to_init_pop) == d, is.numeric(add_to_init_pop), add_to_init_pop >= lower, add_to_init_pop <= upper) # Initialization: child <- if (is.null(constr)) { expression({ ftrial <- fn1(trial) # Evaluate trial with your function if (ftrial <= fpop[i]) { pop[, i] <- trial fpop[i] <- ftrial F[, i] <- Ftrial CR[i] <- CRtrial pF[i] <- pFtrial } }) } else if (meq > 0) { # equality constraints are present # alongside the inequalities # Zhang, Haibo, and Rangaiah, G. P. (2012). # An efficient constraint handling method with integrated differential # evolution for numerical and engineering optimization. # Computers and Chemical Engineering 37, 74-88. expression({ htrial <- constr1(trial) TAVtrial <- sum( pmax(htrial, 0) ) if (TAVtrial > mu) { if (TAVtrial <= TAVpop[i]) { # trial and target are both pop[, i] <- trial # unfeasible, the one with smaller hpop[, i] <- htrial # constraint violation is chosen F[, i] <- Ftrial # or trial vector when both are CR[i] <- CRtrial # solutions of equal quality pF[i] <- pFtrial TAVpop[i] <- TAVtrial } } else if (TAVpop[i] > mu) { # trial is feasible and target is not pop[, i] <- trial fpop[i] <- fn1(trial) hpop[, i] <- htrial F[, i] <- Ftrial CR[i] <- CRtrial pF[i] <- pFtrial TAVpop[i] <- TAVtrial } else { # between two feasible solutions, the ftrial <- fn1(trial) # one with better objective function if (ftrial <= fpop[i]) { # value is chosen pop[, i] <- trial # or trial vector when both are fpop[i] <- ftrial # solutions of equal quality hpop[, i] <- htrial F[, i] <- Ftrial CR[i] <- CRtrial pF[i] <- pFtrial TAVpop[i] <- TAVtrial FF <- sum(TAVpop <= mu)/NP mu <- mu*(1 - FF/NP) } } }) } else { # only inequality constraints are present expression({ htrial <- constr1(trial) TAVtrial <- sum( pmax(htrial, 0) ) if (TAVtrial > mu) { if (TAVtrial <= TAVpop[i]) { # trial and target both unfeasible pop[, i] <- trial hpop[, i] <- htrial F[, i] <- Ftrial CR[i] <- CRtrial pF[i] <- pFtrial TAVpop[i] <- TAVtrial } } else if (TAVpop[i] > mu) { # trial is feasible and target is not pop[, i] <- trial fpop[i] <- fn1(trial) hpop[, i] <- htrial F[, i] <- Ftrial CR[i] <- CRtrial pF[i] <- pFtrial TAVpop[i] <- TAVtrial FF <- sum(TAVpop <= mu)/NP mu <- mu*(1 - FF/NP) } else { # two feasible solutions ftrial <- fn1(trial) if (ftrial <= fpop[i]) { pop[, i] <- trial fpop[i] <- ftrial hpop[, i] <- htrial F[, i] <- Ftrial CR[i] <- CRtrial pF[i] <- pFtrial TAVpop[i] <- TAVtrial FF <- sum(TAVpop <= mu)/NP mu <- mu*(1 - FF/NP) } } }) } fn1 <- function(par) fn(par, ...) if (!is.null(constr)) constr1 <- if (meq > 0) { eqI <- 1:meq function(par) { h <- constr(par, ...) h[eqI] <- abs(h[eqI]) - eps h } } else function(par) constr(par, ...) use.jitter <- !is.null(jitter_factor) # Zielinski, Karin, and Laur, Rainer (2008). # Stopping criteria for differential evolution in # constrained single-objective optimization. # In: U. K. Chakraborty (Ed.), Advances in Differential Evolution, # SCI 143, Springer-Verlag, pp 111-138 conv <- expression(( do.call(FUN, list(fpop)) - fpop[x.best.ind] )/fnscale) pop <- matrix(runif(NP*d, lower, upper), nrow = d) if (!is.null(add_to_init_pop)) { pop <- unname(cbind(pop, add_to_init_pop)) NP <- ncol(pop) } stopifnot(NP >= 4) F <- if (use.jitter) (1 + jitter_factor*runif(d, -0.5, 0.5)) %o% runif(NP, Fl, Fu) else matrix(runif(NP, Fl, Fu), nrow = 1) CR <- runif(NP) pF <- runif(NP) fpop <- apply(pop, 2, fn1) if (!is.null(constr)) { hpop <- apply(pop, 2, constr1) if ( any(is.na(hpop)) ) stop("value of meq is invalid") if (is.vector(hpop)) dim(hpop) <- c(1, length(hpop)) TAVpop <- apply( hpop, 2, function(x) sum(pmax(x, 0)) ) mu <- median(TAVpop) } popIndex <- 1:NP x.best.ind <- which.best(fpop) converge <- eval(conv) rule <- if (!is.null(constr)) expression(converge >= tol || any(hpop[, x.best.ind] > 0)) else expression(converge >= tol) convergence <- 0 iteration <- 0 while (eval(rule)) { # generation loop if (iteration >= maxiter) { warning("maximum number of iterations reached without convergence") convergence <- 1 break } iteration <- iteration + 1 for (i in popIndex) { # Start loop through population # Equalize the mean lifetime of all vectors # Price, KV, Storn, RM, and Lampinen, JA (2005) # Differential Evolution: A Practical Approach to # Global Optimization. Springer, p 284 i <- ((iteration + i) %% NP) + 1 # Fi update # Combine jitter with dither # Storn, Rainer (2008). # Differential evolution research - trends and open questions. # In: U. K. Chakraborty (Ed.), Advances in Differential Evolution, # SCI 143, Springer-Verlag, pp 11-12 Ftrial <- if (runif(1) <= tau1) { if (use.jitter) runif(1, Fl, Fu) * (1 + jitter_factor*runif(d, -0.5, 0.5)) else runif(1, Fl, Fu) } else F[, i] # CRi update CRtrial <- if (runif(1) <= tau2) runif(1) else CR[i] # pFi update pFtrial <- if (runif(1) <= tau3) runif(1) else pF[i] # DE/rand/1/either-or/bin X.i <- pop[, i] # Randomly pick 3 vectors all diferent from target vector r <- sample(popIndex[-i], 3) X.base <- pop[, r[1L]] X.r1 <- pop[, r[2L]] X.r2 <- pop[, r[3L]] trial <- handle.bounds(performReproduction(), X.base) eval(child) x.best.ind <- which.best(fpop) } converge <- eval(conv) if (trace && (iteration %% triter == 0)) cat(iteration, ":", "<", converge, ">", "(", fpop[x.best.ind], ")", pop[, x.best.ind], if (!is.null(constr)) paste("{", which(hpop[, x.best.ind] > 0), "}"), fill = TRUE) } res <- list(par = pop[, x.best.ind], value = fpop[x.best.ind], iter = iteration, convergence = convergence) if (details) { res$poppar <- pop res$popcost <- fpop } res } ## Not exported, and only used because CRAN checks must be faster doExtras <- function() { interactive() || nzchar(Sys.getenv("R_DEoptimR_check_extra")) || identical("true", unname(Sys.getenv("R_PKG_CHECKING_doExtras"))) } DEoptimR/MD50000644000175100001440000000052612612456330012270 0ustar hornikusers46aa848cce853ad91085b727f3c21fd0 *DESCRIPTION e957909d8b7160ad012b9ffd6d073b10 *NAMESPACE 3a8bc800367dfee4e21eeaf9c1282e40 *NEWS 4d0ac2e0b78ddfc19505c0cbd8c4604d *R/JDEoptim.R b4a11b18bccefaffdfe2874c61b951a3 *inst/xtraR/opt-test-funs.R 4fde763af9a19d12dd0de817f9670dfe *man/JDEoptim.Rd 5daa4617c3caed9a2354487ec6079026 *tests/JDEoptim-tst.R DEoptimR/DESCRIPTION0000644000175100001440000000130012612456330013455 0ustar hornikusersPackage: DEoptimR Version: 1.0-4 Date: 2015-10-23 Title: Differential Evolution Optimization in Pure R Author: Eduardo L. T. Conceicao and Martin Maechler [ctb] Maintainer: Eduardo L. T. Conceicao Description: An implementation of the jDE variant of the Differential Evolution stochastic algorithm for global optimization of nonlinear programming problems. Imports: stats Enhances: robustbase License: GPL (>= 2) ByteCompile: yes Repository: CRAN Repository/R-Forge/Project: robustbase Repository/R-Forge/Revision: 706 Repository/R-Forge/DateTimeStamp: 2015-10-23 14:29:59 Date/Publication: 2015-10-23 18:14:16 NeedsCompilation: no Packaged: 2015-10-23 14:45:31 UTC; rforge DEoptimR/man/0000755000175100001440000000000012612443654012535 5ustar hornikusersDEoptimR/man/JDEoptim.Rd0000644000175100001440000003566012612442147014505 0ustar hornikusers\name{JDEoptim} \alias{JDEoptim} \title{Nonlinear Constrained Optimization via Differential Evolution} \description{ An implementation of the jDE variant of the Differential Evolution stochastic algorithm for global optimization of nonlinear programming problems. } \usage{ JDEoptim(lower, upper, fn, constr = NULL, meq = 0, eps = 1e-05, NP = 10*d, Fl = 0.1, Fu = 1, tau1 = 0.1, tau2 = 0.1, tau3 = 0.1, jitter_factor = 0.001, tol = 1e-15, maxiter = 200*d, fnscale = 1, FUN = c("median", "max"), add_to_init_pop = NULL, trace = FALSE, triter = 1, details = FALSE, ...) } \arguments{ \item{lower, upper}{numeric vectors of \emph{lower} or \emph{upper} bounds, respectively, for the parameters to be optimized over. Must be finite (\code{\link{is.finite}}) as they bound the hyper rectangle of the initial random population.} \item{fn}{(nonlinear) objective \code{\link{function}} to be \emph{minimized}. It takes as first argument the vector of parameters over which minimization is to take place. It must return the value of the function at that point.} \item{constr}{an optional \code{\link{function}} for specifying the nonlinear constraints under which we want to minimize \code{fn}. They should be given in the form \eqn{h_i(x) = 0, g_i(x) \le 0}. This function takes the vector of parameters as its first argument and returns a real vector with the length of the total number of constraints. It defaults to \code{NULL}, meaning that \emph{bound-constrained} minimization is used.} \item{meq}{an optional positive integer specifying that the first \code{meq} constraints are treated as \emph{equality} constraints, all the remaining as \emph{inequality} constraints. Defaults to \code{0} (inequality constraints only).} \item{eps}{an optional real vector of small positive tolerance values with length \code{meq} used in the transformation of equalities into inequalities of the form \eqn{|h_i(x)| - \epsilon \le 0}. A scalar value is expanded to apply to all equality constraints. Default is \code{1e-5}.} \item{NP}{an optional positive integer giving the number of candidate solutions in the randomly distributed initial population. Defaults to \code{10*length(lower)}.} \item{Fl}{an optional scalar which represents the minimum value that the \emph{scaling factor} \code{F} could take. Default is \code{0.1}, which is almost always satisfactory.} \item{Fu}{an optional scalar which represents the maximum value that the \emph{scaling factor} \code{F} could take. Default is \code{1}, which is almost always satisfactory.} \item{tau1}{an optional scalar which represents the probability that the \emph{scaling factor} \code{F} is updated. Defaults to \code{0.1}, which is almost always satisfactory.} \item{tau2}{an optional constant value which represents the probability that the \emph{crossover probability} \code{CR} is updated. Defaults to \code{0.1}, which is almost always satisfactory.} \item{tau3}{an optional scalar which represents the probability that the \emph{mutation probability} \eqn{p_F}{pF} in the mutation strategy DE/rand/1/either-or is updated. Defaults to \code{0.1}.} \item{jitter_factor}{an optional tuning constant for \emph{jitter}. If \code{NULL} only \emph{dither} is used. Defaults to \code{0.001}.} \item{tol}{an optional positive scalar giving the tolerance for the stopping criterion. Default is \code{1e-15}.} \item{maxiter}{an optional positive integer specifying the maximum number of iterations that may be performed before the algorithm is halted. Defaults to \code{200*length(lower)}.} \item{fnscale}{an optional positive scalar specifying the typical magnitude of \code{fn}. It is used only in the \emph{stopping criterion}. Defaults to \code{1}. See \sQuote{Details}.} \item{FUN}{an optional character string controlling which function should be applied to the \code{fn} values of the candidate solutions in a generation to be compared with the so-far best one when evaluating the \emph{stopping criterion}. If \dQuote{\code{median}} the \code{median} function is used; else, if \dQuote{\code{max}} the \code{max} function is used. It defaults to \dQuote{\code{median}}. See \sQuote{Details}.} \item{add_to_init_pop}{an optional real vector of length \code{length(lower)} or matrix with \code{length(lower)} rows specifying initial values of the parameters to be optimized which are appended to the randomly generated initial population. It defaults to \code{NULL}.} \item{trace}{an optional logical value indicating if a trace of the iteration progress should be printed. Default is \code{FALSE}.} \item{triter}{an optional positive integer that controls the frequency of tracing when \code{trace = TRUE}. Default is \code{triter = 1}, which means that \code{iteration : < value of stopping test > ( value of best solution ) best solution { index of violated constraints }} is printed at every iteration.} \item{details}{an optional logical value. If \code{TRUE} the output will contain the parameters in the final population and their respective \code{fn} values. Defaults to \code{FALSE}.} \item{...}{optional additional arguments passed to \code{fn()} \emph{and} \code{constr()} if that is not \code{NULL}.} } \details{ The setting of the \emph{control parameters} of standard Differential Evolution (DE) is crucial for the algorithm's performance. Unfortunately, when the generally recommended values for these parameters (see, \emph{e.g.}, Storn and Price, 1997) are unsuitable for use, their determination is often difficult and time consuming. The jDE algorithm proposed in Brest \emph{et al.} (2006) employs a simple self-adaptive scheme to perform the automatic setting of control parameters scale factor \code{F} and crossover rate \code{CR}. This implementation differs from the original description, most notably in the use of the \emph{DE/rand/1/either-or} mutation strategy (Price \emph{et al.}, 2005), combination of \emph{jitter with dither} (Storn 2008), and its use of only a \emph{single population} (Babu and Angira 2006) instead of separate current and child populations as in classical DE. Constraint handling is done using the approach described in Zhang and Rangaiah (2012), but with a different reduction updating scheme for the constraint relaxation value (\eqn{\mu}). Instead of doing it once for every generation or iteration, the reduction is triggered for every new feasible trial candidate solution selected for inclusion in the next generation when the \emph{constraints do not contain equalities}. If the constraints \emph{include equalities}, then the reduction is triggered only whenever a feasible solution in the current generation is replaced. Any DE variant is easily extended to deal with \emph{mixed integer nonlinear programming} problems using a small variation of the technique presented by Lampinen and Zelinka (1999). Integer values are obtained by means of the \code{floor()} function \emph{only} for the evaluation of the objective function. This is because DE itself works with continuous variables. Additionally, each upper bound of the integer variables should be added by \code{1}. Notice that the final solution needs to be \emph{converted with \code{floor()}} to obtain its \emph{integer} elements. The algorithm is stopped if \deqn{\frac{\mathrm{FUN}\{[\mathrm{fn}(x_1),\ldots,\mathrm{fn}(x_\mathrm{npop})]\} - \mathrm{fn}(x_\mathrm{best})}{\mathrm{fnscale}} \le \mathrm{tol}}{% ( FUN{ [fn(x[1]),\ldots,fn(x[npop])] } - fn(x[best]) )/fnscale <= tol,} where the \dQuote{best} individual \eqn{x_\mathrm{best}}{x[best]} is the \emph{feasible} solution with the lowest objective function value in the population and the total number of elements in the population, \code{npop}, is \code{NP+NCOL(add_to_init_pop)}. This is a variant of the \emph{Diff} criterion studied by Zielinski and Laur (2008), which was found to yield the best results.} \value{ A list with the following components: \item{par}{The best set of parameters found.} \item{value}{The value of \code{fn} corresponding to \code{par}.} \item{iter}{Number of iterations taken by the algorithm.} \item{convergence}{An integer code. \code{0} indicates successful completion. \code{1} indicates that the iteration limit \code{maxiter} has been reached.} and if \code{details = TRUE}: \item{poppar}{Matrix of dimension \code{(length(lower), npop)}, with columns corresponding to the parameter vectors remaining in the population.} \item{popcost}{The values of \code{fn} associated with \code{poppar}, vector of length \code{npop}.} } \note{ It is possible to perform a warm start, \emph{i.e.}, starting from the previous run and resume optimization, using \code{NP = 0} and the component \code{poppar} for the \code{add_to_init_pop} argument. } \author{ Eduardo L. T. Conceicao \email{mail@eduardoconceicao.org} } \references{ Babu, B. V. and Angira, R. (2006) Modified differential evolution (MDE) for optimization of non-linear chemical processes. \emph{Computers and Chemical Engineering} \bold{30}, 989--1002. Brest, J., Greiner, S., Boskovic, B., Mernik, M. and Zumer, V. (2006) Self-adapting control parameters in differential evolution: a comparative study on numerical benchmark problems. \emph{IEEE Transactions on Evolutionary Computation} \bold{10}, 646--657. Lampinen, J. and Zelinka, I. (1999). Mechanical engineering design optimization by differential evolution; in Corne, D., Dorigo, M. and Glover, F., Eds., \emph{New Ideas in Optimization}. McGraw-Hill, pp. 127--146. Price, K. V., Storn, R. M. and Lampinen, J. A. (2005) \emph{Differential Evolution: A practical approach to global optimization}. Springer, Berlin, pp. 117--118. Storn, R. (2008) Differential evolution research --- trends and open questions; in Chakraborty, U. K., Ed., \emph{Advances in differential evolution}. SCI 143, Springer-Verlag, Berlin, pp. 11--12. Storn, R. and Price, K. (1997) Differential evolution - a simple and efficient heuristic for global optimization over continuous spaces. \emph{Journal of Global Optimization} \bold{11}, 341--359. Zhang, H. and Rangaiah, G. P. (2012) An efficient constraint handling method with integrated differential evolution for numerical and engineering optimization. \emph{Computers and Chemical Engineering} \bold{37}, 74--88. Zielinski, K. and Laur, R. (2008) Stopping criteria for differential evolution in constrained single-objective optimization; in Chakraborty, U. K., Ed., \emph{Advances in differential evolution}. SCI 143, Springer-Verlag, Berlin, pp. 111--138. } \seealso{ Function \code{\link[DEoptim]{DEoptim}()} in the \pkg{DEoptim} package has many more options than \code{JDEoptim()}, but does not allow constraints in the same flexible manner. } \examples{ \donttest{ # NOTE: Examples were excluded from testing # to reduce package check time. # Use a preset seed so test values are reproducible. set.seed(1234) # Bound-constrained optimization # Griewank function # # -600 <= xi <= 600, i = {1, 2, ..., n} # The function has a global minimum located at # x* = (0, 0, ..., 0) with f(x*) = 0. Number of local minima # for arbitrary n is unknown, but in the two dimensional case # there are some 500 local minima. # # Source: # Ali, M. Montaz, Khompatraporn, Charoenchai, and # Zabinsky, Zelda B. (2005). # A numerical evaluation of several stochastic algorithms # on selected continuous global optimization test problems. # Journal of Global Optimization 31, 635-672. griewank <- function(x) { 1 + crossprod(x)/4000 - prod( cos(x/sqrt(seq_along(x))) ) } JDEoptim(rep(-600, 10), rep(600, 10), griewank, tol = 1e-7, trace = TRUE, triter = 50) # Nonlinear constrained optimization # 0 <= x1 <= 34, 0 <= x2 <= 17, 100 <= x3 <= 300 # The global optimum is # (x1, x2, x3; f) = (0, 16.666667, 100; 189.311627). # # Source: # Westerberg, Arthur W., and Shah, Jigar V. (1978). # Assuring a global optimum by the use of an upper bound # on the lower (dual) bound. # Computers and Chemical Engineering 2, 83-92. fcn <- list(obj = function(x) { 35*x[1]^0.6 + 35*x[2]^0.6 }, eq = 2, con = function(x) { x1 <- x[1]; x3 <- x[3] c(600*x1 - 50*x3 - x1*x3 + 5000, 600*x[2] + 50*x3 - 15000) }) JDEoptim(c(0, 0, 100), c(34, 17, 300), fn = fcn$obj, constr = fcn$con, meq = fcn$eq, tol = 1e-7, trace = TRUE, triter = 50) # Designing a pressure vessel # Case A: all variables are treated as continuous # # 1.1 <= x1 <= 12.5*, 0.6 <= x2 <= 12.5*, # 0.0 <= x3 <= 240.0*, 0.0 <= x4 <= 240.0 # Roughly guessed* # The global optimum is (x1, x2, x3, x4; f) = # (1.100000, 0.600000, 56.99482, 51.00125; 7019.031). # # Source: # Lampinen, Jouni, and Zelinka, Ivan (1999). # Mechanical engineering design optimization # by differential evolution. # In: David Corne, Marco Dorigo and Fred Glover (Editors), # New Ideas in Optimization, McGraw-Hill, pp 127-146 pressure_vessel_A <- list(obj = function(x) { x1 <- x[1]; x2 <- x[2]; x3 <- x[3]; x4 <- x[4] 0.6224*x1*x3*x4 + 1.7781*x2*x3^2 + 3.1611*x1^2*x4 + 19.84*x1^2*x3 }, con = function(x) { x1 <- x[1]; x2 <- x[2]; x3 <- x[3]; x4 <- x[4] c(0.0193*x3 - x1, 0.00954*x3 - x2, 750.0*1728.0 - pi*x3^2*x4 - 4/3*pi*x3^3) }) JDEoptim(c( 1.1, 0.6, 0.0, 0.0), c(12.5, 12.5, 240.0, 240.0), fn = pressure_vessel_A$obj, constr = pressure_vessel_A$con, tol = 1e-7, trace = TRUE, triter = 50) # Mixed integer nonlinear programming # Designing a pressure vessel # Case B: solved according to the original problem statements # steel plate available in thicknesses multiple # of 0.0625 inch # # wall thickness of the # shell 1.1 [18*0.0625] <= x1 <= 12.5 [200*0.0625] # heads 0.6 [10*0.0625] <= x2 <= 12.5 [200*0.0625] # 0.0 <= x3 <= 240.0, 0.0 <= x4 <= 240.0 # The global optimum is (x1, x2, x3, x4; f) = # (1.125 [18*0.0625], 0.625 [10*0.0625], # 58.29016, 43.69266; 7197.729). pressure_vessel_B <- list(obj = function(x) { x1 <- floor(x[1])*0.0625 x2 <- floor(x[2])*0.0625 x3 <- x[3]; x4 <- x[4] 0.6224*x1*x3*x4 + 1.7781*x2*x3^2 + 3.1611*x1^2*x4 + 19.84*x1^2*x3 }, con = function(x) { x1 <- floor(x[1])*0.0625 x2 <- floor(x[2])*0.0625 x3 <- x[3]; x4 <- x[4] c(0.0193*x3 - x1, 0.00954*x3 - x2, 750.0*1728.0 - pi*x3^2*x4 - 4/3*pi*x3^3) }) res <- JDEoptim(c( 18, 10, 0.0, 0.0), c(200+1, 200+1, 240.0, 240.0), fn = pressure_vessel_B$obj, constr = pressure_vessel_B$con, tol = 1e-7, trace = TRUE, triter = 50) res # Now convert to integer x1 and x2 c(floor(res$par[1:2]), res$par[3:4]) } }