From fdf2325cd748531ab1ee7c2068c60c381aebf596 Mon Sep 17 00:00:00 2001 From: Jakob Bossek Date: Wed, 18 Feb 2015 13:35:21 +0100 Subject: [PATCH] fix #59 --- R/ecr.R | 2 +- R/ecrControl.R | 6 +- README.md | 2 +- inst/examples/1plus1_GA_example.R | 2 +- inst/examples/soobench_example.R | 2 +- inst/examples/tspmeta_example.R | 2 +- man/ecr.control.Rd | 4 +- tests/testthat/Find Results | 82 ++++++++++++++++++++++++ tests/testthat/test_ecr.R | 2 +- tests/testthat/test_stoppingConditions.R | 4 +- 10 files changed, 95 insertions(+), 13 deletions(-) create mode 100644 tests/testthat/Find Results diff --git a/R/ecr.R b/R/ecr.R index 4e96fcb..a0143cd 100644 --- a/R/ecr.R +++ b/R/ecr.R @@ -85,7 +85,7 @@ ecr = function(objective.fun, control) { best = getBestIndividual(population) opt.path = addBestToOptPath(opt.path, par.set, best, population$fitness, iter) - stop.object = doTerminate(control$stoppingConditions) + stop.object = doTerminate(control$stopping.conditions) if (length(stop.object) > 0L) { break } diff --git a/R/ecrControl.R b/R/ecrControl.R index 760f535..2c7d571 100644 --- a/R/ecrControl.R +++ b/R/ecrControl.R @@ -45,7 +45,7 @@ #' help pages for the recombination operators for the needed values. #' @param monitor [\code{function}]\cr #' Monitoring function. Default is \code{consoleMonitor}. -#' @param stoppingConditions [\code{list}]\cr +#' @param stopping.conditions [\code{list}]\cr #' List of functions of type \code{ecr_stoppingCondition}. #' @return #' S3 object of type \code{ecr_control}. @@ -67,7 +67,7 @@ ecr.control = function( mutator.control = list(), recombinator.control = list(), monitor = makeConsoleMonitor(), - stoppingConditions = list()) { + stopping.conditions = list()) { assertCount(population.size, positive = TRUE, na.ok = FALSE) assertCount(offspring.size, positive = TRUE, na.ok = FALSE) mating.pool.size = convertInteger(mating.pool.size) @@ -151,7 +151,7 @@ ecr.control = function( recombinator.control = recombinator.control, save.population.at = save.population.at, target.name = target.name, - stoppingConditions = stoppingConditions, + stopping.conditions = stopping.conditions, monitor = monitor), class = "ecr_control") } diff --git a/README.md b/README.md index ae95445..e4b9346 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ control = ecr.control( n.params = 1L, mutator = list(gaussMutator), mutator.control = list(mutator.gauss.sd = 0.005), - stoppingConditions = list(makeMaximumIterationsStoppingCondition(max.iter = 50L)) + stopping.conditions = list(makeMaximumIterationsStoppingCondition(max.iter = 50L)) ``` Now lets start the optimization process and print the result object, which contains the optimization trace, the best parameters, the best fitness value and some additional information. diff --git a/inst/examples/1plus1_GA_example.R b/inst/examples/1plus1_GA_example.R index 33facc8..5c5f7aa 100644 --- a/inst/examples/1plus1_GA_example.R +++ b/inst/examples/1plus1_GA_example.R @@ -44,7 +44,7 @@ control = ecr.control( recombinator = crossoverRecombinator, # see the literature on 1+1 GA for this parameter recommendation mutator.control = list(mutator.flip.prob = 1 / n.params), - stoppingConditions = list(makeMaximumIterationsStoppingCondition(max.iter = 500L)) + stopping.conditions = list(makeMaximumIterationsStoppingCondition(max.iter = 500L)) ) print(control) diff --git a/inst/examples/soobench_example.R b/inst/examples/soobench_example.R index 205734f..4522a04 100644 --- a/inst/examples/soobench_example.R +++ b/inst/examples/soobench_example.R @@ -53,7 +53,7 @@ control = ecr.control( n.params = 1L, mutator.control = list(mutator.gauss.sd = 0.005), monitor = myMonitor, - stoppingConditions = list(makeMaximumIterationsStoppingCondition(max.iter = 25L)) + stopping.conditions = list(makeMaximumIterationsStoppingCondition(max.iter = 25L)) ) # do the evolutionary magic diff --git a/inst/examples/tspmeta_example.R b/inst/examples/tspmeta_example.R index cceb509..9306767 100644 --- a/inst/examples/tspmeta_example.R +++ b/inst/examples/tspmeta_example.R @@ -39,7 +39,7 @@ control = ecr.control( generator = makePermutationGenerator(), mutator = list(swapMutator), recombinator = nullRecombinator, - stoppingConditions = list(makeMaximumIterationsStoppingCondition(max.iter = 200L)) + stopping.conditions = list(makeMaximumIterationsStoppingCondition(max.iter = 200L)) ) print(control) diff --git a/man/ecr.control.Rd b/man/ecr.control.Rd index 0b1c2b9..caba902 100644 --- a/man/ecr.control.Rd +++ b/man/ecr.control.Rd @@ -12,7 +12,7 @@ ecr.control(population.size, offspring.size, generator = makeUniformGenerator(), mutator = list(gaussMutator), recombinator = intermediateRecombinator, mutator.control = list(), recombinator.control = list(), monitor = makeConsoleMonitor(), - stoppingConditions = list()) + stopping.conditions = list()) } \arguments{ \item{population.size}{[\code{integer(1)}]\cr @@ -72,7 +72,7 @@ help pages for the recombination operators for the needed values.} \item{monitor}{[\code{function}]\cr Monitoring function. Default is \code{consoleMonitor}.} -\item{stoppingConditions}{[\code{list}]\cr +\item{stopping.conditions}{[\code{list}]\cr List of functions of type \code{ecr_stoppingCondition}.} } \value{ diff --git a/tests/testthat/Find Results b/tests/testthat/Find Results new file mode 100644 index 0000000..ad1f5e2 --- /dev/null +++ b/tests/testthat/Find Results @@ -0,0 +1,82 @@ +Searching 69 files for "stoppingConditions" + +/Users/jboss/repositories/git/ecr/README.md: + 40 mutator = list(gaussMutator), + 41 mutator.control = list(mutator.gauss.sd = 0.005), + 42: stoppingConditions = list(makeMaximumIterationsStoppingCondition(max.iter = 50L)) + 43 ``` + 44 + +/Users/jboss/repositories/git/ecr/test_specific.R: + 26 recombinator = crossoverRecombinator, + 27 generator = makeBinaryGenerator(), + 28: stoppingConditions = list( + 29 makeMaximumTimeStoppingCondition(max.time = 1), + 30 makeMaximumIterationsStoppingCondition(max.iter = 100L) + +/Users/jboss/repositories/git/ecr/inst/examples/1plus1_GA_example.R: + 45 # see the literature on 1+1 GA for this parameter recommendation + 46 mutator.control = list(mutator.flip.prob = 1 / n.params), + 47: stoppingConditions = list(makeMaximumIterationsStoppingCondition(max.iter = 500L)) + 48 ) + 49 print(control) + +/Users/jboss/repositories/git/ecr/inst/examples/soobench_example.R: + 54 mutator.control = list(mutator.gauss.sd = 0.005), + 55 monitor = myMonitor, + 56: stoppingConditions = list(makeMaximumIterationsStoppingCondition(max.iter = 25L)) + 57 ) + 58 + +/Users/jboss/repositories/git/ecr/inst/examples/tspmeta_example.R: + 40 mutator = list(swapMutator), + 41 recombinator = nullRecombinator, + 42: stoppingConditions = list(makeMaximumIterationsStoppingCondition(max.iter = 200L)) + 43 ) + 44 print(control) + +/Users/jboss/repositories/git/ecr/R/ecr.R: + 86 opt.path = addBestToOptPath(opt.path, par.set, best, population$fitness, iter) + 87 + 88: stop.object = doTerminate(control$stoppingConditions) + 89 if (length(stop.object) > 0L) { + 90 break + +/Users/jboss/repositories/git/ecr/R/ecrControl.R: + 46 #' @param monitor [\code{function}]\cr + 47 #' Monitoring function. Default is \code{consoleMonitor}. + 48: #' @param stoppingConditions [\code{list}]\cr + 49 #' List of functions of type \code{ecr_stoppingCondition}. + 50 #' @return + .. + 68 recombinator.control = list(), + 69 monitor = makeConsoleMonitor(), + 70: stoppingConditions = list()) { + 71 assertCount(population.size, positive = TRUE, na.ok = FALSE) + 72 assertCount(offspring.size, positive = TRUE, na.ok = FALSE) + .. + 152 save.population.at = save.population.at, + 153 target.name = target.name, + 154: stoppingConditions = stoppingConditions, + 155 monitor = monitor), + 156 class = "ecr_control") + +/Users/jboss/repositories/git/ecr/tests/testthat/test_ecr.R: + 25 representation = "float", + 26 monitor = makeNullMonitor(), + 27: stoppingConditions = list(makeMaximumIterationsStoppingCondition(max.iter = max.iter)) + 28 ) + 29 } + +/Users/jboss/repositories/git/ecr/tests/testthat/test_stoppingConditions.R: + 23 + 24 # check for max time budget + 25: control$stoppingConditions = list(makeMaximumTimeStoppingCondition(max.time = 2)) + 26 expect_true(grepl("Time limit", ecr(obj.fn, control)$message)) + 27 + 28 # check for max iterations + 29: control$stoppingConditions = list(makeMaximumIterationsStoppingCondition(max.iter = 10L)) + 30 expect_true(grepl("iterations", ecr(obj.fn, control)$message)) + 31 }) + +13 matches across 9 files diff --git a/tests/testthat/test_ecr.R b/tests/testthat/test_ecr.R index b2c8274..a9079be 100644 --- a/tests/testthat/test_ecr.R +++ b/tests/testthat/test_ecr.R @@ -24,7 +24,7 @@ test_that("ecr works with simple soo function", { n.params = 2L, representation = "float", monitor = makeNullMonitor(), - stoppingConditions = list(makeMaximumIterationsStoppingCondition(max.iter = max.iter)) + stopping.conditions = list(makeMaximumIterationsStoppingCondition(max.iter = max.iter)) ) } diff --git a/tests/testthat/test_stoppingConditions.R b/tests/testthat/test_stoppingConditions.R index 223e228..db28093 100644 --- a/tests/testthat/test_stoppingConditions.R +++ b/tests/testthat/test_stoppingConditions.R @@ -22,10 +22,10 @@ test_that("stopping conditions work", { ) # check for max time budget - control$stoppingConditions = list(makeMaximumTimeStoppingCondition(max.time = 2)) + control$stopping.conditions = list(makeMaximumTimeStoppingCondition(max.time = 2)) expect_true(grepl("Time limit", ecr(obj.fn, control)$message)) # check for max iterations - control$stoppingConditions = list(makeMaximumIterationsStoppingCondition(max.iter = 10L)) + control$stopping.conditions = list(makeMaximumIterationsStoppingCondition(max.iter = 10L)) expect_true(grepl("iterations", ecr(obj.fn, control)$message)) })