Learn R Programming

windfarmGA (version 5.0.0)

selection: Selection Method

Description

Select a certain amount of individuals and recombine them to parental teams. Add the mean fitness value of both parents to the parental team. Depending on the selected selection_mode, the algorithm will either take always 50 percent or a variable percentage of the current population. The variable percentage depends on the evolution of the populations fitness values. With elitism = TRUE the best individuals are always included in the mating pool.

Usage

selection(
  fit,
  grid,
  share,
  elitism = TRUE,
  n_elite = 3,
  selection_mode = "VAR",
  verbose = FALSE
)

Value

Returns a list with 2 elements. Element 1 is an integer matrix of selected layouts (n turbines x selected individuals), each column a set of unique grid cell IDs. Element 2 is the fitness of each selected individual.

Arguments

fit

A list of all fitness-evaluated individuals

grid

Indexed grid from grid_area()

share

Selection divisor: parents are about nrow / share of the population (2 is about 50 %).

elitism

Archive the best layout and breed elite children.

n_elite

Base elite count (grows/shrinks with search phase).

selection_mode

"VAR" (parent share follows fitness) or "FIX" (50 %).

verbose

If TRUE, will print out further information.

See Also

Other Genetic Algorithm Functions: crossover(), fitness(), genetic_algorithm(), init_population(), mutation(), set_crossover(), swap_mutation(), trimton()

Examples

Run this code
# \donttest{
## Exemplary input Polygon with 2km x 2km:
library(sf)
area <- sf::st_as_sf(sf::st_sfc(
  sf::st_polygon(list(cbind(
    c(4498482, 4498482, 4499991, 4499991, 4498482),
    c(2668272, 2669343, 2669343, 2668272, 2668272)
  ))),
  crs = 3035
))

## Calculate a Grid and an indexed data.frame with coordinates and grid cell Ids.
Grid1 <- grid_area(area = area, size = 200, prop = 1)
Grid <- Grid1[[1]]
AmountGrids <- nrow(Grid)

startsel <- init_population(Grid, 10, 20)
wind <- as.data.frame(cbind(ws = 12, wd = 0))
wind <- list(wind, probab = 100)
fit <- fitness(
  population = startsel, reference_height = 100, rotor_height = 100,
  surface_roughness = 0.3, area = area, rotor = 20, wind = wind,
  terrain = FALSE
)
allparks <- do.call("rbind", fit)
## SELECTION
## print the amount of Individuals selected. Check if the amount
## of Turbines is as requested.
selec6best <- selection(fit, Grid, 2, TRUE, 6, "VAR")
selec6best <- selection(fit, Grid, 2, TRUE, 6, "FIX")
selec6best <- selection(fit, Grid, 4, FALSE, 6, "FIX")
# }

Run the code above in your browser using DataLab