Dijkstra's algorithm: Difference between revisions
Content added Content deleted
(Dialects of BASIC moved to the BASIC section.) |
m (→{{header|Tailspin}}: Add necessary type info) |
||
Line 7,160: | Line 7,160: | ||
def edges: {| |
def edges: {| |
||
{ from: 'a', to: 'b', cost: 7"1" }, |
{ from: vertex´'a', to: vertex´'b', cost: 7"1" }, |
||
{ from: 'a', to: 'c', cost: 9"1" }, |
{ from: vertex´'a', to: vertex´'c', cost: 9"1" }, |
||
{ from: 'a', to: 'f', cost: 14"1" }, |
{ from: vertex´'a', to: vertex´'f', cost: 14"1" }, |
||
{ from: 'b', to: 'c', cost: 10"1" }, |
{ from: vertex´'b', to: vertex´'c', cost: 10"1" }, |
||
{ from: 'b', to: 'd', cost: 15"1" }, |
{ from: vertex´'b', to: vertex´'d', cost: 15"1" }, |
||
{ from: 'c', to: 'd', cost: 11"1" }, |
{ from: vertex´'c', to: vertex´'d', cost: 11"1" }, |
||
{ from: 'c', to: 'f', cost: 2"1" }, |
{ from: vertex´'c', to: vertex´'f', cost: 2"1" }, |
||
{ from: 'd', to: 'e', cost: 6"1" }, |
{ from: vertex´'d', to: vertex´'e', cost: 6"1" }, |
||
{ from: 'e', to: 'f', cost: 9"1" } |
{ from: vertex´'e', to: vertex´'f', cost: 9"1" } |
||
|}; |
|}; |
||
def fromA: 'a' -> shortestPaths&{graph: $edges}; |
def fromA: vertex´'a' -> shortestPaths&{graph: $edges}; |
||
($fromA matching {|{to:'e'}|})... -> 'Shortest path from $.path(1); to $.to; is distance $.distance; via $.path(2..last); |
($fromA matching {|{to:vertex´'e'}|})... -> 'Shortest path from $.path(1); to $.to; is distance $.distance; via $.path(2..last); |
||
' -> !OUT::write |
' -> !OUT::write |
||
($fromA matching {|{to:'f'}|})... -> 'Shortest path from $.path(1); to $.to; is distance $.distance; via $.path(2..last); |
($fromA matching {|{to:vertex´'f'}|})... -> 'Shortest path from $.path(1); to $.to; is distance $.distance; via $.path(2..last); |
||
' -> !OUT::write |
' -> !OUT::write |
||
</syntaxhighlight> |
</syntaxhighlight> |