Learn R Programming

tbart (version 1.0)

allocate: Teitz-Bart algorithm applied to Spatial* and Spatial*DataFrame objects

Description

This function returns the allocations for each demand point - in terms of the index number of the record in swdf2 assigned as the supply point. This version is useful as part of code inside other functions

Usage

allocate(swdf1, swdf2, force, p, metric, verbose = FALSE)

Arguments

swdf1
- first Spatial* or Spatial*DataFrame objects
swdf2
- second Spatial* or Spatial*DataFrame objects (if omitted, defaults to the same value as swdf1)
force
- list of supply points or logical vector with length the same as the number of supply points that are forced to be used - eg existing outlets
p
- either a guess at the initial $p$-median set of a single integer indicating the size of the set (which is then chosen randomly)
metric
- the distance matrix (defaults to Euclidean computed via euc.dists(swdf1,swdf2) if not supplied)
verbose
- if TRUE print out each swap in the algorithm (default is FALSE)

Value

List of nearest neigbour indices for each element from the $p$-median set

Examples

Run this code
data(meuse)
coordinates(meuse) <- ~x+y
allocate(meuse,p=5)



require(RColorBrewer)
require(GISTools)
data(georgia)
allocations.list <- allocate(georgia2,p=5)
zones <- gUnaryUnion(georgia2,allocations.list)
plot(zones,col=brewer.pal(5,"Accent"))
plot(georgia2,border=rgb(0,0,0,0.1),add=TRUE)
points(coordinates(georgia2)[allocations.list,],pch=16,cex=2,col=rgb(1,0.5,0.5,0.1))

Run the code above in your browser using DataLab