selectTournoi: Select Individuals Using Tournament Selection

View source: R/terga1.lib.R

selectTournoiR Documentation

Select Individuals Using Tournament Selection

Description

This function performs tournament selection on a population, randomly selecting a specified percentage of individuals for the next generation. The selection can be either a fixed number ('discrete = TRUE') or a percentage of the population size.

Usage

selectTournoi(selection, percentage, discrete = TRUE)

Arguments

selection

A vector representing the indices or identifiers of the individuals from which to select.

percentage

A numeric value indicating either the exact number (if 'discrete = TRUE') or percentage (if 'discrete = FALSE') of individuals to select.

discrete

A logical value indicating whether 'percentage' should be treated as a discrete number of individuals ('TRUE') or a percentage of the total population ('FALSE').

Details

If 'discrete' is set to 'TRUE', the function selects exactly 'percentage' individuals from 'selection'. If 'discrete' is 'FALSE', the function interprets 'percentage' as a proportion of the population size, and the number of individuals selected is calculated accordingly.

This selection method introduces randomness while maintaining a proportionate selection of individuals, which can help maintain diversity within the population in evolutionary algorithms.

Value

A vector of selected individuals from 'selection'.

Examples

## Not run: 
selection <- 1:10
# Select 3 individuals directly
selected_indices <- selectTournoi(selection, percentage = 3, discrete = TRUE)
print(selected_indices)

# Select 30% of individuals from the population
selected_indices <- selectTournoi(selection, percentage = 30, discrete = FALSE)
print(selected_indices)

## End(Not run)


predomics/predomicspkg documentation built on Dec. 11, 2024, 11:06 a.m.