R Under development (unstable) (2024-11-22 r87365 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > require("DEoptimR") Loading required package: 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() + g11, RND, HEND, and alkylation list of $obj and $con testing functions > (doExtras <- DEoptimR:::doExtras()) [1] FALSE > > set.seed(2345) > # Bound-constrained test problems ---------------------------------------------- > S.time(sf1. <- JDEoptim(c(-100, -100), c(100, 100), sf1, + NP = 50, tol = 1e-7, maxiter = 800)) Time elapsed: 0.45 0.01 0.47 NA NA > S.time(swf. <- JDEoptim(rep(-500, 10), rep(500, 10), swf, + tol = 1e-7)) Time elapsed: 1.04 0.02 1.06 NA NA > # Only equality constraints ---------------------------------------------------- > S.time(g11. <- JDEoptim(-c(1, 1), c(1, 1), + fn = g11$obj, constr = g11$con, meq = g11$eq, eps = 1e-3, + tol = 1e-7)) Time elapsed: 0.28 0 0.28 NA NA > # Only inequality constraints -------------------------------------------------- > S.time(RND. <- JDEoptim(c(1e-5, 1e-5), c(16, 16), RND$obj, RND$con, + NP = 40, tol = 1e-7)) Time elapsed: 0.38 0 0.37 NA NA > if (doExtras) { + 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)) + 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)) + } > > # Expected optimal values ------------------------------------------------------ > 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( unname(c(abs(g11.$par[1]), g11.$par[2], g11.$value)), + c(1/sqrt(2), 0.5, 0.75), + tolerance = 1e-2 ) + ) > if (doExtras) { + stopifnot( + all.equal( bare.p.v(HEND.), + c(579.19, 1360.13, 5109.92, 182.01, 295.60, 7049.25), + tolerance = 1e-3 ), + 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 ) + ) + } > > c.time(proc.time()) Time elapsed: 2.54 0.06 2.59 NA NA > > proc.time() user system elapsed 2.54 0.06 2.59