Dijkstra's algorithm: Difference between revisions

No edit summary
Line 1,516:
This solution is incorrect. Since the path is directed and f is only a sink, f cannot be in the middle of a path.
 
<lang Mathematica>bd = Graph[ {"a" \[DirectedEdge] "b", "a" \[DirectedEdge] "c",
"a"\[UndirectedEdge] "b", "a"\[UndirectedEdgeDirectedEdge] "c", "b" \[UndirectedEdgeDirectedEdge] "cd",
"b"\[UndirectedEdge] "d", "c" \[UndirectedEdgeDirectedEdge] "d", "d" \[UndirectedEdgeDirectedEdge] "e",
"a" \[UndirectedEdgeDirectedEdge] "f", "c" \[UndirectedEdgeDirectedEdge] "f", "e"\[UndirectedEdge] "f"
"e" \[DirectedEdge] "f"},
} ,
EdgeWeight -> {7, 9, 10, 15, 11, 6, 14, 2, 9},VertexLabels->"Name",
VertexLabels -> "Name", VertexLabelStyle -> Directive[Black, 20],ImagePadding->20]
ImagePadding -> 20]
 
FindShortestPath[bd, "a", "e", Method -> "Dijkstra"]
-> {"a", "c", "fd", "e"}</lang>
[[File:Mma_dijkstraMma_dijkstra2.PNG]]
 
=={{header|Maxima}}==
Anonymous user