[Jprogramming] Shortest Path
Ricardo Forno
joinville at keko.com.ar
Tue Mar 6 02:42:43 HKT 2007
I don't know the solution in J language, but the iterative algorithm is
known as Dijkstra's algorithm. It runs as follows:
Get the direct distances from the start node (lets call it A) to all other
nodes (replacing it with infinite when no direct connection exists). Select
the node (call it B)with the shortests distance from the start node (lets
call it Dist). Then, select the minimum between the present distance from A
to the remaining nodes and the sum of the Dist and the distance from B to
the remaining nodes, and so on. This is an algorithm of the "greedy" type,
applied to directed graphs.
The traversal path (or the several traversal paths with equal minimum
lengths) can be obtained by tracing back from the end nodes.
Surely you'll get more information in the Web.
Regards.
----- Original Message -----
From: "June Kim" <juneaftn at gmail.com>
To: "Programming forum" <programming at jsoftware.com>
Sent: Monday, March 05, 2007 3:11 PM
Subject: Re: [Jprogramming] Shortest Path
> Thank you for the suggestion.
>
> Following is a simple example:
>
> a
> 0 1 10 5 8
> _ 0 2 _ _
> _ _ 0 _ 4
> _ _ 3 0 _
> _ _ 4 _ 0
> ]spl=.<./ . + ~ ^:_ a
> 0 1 3 5 7
> _ 0 2 _ 6
> _ _ 0 _ 4
> _ _ 3 0 7
> _ _ 4 _ 0
>
>>From node 0 to 4, the length of the shortest path is 7.
>
> (<0 4) { spl
> 7
>
> Now, I want to know the traversal path that makes up 7:
> (<0 4) { sp a NB. the statement doesn't need to be the same with this
> 0 1 2 4
>
> 2007/3/6, Oleg Kobchenko <olegykj at yahoo.com>:
>> --- June Kim <juneaftn at gmail.com> wrote:
>>
>> > Given an adjacent matrix of a graph, what is the simplest way in J to
>> > get the shortest path(not the length[0])~ from i to j? That is, the
>> > sequence of vertices that composes the shortest path in the graph,
>> > which starts with i and ends with j.
>> >
>> > [0] the length matrix can be calculated by <./ .+~^:_
>>
>> With such kind of question, it's good to provide
>> a short example of the adjacency matrix, sample inputs
>> and desired outputs. It will save time and exclude
>> misunderstanding, and increase the likelyhood that more
>> people will be willing to get involved.
>>
>>
>>
>>
>> ____________________________________________________________________________________
>> Get your own web address.
>> Have a HUGE year through Yahoo! Small Business.
>> http://smallbusiness.yahoo.com/domains/?p=BESTDEAL
>> ----------------------------------------------------------------------
>> For information about J forums see http://www.jsoftware.com/forums.htm
>>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
More information about the Programming
mailing list