-
Notifications
You must be signed in to change notification settings - Fork 1k
Closed
Labels
Description
I haven't managed to shrink the example down much:
library(irace)
target_evaluator <- function(experiment, num_configurations, all_conf_id,
scenario, target_runner_call) {
withr::local_seed(experiment$seed)
list(cost = runif(1), call = deparse1(experiment))
}
parameters <- readParameters(text = '
algorithm "--" c (as,mmas,eas,ras,acs)
')
target_runner <- function(experiment, scenario) {
withr::local_seed(experiment$seed)
list(time = min(experiment$bound, as.integer(1 + 10*runif(1))))
}
instances <- 1:10
limit <- 100L
wrap_target_runner_counter <- function(target_runner)
{
counter <- 0L
target_runner <- force(target_runner)
fun <- function(experiment, scenario) {
counter <<- counter + 1L
target_runner(experiment, scenario)
}
parent.env(environment(fun)) <- globalenv()
fun
}
seed <- 389493
logFile <- withr::local_tempfile(pattern = "irace", fileext = ".Rdata")
scenario <- checkScenario(list(
targetRunner = target_runner, targetEvaluator = target_evaluator,
maxTime = 2000, boundMax = 10, instances = instances,
logFile = logFile, seed = seed,
quiet = TRUE,
parameters = parameters))
irace(scenario = scenario)
logFile_new <- withr::local_tempfile(pattern = "irace", fileext = ".Rdata")
scenario <- modifyList(scenario, list(
targetRunner = wrap_target_runner_counter(target_runner),
recoveryFile = logFile,
seed = NA,
quiet = FALSE,
logFile = logFile_new))
irace(scenario = scenario)