crossover_sequences {gor}R Documentation

Crossover of sequences

Description

Crossover sequence operation for use in the genetic cut-search algorithm.

Usage

crossover_sequences(s1, s2, cpoint = NA)

Arguments

s1

Sequence

s2

Sequence of the same lenght as s1

cpoint

Crossover point, an integer between 1 and length(s1)-1. Defaults to NA, in which case it will be randomly chosen

Details

This operation takes two sequences of the same lenght "n" and splits them in two at a crossover point between 1 and "n-1". Then it produces two "offsprings" by interchanging the pieces and gluing them together.

The crossover point can be specified in argument cpoint. By providing NA (the default), cpoint is chosen randomly.

Note that this crossover operation is the "classic" crossover included in the original genetic algorithm, and it is adequate when applied to binary sequences. However, when applied to permutations, the result of this function can have repeated elements; hence, it is not adequate for the TSP.

Value

A two-row matrix. Rows are the offsprings produced by the crossover

Author(s)

Cesar Asensio

See Also

search_cut_genetic genetic algorithm cut-search, mutate_binary_sequence binary sequence mutation

Examples

set.seed(1)
s1 <- sample(0:1, 10, replace = TRUE)
s2 <- sample(0:1, 10, replace = TRUE)
crossover_sequences(s1, s2)

set.seed(1)
s1 <- sample(1:10, 10)
s2 <- sample(1:10, 10)
crossover_sequences(s1, s2, cpoint = 5)


[Package gor version 1.0 Index]