Skip to content

Commit

Permalink
return multiple offsprings
Browse files Browse the repository at this point in the history
  • Loading branch information
surmann committed Jun 29, 2015
1 parent 57888e1 commit 31e931c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
21 changes: 17 additions & 4 deletions R/generateOffspring.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ generateOffspring = function(matingPool, objective.fun, control, opt.path) {

offspring = vector("list", n.offspring)

for (i in seq(n.offspring)) {
i = 1
while (i < n.offspring) {
#catf("Parent %i", i)
parents = getParents(matingPool)
#print(parents)
Expand All @@ -28,9 +29,21 @@ generateOffspring = function(matingPool, objective.fun, control, opt.path) {
#catf("Child %i", i)
#print(child)
mutator.control = mutationStrategyAdaptor(mutator.control, opt.path)
# pass just the individual and get a single individual
child = mutator(child, mutator.control, control)
offspring[[i]] = child
# mutate the child or children
if (isTRUE(attr(child, "children"))) {
max.children = min(length(child), n.offspring - i + 1)
for (ii in seq(max.children)) {
# pass just the individual and get a single individual
child[[ii]] = mutator(child[[ii]], mutator.control, control)
offspring[[i]] = child[[ii]]
i = i + 1
}
} else {
# pass just the individual and get a single individual
child = mutator(child, mutator.control, control)
offspring[[i]] = child
i = i + 1
}
}
#print(offspring)
offspring.fitness = computeFitness(makePopulation(offspring), objective.fun)
Expand Down
6 changes: 4 additions & 2 deletions R/recombinator.crossover.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ makeCrossoverRecombinator = function(recombinator.crossover.prob = 1) {
child1[(idx + 1L):n] = parent2[(idx + 1L):n]
child2[1:idx] = parent1[1:idx]
}
#FIXME: here we just return one offspring for now
return(child1)
# return two offsprings
children = list(child1, child2)
attr(children, "children") = TRUE
return(children)
}

makeRecombinator(
Expand Down
6 changes: 4 additions & 2 deletions R/recombinator.pmx.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ makePMXRecombinator = function() {
c2[i] = ins
}
}
#FIXME: until now we only allow to return one individual, but we created two
return(c1)
# return two offsprings
children = list(c1, c2)
attr(children, "children") = TRUE
return(children)
}

makeRecombinator(
Expand Down

0 comments on commit 31e931c

Please sign in to comment.