Description Usage Arguments Value See Also Examples
The algorithm takes a graph and an initial node and calculates the shortest path from the initial node to every other node in the graph.
1 | dijkstra(graph, init_node)
|
graph |
A dataframe with with three variables (v1, v2 and w) that contains the edges of the graph (from v1 to v2) with the weight of the edge (w). |
init_node |
A number. |
The shortest path to every other node in graph
from the
init_node
as a vector.
https://en.wikipedia.org/wiki/Dijkstra
1 2 3 4 5 6 | wiki_graph <-
data.frame(v1=c(1,1,1,2,2,2,3,3,3,3,4,4,4,5,5,6,6,6),
v2=c(2,3,6,1,3,4,1,2,4,6,2,3,5,4,6,1,3,5),
w=c(7,9,14,7,10,15,9,10,11,2,15,11,6,6,9,14,2,9))
dijkstra(wiki_graph, 1)
dijkstra(wiki_graph, 3)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.