This vignette provides a guide to using maxcovr to solve the maximum covering location problem, assuming that you can relocate facilities.

library(dplyr)
library(maxcovr)

The "fixed location" method provided in max_coverage is limited in that it assumes that you cannot move existing facilities. max_coverage_relocation assumes that you can move already existing facilities, but that there is some cost of removal, and a cost of installation.

To illustrate the benefits of relocation, we are first going to consider an example where the existing facilities provide no coverage to users. We identify facility locations that are really far away.

york_selected_worst_id <- york_crime %>% 
    nearest(york) %>%
    arrange(-distance) %>%
    slice(1:20) %>%
    select(desig_id) %>%
    distinct(desig_id)


# york_worst <- york_selected_worst_id %>% 
york_existing_worst <- york_selected_worst_id %>% 
    left_join(york,
              by = "desig_id")

Then we identify some really ideal locations.

york_not_selected_worst <- york %>%
    anti_join(york_existing_worst,
              by = "desig_id")

york_proposed_best <- 
 york_crime %>%
    nearest(york_not_selected_worst) %>%
    arrange(distance) %>%
    slice(1:100) %>%
    select(desig_id) %>%
    distinct(desig_id) %>%
    left_join(york,
              by = "desig_id")
york_proposed_best
york_existing_worst

Let's look at the coverage of these places,

coverage(york_existing_worst,
         york_crime,
         distance_cutoff = 100)

So these are worst placements - we should choose some better facilities. However, if we consider the possibility that we could move these existing facilities to better locations, then we might be able to save a lot of money! We can do this with max_coverage_relocation.

Here we use max_coverage_relocation, which is similar in form to max_coverage.

Here, we specify:

instead of specifying n_added, as in max_coverage, we specify three cost_ parameters:

Here we state that the installation cost is 10, the remocal cost is 1, and the total available cost is 10. There is only enough total resources to install one facility.

system.time(
mc_relocate_worst <-  max_coverage_relocation(
    existing_facility = york_existing_worst,
    proposed_facility = york_proposed_best,
    user = york_crime,
    distance_cutoff = 100,
    cost_install = 500,
    cost_removal = 100,
    cost_total = 1000)
)

mc_relocate_worst
summary(mc_relocate_worst)

dim(york_existing_worst)
dim(york_proposed_best)

mc_relocate_worst$existing_facility[[1]]
mc_relocate_worst$proposed_facility[[1]]
mc_relocate_worst$facilities_selected[[1]]

You can then start to toy with the different pricings if you like.

system.time(
mc_relocate_worst_eq <-  max_coverage_relocation(
    existing_facility = york_existing_worst,
    proposed_facility = york_proposed_best,
    user = york_crime,
    distance_cutoff = 100,
    cost_install = 10,
    cost_removal = 100,
    cost_total = 10)
)

mc_relocate_worst_eq

summary(mc_relocate_worst_eq)


njtierney/copertura documentation built on Nov. 13, 2019, 6:37 p.m.