Skip to content

Commit

Permalink
pass opt.state to selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobbossek committed Jan 24, 2016
1 parent 57abb8f commit 1183d0b
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion R/emoa.as-emoa.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ asemoa = function(

# Implementation of surival selection operator of the AS-EMOA algorithm.
asemoaSelector = makeSelector(
selector = function(fitness, n.select, task, control, storage) {
selector = function(fitness, n.select, task, control, opt.state) {
all.idx = 1:ncol(fitness)

# filter nondominated points
Expand Down
2 changes: 1 addition & 1 deletion R/emoa.nsga2.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ nsga2 = function(

# set up the core of NSGA-II, namely the survival selection
nsga2SurvivalSelector = makeSelector(
selector = function(fitness, n.select, task, control, storage) {
selector = function(fitness, n.select, task, control, opt.state) {
nondom.layers = doNondominatedSorting(fitness)

# storage for indizes of selected individuals
Expand Down
2 changes: 1 addition & 1 deletion R/emoa.sms-emoa.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ smsemoa = function(
max.time = NULL, ...) {

hypervolumeSelector = makeSelector(
selector = function(fitness, n.select, task, control, storage) {
selector = function(fitness, n.select, task, control, opt.state) {
all.idx = 1:ncol(fitness)

# do non-dominated sorting
Expand Down
2 changes: 1 addition & 1 deletion R/makeSelector.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ makeSelector = function(
supported = getAvailableRepresentations(),
supported.objectives,
supported.opt.direction = "minimize") {
assertFunction(selector, args = c("fitness", "n.select", "task", "control", "storage"), ordered = TRUE)
assertFunction(selector, args = c("fitness", "n.select", "task", "control", "opt.state"), ordered = TRUE)
assertSubset(supported.objectives, c("single-objective", "multi-objective"))
assertChoice(supported.opt.direction, choices = c("maximize", "minimize"))
selector = makeOperator(selector, name, description, supported)
Expand Down
2 changes: 1 addition & 1 deletion R/selector.greedy.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#' @family selectors
#' @export
makeGreedySelector = function() {
selector = function(fitness, n.select, task, control, storage) {
selector = function(fitness, n.select, task, control, opt.state) {
fitness = as.numeric(fitness)
idx = order(fitness)[seq(n.select)]
return(idx)
Expand Down
2 changes: 1 addition & 1 deletion R/selector.k-tournament.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ makeTournamentSelector = function(k = 3L) {

force(k)

selector = function(fitness, n.select, task, control, storage) {
selector = function(fitness, n.select, task, control, opt.state) {
fitness = as.numeric(fitness)
pop.idx = seq_along(fitness)
idx = integer(n.select)
Expand Down
2 changes: 1 addition & 1 deletion R/selector.roulettewheel.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ makeRouletteWheelSelector = function(offset = 0.1) {

force(offset)

selector = function(fitness, n.select, task, control, storage) {
selector = function(fitness, n.select, task, control, opt.state) {
fitness = as.numeric(fitness)
# shift negative values
if (any(fitness <= 0L)) {
Expand Down
2 changes: 1 addition & 1 deletion R/selector.simple.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#' @family selectors
#' @export
makeSimpleSelector = function() {
selector = function(fitness, n.select, task, control, storage) {
selector = function(fitness, n.select, task, control, opt.state) {
return(1:ncol(fitness))
}
makeSelector(
Expand Down
4 changes: 2 additions & 2 deletions R/setupECRControl.R
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ selectForMating = function(opt.state, control) {
task = opt.state$task
fitness = population$fitness
fitness2 = transformFitness(fitness, task, control$parent.selector)
idx.mating = control$parent.selector(fitness2, control$n.mating.pool, task, control, NULL)
idx.mating = control$parent.selector(fitness2, control$n.mating.pool, task, control, opt.state)
subsetPopulation(population, idx = idx.mating)
}

Expand All @@ -197,6 +197,6 @@ selectForSurvival = function(opt.state, population, control, n.select = control$
fitness = population$fitness
task = opt.state$task
fitness2 = transformFitness(fitness, task, control$survival.selector)
idx.survival = control$survival.selector(fitness2, n.population, task, control, NULL)
idx.survival = control$survival.selector(fitness2, n.population, task, control, opt.state)
subsetPopulation(population, idx = idx.survival)
}

0 comments on commit 1183d0b

Please sign in to comment.