tag_ToBeMutated | R Documentation |
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'.
tag_ToBeMutated(pop, mutate_size, protected = NULL)
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 |
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
.
The modified population list with 'toBeMutated' attributes set to 'TRUE' for the selected individuals.
## 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.