RosettaCodeData/Task/Dijkstras-algorithm/Mathematica/dijkstras-algorithm.math
2023-07-01 13:44:08 -04:00

11 lines
467 B
Text

bd = Graph[{"a" \[DirectedEdge] "b", "a" \[DirectedEdge] "c",
"b" \[DirectedEdge] "c", "b" \[DirectedEdge] "d",
"c" \[DirectedEdge] "d", "d" \[DirectedEdge] "e",
"a" \[DirectedEdge] "f", "c" \[DirectedEdge] "f",
"e" \[DirectedEdge] "f"},
EdgeWeight -> {7, 9, 10, 15, 11, 6, 14, 2, 9},
VertexLabels -> "Name", VertexLabelStyle -> Directive[Black, 20],
ImagePadding -> 20]
FindShortestPath[bd, "a", "e", Method -> "Dijkstra"]
-> {"a", "c", "d", "e"}