getSecondParents: Get Second Parent

Description Usage Arguments Details Value Examples

Description

Generates a list of parents to breed with the first parents selected. Makes sure that a parent is not breeding with itself. Called within the Breed() function

Usage

1
getSecondParents(firstParents, method, nPop, relScore)

Arguments

firstParents

List of the first parents in each mating.

method

One of two scoring methods to determine the second parent.

  • oneScore: Second parent is chosen at random.

  • twoScore: Second parent is chosen based on relative fitness.

nPop

Number of chromosomes in the population. Equal to the length of firstParents.

relScore

Relative fitness score as calculated by Fitness(). Lower is better.

Details

This function ensures that the second parent in a crossover is distinct from the first. It uses one of two methods to determine the second parent. This will be slower than randomly picking the second parent but could provide better performance. Function assumes that the worse member of the previous generation has already been removed.

Value

A vector indicating the row position in the population matrix of the parents that will breed with the firstParents vector.

Examples

1
2
3
4
5
set.seed(42)
test_parent1 <-  matrix(data = sample(c(0,1), size = 16, replace = TRUE), nrow = 4, ncol = 4)
test_nPop <- length(test_parent1)
test_relScore <- rnorm(x = 4, mean = 10, sd = 1)
getSecondParents(firstParents=test_parent1, method="oneScore", nPop=4, relScore=test_relScore)

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