tag_Couples | R Documentation |
This function pairs individuals in a population to form mating couples, assigning each pair a 'mate' attribute. Each individual can be matched with one other individual from the specified parents list.
tag_Couples(pop, parents)
pop |
A list representing the population, where each individual has a 'mate' attribute to indicate their paired individual. |
parents |
A vector of indices or identifiers for individuals in the population that are eligible to be paired. |
The function randomly pairs individuals from the 'parents' list. For each couple, it assigns the 'mate' attribute of one individual to the other’s index, and vice versa. If an individual’s 'mate' attribute is positive, it indicates the index of their partner. If it’s negative, it indicates their partner’s index with a negative sign.
If the population is empty, the function issues a warning and returns
NULL
.
The modified population list, with 'mate' attributes assigned for paired individuals.
## Not run:
pop <- list(
list(fit_ = 0.9, selected = FALSE, mate = NULL),
list(fit_ = 0.8, selected = FALSE, mate = NULL),
list(fit_ = 0.7, selected = FALSE, mate = NULL),
list(fit_ = 0.6, selected = FALSE, mate = NULL)
)
parents <- c(1, 2, 3, 4)
pop <- tag_Couples(pop, parents)
# Check mates for each individual
sapply(pop, function(ind) ind$mate)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.