Floyd-Warshall algorithm: Difference between revisions

m
J: might as well make nodes connect to themselves...
m (J: might as well make nodes connect to themselves...)
Line 182:
 
<lang J>graph=:".;._2]0 :0
_0 _ _2 _ NB. 1->3 costs _2
4 _0 3 _ NB. 2->1 costs 4; 2->3 costs 3
_ _ _0 2 NB. 3->4 costs 2
_ _1 _ _0 NB. 4->2 costs _1
)
 
floyd graph
30 _1 _2 0
4 30 2 4
5 1 30 2
3 _1 1 30</lang>
 
The graph matrix holds the costs of each directed node. Row index corresponds to starting node. Column index corresponds to ending node. Unconnected nodes have infinite cost.
6,962

edits