selection: Selecting the fitting the population

View source: R/selection.R

selectionR Documentation

Selecting the fitting the population

Description

The function described below selects the 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

selection(population, fitness, num_parents)

Arguments

population

The list of individuals of the population

fitness

The list of individuals(value) obtained from the function of genetic.algo.optimizeR namely 'evaluate_fitness'.

num_parents

The number of selected individuals that fit the best with the predefined aim.

Value

The output expected should be a list of selected individuals that fit the best with the predefined condition(aim/objective).

Author(s)

Dany Mukesha

Examples

# example of usage
library(genetic.algo.optimizeR)

population <- c(1, 3, 0)

# Evaluate fitness
fitness <- genetic.algo.optimizeR::evaluate_fitness(population)
print("Evaluation:")
print(fitness)

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


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