tournamentSelection: Tournament Selection

Description Usage Arguments Details Value Examples

Description

Uses the tournament method to generate a list of parents to be used in crossover. Tournament size used is k=2. It is called within Breed function.

Usage

1
tournamentSelection(population=population, scores=scores, nPop=nPop)

Arguments

population

current chromosome population as a matrix with each row representing a chromosome and each value indicating the presence (1) or absence (0) of a specific trait

scores

scores for the current chromosomes in the population a lower score is better

nPop

current number of chromosomes in the population If you do not remove the worst chromosome before using You could set this to nPop1 to get results

Details

The function generates a list of parents using the tournament method with size 2. The current population is broken into groups of 2 (if it is odd one member is randomly selected to sit out the tournament). For each group of 2 chromosomes the one with the lowest score is chose as a parent. This is repeated until the desired number of parents ((nPop-1)*2) has been generated.

Value

A vector indicating the row positions in the population matrix of the parents that will be bred using Crossover.

Examples

1
2
3
4
5
6
7
PopChrom <- matrix(data = sample(x = c(0,1), size = 6*3, replace = TRUE),
                   nrow = 6, ncol = 3)
PopChrom <- safetyFunc(population = PopChrom)

#assumes 1 chrom was left out of of sample and reserved for next gen.

parents <- tournamentSelection(population=PopChrom, scores=c(4,50,3,100,4), nPop=6)

GilChrist19/GA documentation built on May 13, 2019, 5:32 p.m.