View source: R/11-grafos-NPdif.R
crossover_sequences | R Documentation |
Crossover sequence operation for use in the genetic cut-search algorithm.
crossover_sequences(s1, s2, cpoint = NA)
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 |
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.
A two-row matrix. Rows are the offsprings produced by the crossover
Cesar Asensio
search_cut_genetic genetic algorithm cut-search, mutate_binary_sequence binary sequence mutation
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.