Description Usage Arguments Details Value Examples
Use the Bellman-Ford algorithm to calculate the shortest path from a source vertex to a target vertex in a directed, weighted graph
1 | bellmanFord(graph, from, to)
|
graph |
The |
from |
Source node |
to |
Target node |
The Bellman-Ford algorithm is a single source algorithm which can in contrast to the Dijkstra's and A*-Search algorithms deal with negative edge weights (Note in order to find the right shortest path it is required that no negative-weight cycle exist in the graph). The algorithm automatically detects cycles with a negative weight and shows a corresponding error message.
Like Dijkstra, the algorithm is based on the principle of relaxation. While Dijkstra selects the vertex with the minimum distance, the Bellman-Ford algorithm simply relaxes all the edges (#V-1 times). Thus, Bellman-Ford has a runtime of #V * #E.
An spresults
object.
1 2 3 4 5 6 7 8 9 | g <- randomGraph(6, euclidean=FALSE)
bf <- bellmanFord(g, "A", "F")
plot(bf)
for(step in bf){
print(step$min_dists)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.