Learn R Programming

windfarmGA (version 2.3.0)

init_population: Create a random initial Population

Description

Create nStart random sub-selections from the indexed grid and assign binary variable 1 to selected grids. This function initiates the genetic algorithm with a first random population and will only be needed in the first iteration.

Usage

init_population(Grid, n, nStart = 100)

Arguments

Grid

The data.frame output of grid_area" function, with X and Y coordinates and Grid cell IDs.

n

A numeric value indicating the amount of required turbines.

nStart

A numeric indicating the amount of randomly generated initial individuals. Default is 100.

Value

Returns a list of nStart initial individuals, each consisting of n turbines. Resulting list has the x and y coordinates, the grid cell ID and a binary variable of 1, indicating a turbine in the grid cell.

See Also

Other Genetic Algorithm Functions: crossover(), fitness(), genetic_algorithm(), mutation(), selection(), trimton(), windfarmGA()

Examples

Run this code
# NOT RUN {
library(sp)
## Exemplary input Polygon with 2km x 2km:
Polygon1 <- Polygon(rbind(c(0, 0), c(0, 2000),
c(2000, 2000), c(2000, 0)))
Polygon1 <- Polygons(list(Polygon1),1);
Polygon1 <- SpatialPolygons(list(Polygon1))
Projection <- "+init=epsg:3035"
proj4string(Polygon1) <- CRS(Projection)

Grid <- grid_area(Polygon1,200,1,"TRUE")

## Create 5 individuals with 10 wind turbines each.
firstPop <- init_population(Grid = Grid[[1]], n = 10, nStart = 5)

# }

Run the code above in your browser using DataLab