resetTags: Reset Tags for All Individuals in a Population

View source: R/terga2.lib.R

resetTagsR Documentation

Reset Tags for All Individuals in a Population

Description

This function resets specific tags for all individuals in a population, including 'selected', 'toBeMutated', and 'mate' attributes. It can be used to clear or initialize these tags before further processing.

Usage

resetTags(pop, selected = FALSE, toBeMutated = FALSE, mate = -1)

Arguments

pop

A list representing the population, where each individual is expected to have attributes 'selected', 'toBeMutated', and 'mate'.

selected

A logical value to set for the 'selected' attribute of each individual. Defaults to FALSE.

toBeMutated

A logical value to set for the 'toBeMutated' attribute of each individual. Defaults to FALSE.

mate

A value to set for the 'mate' attribute of each individual. Defaults to -1.

Details

The function iterates through each individual in the population and sets their 'selected', 'toBeMutated', and 'mate' attributes to the specified values. This function is useful for resetting the population's status before selection and mutation operations.

If 'pop' is NULL, the function issues a warning (if 'clf$params$warnings' is enabled) and returns NULL. If 'pop' is not a list, an error is raised.

Value

The modified population list with updated 'selected', 'toBeMutated', and 'mate' attributes for each individual.

Examples

## Not run: 
pop <- list(
  list(fit_ = 0.9, selected = TRUE, toBeMutated = TRUE, mate = 2),
  list(fit_ = 0.8, selected = TRUE, toBeMutated = FALSE, mate = 3),
  list(fit_ = 0.7, selected = FALSE, toBeMutated = TRUE, mate = -1)
)
pop <- resetTags(pop, selected = FALSE, toBeMutated = FALSE, mate = -1)
# Check updated population
str(pop)

## End(Not run)


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