| cpp_customize | R Documentation |
Update a prepared CCH with the edge weights that should be used for shortest path queries. Customization is much cheaper than preparing the CCH topology, so it is the step to repeat when congestion changes travel times.
cpp_customize(CCH, weights = NULL)
CCH |
An object generated by cpp_contract with |
weights |
Optional edge weights. Defaults to the original graph cost.
Give a single column name ( |
The recommended way to customize a CCH is to import the weights up front with
makegraph using the aux argument and select them by column
name, e.g. cpp_customize(cch, weights = "time"). This is safer than
writing a raw vector at query time: the edge table stored in the CCH doubles
when the graph was built with directed = FALSE, so a raw vector is easy
to get the wrong length or order for, and a mismatch is silently accepted.
A raw numeric vector must then hold one value per edge of
CCH$original$data, in that exact order.
A customized CCH metric object usable by get_distance_pair, get_distance_matrix and get_aon.
RcppParallel::setThreadOptions(numThreads = 1)
# Travel time as the main cost, road length as an auxiliary weight
edges <- data.frame(from_vertex = c(0, 0, 1, 1, 2),
to_vertex = c(1, 2, 2, 3, 3),
cost = c(1, 4, 1, 2, 1))
graph <- makegraph(edges, directed = TRUE,
aux = data.frame(length = c(1, 3, 2, 4, 2)))
cch <- cpp_contract(graph, customizable = TRUE)
# First customization with the travel time (the default)
metric_time <- cpp_customize(cch)
get_distance_pair(metric_time, from = c(0, 1), to = c(3, 3))
# Second customization with the road length, selected by column name
metric_length <- cpp_customize(cch, weights = "length")
get_distance_pair(metric_length, from = c(0, 1), to = c(3, 3))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.