Shortest path (igraph)
shortest_path_igraph.Rd
The function shortest_path_igraph
can be used to calculate the shortest path (either in minutes or meters) between nodes in the Norwegian road network. The function can also return the node link, i.e. path, that the shortest path consists of.
Usage
shortest_path_igraph(
from_node_ID,
to_node_ID,
graph_object = graph,
unit = "minutes",
path = FALSE
)
Arguments
- from_node_ID
Numeric value with the from node ID (if multiple node ID’s are to be used, see the function
shortest_path_cppRouting()
).- to_node_ID
Numeric value with the to node ID (if multiple node ID’s are to be used, see the function
shortest_path_cppRouting()
).- graph_object
The road network structured as a tidy graph (
tbl_graph
object). This can be created with the functionvegnett_to_R()
.- unit
Character vector with
minutes
to calculate the shortest path in minutes ormeters
for the shortest path in meters.- path
Logical. If
TRUE
the node link with the shortest path is returned.
Value
Vector with the shortest path in minutes or meters. If path = TRUE
the node link that the shortest path consists of is returned.
Details
Before the function can be used, the road network must be converted to a tbl_graph
object. This can be done with the function vegnett_to_R()
). There objects graph
and edges
needs to be loaded.
Examples
shortest_path_igraph(from_node_ID = 25,
to_node_ID = 33,
unit = "minutes",
graph_object = graph_sampledata)
#> # A tibble: 1 x 1
#> length
#> <dbl>
#> 1 0.607
shortest_path_igraph(from_node_ID = 25,
to_node_ID = 33,
unit = "meters",
graph_object = graph_sampledata)
#> # A tibble: 1 x 1
#> length
#> <dbl>
#> 1 347.
shortest_path_igraph(from_node_ID = 25,
to_node_ID = 33,
unit = "minutes",
path = TRUE,
graph_object = graph_sampledata)
#> $vpath
#> $vpath[[1]]
#> + 9/1159 vertices, from d4a5573:
#> [1] 25 26 27 28 29 30 31 32 33
#>
#>
#> $epath
#> $epath[[1]]
#> + 8/1741 edges from d4a5573:
#> [1] 25->26 26->27 27->28 28->29 29->30 30->31 31->32 32->33
#>
#>
#> $predecessors
#> NULL
#>
#> $inbound_edges
#> NULL
#>