From https://observablehq.com/@jwolondon/gridmap-allocation. Returns an LP solution allocating 2D points to a grid.
Arguments
- pts
tibble of geographic points (x,y) to be transformed for allocation to grid.
- grd
tibble defining grid positions.
- compactness
Optional parameter between 0 and 1 where 0 allocates towards edges, 0.5 preserves scaled geographic location and 1 allocates towards centre of grid. Default is 1 (compact cluster).
Examples
library(tibble)
pts <- tribble(
~x, ~y,
2, 4,
1, 5,
2, 1,
3, 3,
3, 4
)
grd <- grid_locations(n_row = 3, n_col = 3, spacers = list())
solve_lp(pts, grd, 0.6)
#> grd pt
#> 1 8 1
#> 2 7 2
#> 3 2 3
#> 4 6 4
#> 5 9 5