Jump to content



Welcome to AstaHost - Dear Guest , Please Register here to get Your own website. - Ask a Question / Express Opinion / Reply w/o Sign-Up!

Toggle shoutbox Shoutbox Open the Shoutbox in a popup

@  agyat : (24 May 2013 - 05:15 PM) O Dear, Where Are You? Without Your Words This Sb Is ..
@  agyat : (23 May 2013 - 01:23 AM) Wow! Mr. Sb Back Home.
@  OpaQue : (23 May 2013 - 12:44 AM) Ting
@  OpaQue : (24 April 2013 - 02:44 PM) I guess, Time to run Mycent script.
@  OpaQue : (24 April 2013 - 02:43 PM) wow.. not much spam. except habatt posting lot of links.. :P
@  yordan : (23 April 2013 - 01:04 PM) You're welcome, agyat. Nice to have been helpful. Second lesson: try full words, "you" instead of "EW".
@  agyat : (23 April 2013 - 05:03 AM) @YORDAN: tHANK EW FOR YOUR FIRST LESSON.   :D
@  yordan : (22 April 2013 - 09:43 PM) @agyat : "why don't you help me", or "please help me", or "please teach us"
@  yordan : (22 April 2013 - 09:42 PM) welcome back, velma
@  velma : (22 April 2013 - 07:51 AM) **yawns** Good to be back, wonder what is going on here :)
@  agyat : (22 April 2013 - 03:50 AM) Oh! so, why don't help me learn english..
@  yordan : (21 April 2013 - 08:38 PM) The goal mentioned by shiu : "learning english, learning computer"
@  agyat : (21 April 2013 - 06:31 PM) WHAT GOAL?
@  yordan : (20 April 2013 - 10:39 AM) yes, that's our goal. simultaneouly learning English and teaching/learning computer using.
@  shiyu : (20 April 2013 - 07:30 AM) learning english,learning computer
@  yordan : (19 April 2013 - 01:11 PM) Oh, I see, it's just a trick in order to force people looking at your texte. Somehow smart, maybe.
@  agyat : (19 April 2013 - 02:54 AM) And of course I know it is not SEO friendly.
@  agyat : (19 April 2013 - 02:52 AM) There may be two possible answers for that ....


1) Shout was posted using mobile keypad.

2) To force people read content carefully and/or with more concentration.
@  agyat : (19 April 2013 - 02:49 AM) There may be two possible answers for that ....
@  yordan : (18 April 2013 - 09:35 PM) however, why this mixing of capital letters in the middle of your text?

Photo
- - - - -

Floyd - Warshall - Shortest Path Graphs


No replies to this topic

#1 Andres Martinez Andrade

Andres Martinez Andrade

    Newbie [ Level 2 ]

  • Members
  • 19 posts
  • Gender:Male
  • Location:Mexico
  • Interests:Artificial Intelligence, Programming Contests like ACM, Programming & Algorithms, Favorite languages Java, C++, PHP, Perl, Prolog, Scheme. Web Apps, Software Development, and more Geek's stuff...jaja

Posted 16 December 2007 - 07:44 AM

Floyd - Warshall

The Floyd - Warshall algorithm is used to find the shortest path between all nodes in a directed graph with weights in its connections.

A single run of the algorithm will find the shortest path between any pair of nodes in the graph with a complexity time of O(V^3), where V is the number of nodes of the graph. This complexity time is due to the 3 cycles it uses in its implementation.

The algorithm works by estimating the cost of the shortest path between nodes and it corrects its answer in each iteration.

Let's suppose that we have a graph with V nodes, all numbered from 1 to N.
The shortest path between node 'i' and node 'j' could be one of the followings:
- The path between "i" and "j" or
- The path between "i" and "k" plus the shortest path between "k" and "j", where "k: is the intermediate node smaller than N

In other words these two statements could be written as pseudo code:
shortestPath_i_to_j = min(shortestPath(i, j), shortestPath(j, k) + shortestPath(k, i));

And the complete pseudo code is:

procedure FloydWarshall ()
for k = 1 to n
for each (i,j) in (1..n)
path[i][j] = min (path[i][j], path[i][k]+path[k][j] );
end
end
end procedure



Assume that N is the number of nodes in the graph and that each element of the path[i][j] has been initialize with the cost of traveling from i to j, normally using an adjacency matrix.

For numerically meaningful output, Floyd-Warshall assumes that there are no negative cycles (in fact, between any pair of vertices which form part of a negative cycle, the shortest path is not well-defined). Nevertheless, if there are negative cycles, Floyd–Warshall can be used to detect them: either run one more iteration and see if there are any changes, or look for negative values in the diagonal.

Some of its applications and problems were it could be applied are
- Shortest paths in directed graphs.
- Transitive closure of directed graphs. In Warshall's original formulation of the algorithm, the graph is unweighted and represented by a Boolean adjacency matrix. Then the addition operation is replaced by logical conjunction (AND) and the minimum operation by logical disjunction (OR).
- Finding a regular expression denoting the regular language accepted by a finite automaton (Kleene's algorithm) (sound complex? yes!)
- Inversion of real matrices (Gauss-Jordan algorithm).
- Optimal routing. In this application one is interested in finding the path with the maximum flow between two vertices. This means that, rather than taking minima as in the pseudocode above, one instead takes maxima. The edge weights represent fixed constraints on flow. Path weights represent bottlenecks; so the addition operation above is replaced by the minimum operation.
- Testing whether an undirected graph is bipartite.


Hope this was useful to understand the algorithm and that you will be able to apply this algorithm in solving problems.



Reply to this topic



  


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users