tag_Couples: Pair Individuals in Population as Mating Couples

View source: R/terga2.lib.R

tag_CouplesR Documentation

Pair Individuals in Population as Mating Couples

Description

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.

Usage

tag_Couples(pop, parents)

Arguments

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.

Details

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.

Value

The modified population list, with 'mate' attributes assigned for paired individuals.

Examples

## 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)


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