crossover: Crossover of selected parents from the fitting population

View source: R/crossover.R

crossoverR Documentation

Crossover of selected parents from the fitting population

Description

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.

Usage

crossover(selected_parents, offspring_size)

Arguments

selected_parents

The list of selected individuals from the population.

offspring_size

The number of offspring that the selected population should have.

Value

The output expected should be a list of offspring for the next generation.

Author(s)

Dany Mukesha

Examples

population <- c(1, 3, 0)

# Evaluate fitness
fitness <- evaluate_fitness(population)
print("Evaluation:")
print(fitness)

# Selection
selected_parents <- selection(population, fitness, num_parents = 2)
print("Selection:")
print(selected_parents)

# Crossover
offspring <- crossover(selected_parents, offspring_size = 2)
print("Crossover:")
print(offspring)


genetic.algo.optimizeR documentation built on Oct. 10, 2024, 5:07 p.m.