| routed_cost_curve | R Documentation |
Selects samples of each size in n_grid, routes each one from the depot
(or bases), prices it with the cost model, and fits the expected cost as
G(n) = c0 + a n + b sqrt(n). This is the cost function of Hansen, Hurwitz
and Madow (1953, Vol. I, Chapter 6, Section 12), C0 sqrt(m) + C1 m, with b in
the role of their travel constant C0 and a of the cost per primary unit
C1. They derived C0 from points on a regular grid and called it a rough
approximation; here it is measured on the frame, with its roads (when the
matrix comes from OSRM), its depots and its route limits. The travel of a
tour through n scattered points grows like sqrt(n) (Beardwood, Halton
and Hammersley 1959), and fixed costs per visit and per route add the
linear term.
routed_cost_curve(
frame,
depot,
cost_model,
n_grid,
size = NULL,
strata = NULL,
selection = c("lpm", "systematic", "srs"),
replicates = 1,
matrix = NULL,
method = c("haversine", "euclidean", "osrm"),
max_length = Inf,
max_stops = Inf,
n_rep = 10,
iterations = 100,
seed = 1
)
## S3 method for class 'fieldopt_cost_curve'
predict(object, newdata, type = c("total", "average", "marginal"), ...)
## S3 method for class 'fieldopt_cost_curve'
tidy(x, ...)
## S3 method for class 'fieldopt_cost_curve'
glance(x, ...)
## S3 method for class 'fieldopt_cost_curve'
autoplot(object, ...)
frame |
Data frame of units as in |
depot |
Name of the depot unit in |
cost_model |
A |
n_grid |
Sample sizes to route (at least three distinct values for the three coefficients). |
size |
Optional size column for probability-proportional-to-size selection. |
strata |
Optional stratum column, passed to |
selection |
Selection method of |
replicates |
Replicates of a |
matrix |
Optional |
method |
Distance method of |
max_length, max_stops |
Route limits passed to |
n_rep |
Routed samples per sample size. |
iterations |
GRASP iterations per routing. |
seed |
Seed. |
newdata |
Sample sizes (a numeric vector) for |
type |
|
... |
Unused. |
x, object |
A |
The fit is constrained to be increasing and concave (a >= 0, b >= 0),
so the marginal cost G'(n) = a + b / (2 sqrt(n)) is positive and falls
with n. The marginal cost is the one the classical allocation formulas
need (see two_stage_design()).
An object of class fieldopt_cost_curve: a list with points (a
tibble with n, cost_mean, cost_sd, travel_mean, routes_mean per
routed size), coef (c0, a, b), r_squared, currency and the
settings. predict() gives the total, average or marginal cost at any
n; tidy(), glance() and autoplot() are available.
Hansen, M. H., Hurwitz, W. N. and Madow, W. G. (1953). Sample Survey Methods and Theory, Vol. I, Chapter 6, Sections 11-15, and Vol. II, Chapter 6, Section 11. Wiley. Beardwood, J., Halton, J. H. and Hammersley, J. M. (1959). The shortest path through many points. Proc. Cambridge Phil. Soc., 55, 299-327.
set.seed(2)
cells <- expand.grid(x = 1:15, y = 1:15)
cells$unit <- paste0("c", seq_len(nrow(cells)))
frame <- rbind(data.frame(unit = "depot", x = 8, y = 8), cells)
model <- field_cost_model(per_travel = 3, per_unit = 40)
curve <- routed_cost_curve(frame, "depot", model,
n_grid = c(10, 20, 40, 80), method = "euclidean", n_rep = 2,
iterations = 20
)
curve
predict(curve, c(30, 60), type = "marginal")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.