% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/max_coverage.R
\name{max_coverage}
\alias{max_coverage}
\title{Solve the Maximal Covering Location Problem}
\usage{
max_coverage(existing_facility, proposed_facility, user, distance_cutoff,
  n_added, d_existing_user = NULL, d_proposed_user = NULL,
  solver = "glpk")
}
\arguments{
\item{existing_facility}{data.frame containing the facilities that are
already in existing, with columns names lat, and long.}

\item{proposed_facility}{data.frame containing the facilities that are
being proposed, with column names lat, and long.}

\item{user}{data.frame containing the users of the facilities, along with
column names lat, and long.}

\item{distance_cutoff}{numeric indicating the distance cutoff (in metres)
you are interested in. If a number is less than distance_cutoff, it will be
1, if it is greater than it, it will be 0.}

\item{n_added}{the maximum number of facilities to add.}

\item{d_existing_user}{Optional distance matrix between existing facilities
and users. Default distances are direct (geospherical ellipsoidal) distances;
this allows alternative measures such as street-network distances to be
submitted (see Examples).}

\item{d_proposed_user}{Option distance matrix between proposed facilities and
users (see Examples).}

\item{solver}{character "glpk" (default) or "lpSolve". "gurobi" is currently
in development, see \url{https://github.com/njtierney/maxcovr/issues/25}}
}
\value{
dataframe of results
}
\description{
\code{max_coverage} solves the binary optimisation problem known as the
"maximal covering location problem" as described by Church
(http://www.geo .ucsb.edu/~forest/G294download/MAX_COVER_RLC_CSR.pdf).
This package was implemented to make it easier to solve this problem in the
context of the research initially presented by Chan et al
(http://circ.ahajournals.org/content/127/17/1801.short) to identify ideal
locations to place AEDs.
}
\examples{

library(dplyr)

# already existing locations
york_selected <- york \%>\% filter(grade == "I")

# proposed locations
york_unselected <- york \%>\% filter(grade != "I")

mc_result <- max_coverage(existing_facility = york_selected,
                          proposed_facility = york_unselected,
                          user = york_crime,
                          distance_cutoff = 100,
                          n_added = 20)

mc_result

summary(mc_result)

# get the facilities chosen
mc_result$facility_selected

# get the users affected
mc_result$user_affected

# get the summaries
mc_result$summary

# Example of street-network distance calculations
\dontrun{
library(dodgr)
net <- dodgr_streetnet_sf ("york england") \%>\%
    weight_streetnet (wt_profile = "foot")

from <- match_points_to_graph (v, york_selected [, c ("long", "lat")])
to <- match_points_to_graph (v, york_crime [, c ("long", "lat")])
d_existing_user <- dodgr_dists (net, from = from, to = to)

from <- match_points_to_graph (v, york_unselected [, c ("long", "lat")])
d_proposed_user <- dodgr_dists (net, from = from, to = to)

mc_result <- max_coverage(existing_facility = york_selected,
                          proposed_facility = york_unselected,
                          user = york_crime,
                          distance_cutoff = 100,
                          n_added = 20,
                          d_existing_user = d_existing_user,
                          d_proposed_user = d_proposed_user)

}
}
