allocations: Teitz-Bart algorithm applied to Spatial* and...

Description Usage Arguments Value Examples

View source: R/tbmain.R

Description

Return demand Spatial*Dataframe with new columns giving allocation id and distance to supply point

Usage

1
allocations(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 e

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

Copy of swdf1 with extra data columns called allocation and allocdist with indices for each element from the p-median set

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
require(RColorBrewer)
require(GISTools)
data(georgia)
georgia3 <- allocations(georgia2,p=5,force=c(1,120,44))
col.index <- match(georgia3$allocation,unique(georgia3$allocation))
col.alloc <- brewer.pal(5,'Accent')[col.index]
par(mfrow=c(1,2))
plot(georgia3,col=col.alloc)
choropleth(georgia3,georgia3$allocdist)


# Use in conjunction with rgeos
require(rgeos)
require(GISTools)
georgia3 <- allocations(georgia2,p=5,force=c(1,120,44))
georgia4 <- gUnaryUnion(georgia3,georgia3$allocation)
plot(georgia4)
plot(star.diagram(georgia3),col='darkred',lwd=2,add=TRUE)

tbart documentation built on May 2, 2019, 2:49 p.m.