Dear forum,
I'm looking for nice one-liner code of "Floyd-Warshall" algorithm.
MP=: <./ . +~^:_
is good for all pairs shortest paths problem,
but ~O(n^3 log n).
Floyd-Warshall algorithm is O(n^3).
I have this:
-----------------
FWx=: 3 : 0
for_k. i.#y do.
y=.k (]<.{"1 +/ {)y
end.
)
-----------------
and one-liner
------------------------------------
FWt=:(1 1 |. ] <. {."1 +/ {.)^:(#`])
------------------------------------
FWx's performance is better than FWw's and MP's.
So, my question: How can I get a one-liner by using { and k in
for-loop implicitly?
Thanks in advance, and sorry for my English.
--
Eesuk Chung
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm