Learn R Programming

nlmixr2auto (version 1.0.0)

ga.crossover: Crossover operator (one- or two-point) for binary chromosomes

Description

Apply one- or two-point crossover to a selected population of binary chromosomes.

Usage

ga.crossover(sel.population, pcross, npop, nbits)

Value

Numeric matrix containing the children population after crossover.

Arguments

sel.population

Numeric matrix of dimension npop by nbits. Each row is a chromosome and is expected to contain binary values (0/1).

pcross

Single numeric value in \([0, 1]\) giving the probability of applying crossover to each parent pair.

npop

Single positive even integer giving the population size.

nbits

Single positive integer giving the chromosome length.

Author

Zhonghui Huang

Details

Parents are paired sequentially (1 with 2, 3 with 4, etc.). For each pair, crossover is applied with probability pcross; otherwise the parents are copied unchanged. Crossover points are sampled from 0:nbits. If the sampled points do not yield a valid crossover, no crossover is performed for that pair.

Examples

Run this code
sel.population <- matrix(sample(0:1, 100, replace = TRUE), nrow = 10)
ga.crossover(sel.population = sel.population, pcross = 0.7, npop = 10, nbits = 10)

Run the code above in your browser using DataLab