| get_grids | R Documentation |
Map a population of layouts to grid coordinates. Accepts either
an integer matrix of unique cell IDs (n turbines x individuals) or a
legacy binary matrix (n_gridcells x individuals).
get_grids(layouts, grid)
layouts |
Binary matrix (legacy) or integer matrix of grid IDs
( |
grid |
Indexed grid from |
Returns a list of all individuals with X and Y coordinates and the grid cell ID.
Other Helper Functions:
grid_area(),
hexa_area(),
isSpatial(),
permutations(),
read_power_curve(),
splitAt(),
wind_from_series(),
wind_from_uv(),
windata_format()
## Create a random rectangular shapefile
library(sf)
area <- sf::st_as_sf(sf::st_sfc(
sf::st_polygon(list(cbind(
c(0, 0, 2000, 2000, 0),
c(0, 2000, 2000, 0, 0)
))),
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]]
startsel <- init_population(Grid, 10, 20)
wind <- data.frame(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 (n unique cell IDs per individual)
selec6best <- selection(fit, Grid, 2, TRUE, 6, "VAR")
## Set-crossover and swap-mutation keep exactly n turbines.
cross_ids <- set_crossover(selec6best[[1]], Grid[, "ID"], uplimit = 20)
mut_ids <- swap_mutation(cross_ids, Grid[, "ID"], p = 0.2)
## Look up XY coordinates for the next fitness evaluation.
getRectV <- get_grids(mut_ids, Grid)
fit <- fitness(
population = getRectV, reference_height = 100, rotor_height = 100,
surface_roughness = 0.3, area = area, rotor = 20,
wind = wind, terrain = FALSE
)
head(fit)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.