Gets the last generation that was evaluated as counted by the "dob" column in the OptimInstance's Archive.

This accepts OptimInstances that were not evaluated with miesmuschel and are therefore missing the "dob" column, returning a value of 0. However, if the "dob" column is invalid (the inferred generation is not integer numeric or not non-negative), an error is thrown.

mies_generation(inst)

Arguments

inst

(OptimInstance)
Optimization instance to evaluate.

Value

a scalar integer value indicating the last generation that was evaluated in inst. It is 0 when inst is empty, and also typically 0 if all evaluations in inst so far were performed outside of miesmuschel. Every call of mies_init_population that actually performs evaluations, as well as each call to mies_evaluate_offspring with non-empty offspring, increases the generation by 1.

Examples

library("bbotk")
lgr::threshold("warn")

# Define the objective to optimize
objective <- ObjectiveRFun$new(
  fun = function(xs) {
    z <- 10 - exp(-xs$x^2 - xs$y^2) + 2 * exp(-(2 - xs$x)^2 - (2 - xs$y)^2)
    list(Obj = z)
  },
  domain = ps(x = p_dbl(-2, 4), y = p_dbl(-2, 4)),
  codomain = ps(Obj = p_dbl(tags = "minimize"))
)

oi <- OptimInstanceSingleCrit$new(objective,
  terminator = trm("evals", n_evals = 6)
)

op <- opt("mies",
  lambda = 2, mu = 2,
  mutator = mut("gauss", sdev = 0.1),
  recombinator = rec("xounif"),
  parent_selector = sel("best")
)
set.seed(1)

mies_generation(oi)
#> [1] 0

op$optimize(oi)
#>            x       y  x_domain      Obj
#>        <num>   <num>    <list>    <num>
#> 1: -0.406948 1.43712 <list[2]> 9.897011
mies_generation(oi)
#> [1] 3

oi$terminator = trm("evals", n_evals = 10)

op$optimize(oi)
#>           x         y  x_domain      Obj
#>       <num>     <num>    <list>    <num>
#> 1: -1.10684 0.9706259 <list[2]> 9.885548
mies_generation(oi)
#> [1] 5