tag_ToBeMutated: Tag Individuals for Mutation in a Population

View source: R/terga2.lib.R

tag_ToBeMutatedR Documentation

Tag Individuals for Mutation in a Population

Description

This function tags a specified number of individuals in the population for mutation, while optionally protecting certain individuals from being selected. The tagged individuals are marked with a 'toBeMutated' attribute set to 'TRUE'.

Usage

tag_ToBeMutated(pop, mutate_size, protected = NULL)

Arguments

pop

A list representing the population, where each individual has a 'toBeMutated' attribute.

mutate_size

An integer specifying the number of individuals to mark for mutation.

protected

An optional vector of indices representing individuals that should not be tagged for mutation. Defaults to NULL.

Details

The function selects 'mutate_size' individuals from the population, excluding any indices specified in 'protected'. If 'mutate_size' exceeds the number of non-protected individuals, the function issues a warning and reduces the mutation count to the maximum available.

If the number of protected individuals is too large to allow sufficient mutations, the function removes some individuals from the 'protected' list as necessary to meet the mutation quota.

If the population is empty, the function issues a warning (if 'clf$params$warnings' is 'TRUE') and returns NULL.

Value

The modified population list with 'toBeMutated' attributes set to 'TRUE' for the selected individuals.

Examples

## Not run: 
pop <- list(
  list(fit_ = 0.9, toBeMutated = FALSE),
  list(fit_ = 0.8, toBeMutated = FALSE),
  list(fit_ = 0.7, toBeMutated = FALSE),
  list(fit_ = 0.6, toBeMutated = FALSE)
)
protected <- c(1, 2)
pop <- tag_ToBeMutated(pop, mutate_size = 2, protected = protected)
# Check which individuals are tagged for mutation
sapply(pop, function(ind) ind$toBeMutated)

## End(Not run)


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