This function performs crossover between the selected individuals that fit the best based on the predefined condition(aim/objective).
e.g.: To optimize the function \(f(x) = x^2 - 4x + 4\) to find the value of \(x\) that minimizes the function. \(x\): represents a possible value the an individual from the population can have.
crossover(selected_parents, offspring_size)
Arguments
The list of selected individuals from the population.
The number of offspring that the selected population should have.
The output expected should be a list of offspring for the next generation.
Examplespopulation <- c(1, 3, 0)
# Evaluate fitness
fitness <- evaluate_fitness(population)
print("Evaluation:")
#> [1] "Evaluation:"
print(fitness)
#> [1] 1 1 4
# Selection
selected_parents <- selection(population, fitness, num_parents = 2)
print("Selection:")
#> [1] "Selection:"
print(selected_parents)
#> [1] 1 3
# Crossover
offspring <- crossover(selected_parents, offspring_size = 2)
print("Crossover:")
#> [1] "Crossover:"
print(offspring)
#> [1] 1 1
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4