[Jprogramming] Shortest Path

Raul Miller rauldmiller at gmail.com
Tue Mar 6 03:29:31 HKT 2007


Here's a simpleminded approach:

First, append the path to each of the distances in a

   b=:(,&.>(<@#:i.)@$) a

Second, define a minimum function which works on this form

   min=: (>&{. { ,:)&.>

Third, define an addition function which works on this form

   plus=: (+&{. , ~.@,&}.)&.>

Now you can find the costs with their paths

    min/ .plus~^:_ b

Note, also:
   (<./ .+~^:_ a) -: {.&> min/ .plus~^:_ b
1

   (<0 4){::min/ .plus~^:_ b
7 0 1 2 4

-- 
Raul


More information about the Programming mailing list