Builds a per-edge penalty column from the edge highway class: each edge
gets factor * weight, where factor comes from the named penalties
vector (classes not listed get 0). The column quantifies how much of a
route runs on penalized road types, in the units of weight.
Arguments
- g
An osm_graph.
- penalties
Named numeric vector of
highway = factorpairs; each edge's penalty isfactor * weight. Classes not listed (and edges with nohighway) get0.- weight
Edge column the factors multiply. Default
"length".- name
Name of the new edge column. Default
"penalty".
Value
The osm_graph with the penalty edge column added.
Details
Two ways to use it:
Scalarized routing — add the penalty onto the routing weight (
g$edges$w <- g$edges$length + g$edges$penalty) and route onwwithox_shortest_path(): an ordinary shortest path that trades length against preference at a fixed rate.Constrained / Pareto routing — pass the column as the
resourceofox_route_constrained()orox_route_pareto(), e.g. "fastest route with at most 500 m on residential streets" (penalties = c(residential = 1),budget = 500).
Examples
g <- example_osm_graph()
g <- ox_add_edge_penalties(g, c(residential = 1))
head(g$edges$penalty)
#> [1] 100 100 100 100 100 100