课 Progress
0% Complete

Floyd’s algorithm

What is Floyd’s algorithm?

  • Floyd’s algorithm finds the shortest distance and the shortest route between any pair of nodes in a network

  • This is achieved by setting up and updating a pair of matrices

    • The first is a matrix of (least) distances between nodes

      • it is generally called the distance matrix 

      • the final distance matrix shows the shortest distance between any pair of nodes

    • The second matrix allows the shortest route between nodes to be deduced

      • it is generally called the route matrix

  • At each stage (iteration) of Floyd’s algorithm, both the distance matrix and route matrix are updated

  • Floyd’s algorithm will seem long winded and slow at first

    • But the symmetry (in undirected networks) in the distance matrix can reduce the amount of work involved whilst also acting as a check

 

How do I set up the initial distance matrix and initial route matrix for Floyd’s algorithm?

  • The initial distance matrix has the direct distances between nodes

    • If there is no direct distance the symbol infinity is used (to represent/assume a very large distance!)

    • In an undirected network, all distance matrices will exhibit symmetry

      • this is because the distance from node A to C, say, will be the same as the distance from C to A

      • this will apply to all pairs of nodes

      • this helps reduce the work required in Floyd’s algorithm but also acts as a means of checking each distance matrix 

  • The initial route matrix assumes the shortest route between each pair of nodes is a direct link

    • So the shortest route between A and D, say, is to go directly from A to D

    • It doesn’t matter if there is no direct link between a pair of nodes

      • this will be accounted for later in Floyd’s algorithm

Worked Example

For the network shown below, set up the initial distance matrix and the initial route matrix for Floyd’s algorithm.

floyd-we-network

Use the direct distances given on the diagram Where there is no direct link, use infinity for the (initial) distance

There is a direct link between nodes A and C, with a distance of 5, so row A, column C will contain a 5 (This is also true for row C, column A, as the network is undirected)

There is no direct link between nodes A and E, so use infinity (also true for row E, column A)

 

Initial distance matrix

 

A

B

C

D

E

A

7

5

10

bold infinity

B

7

4

bold infinity

3

C

5

4

6

<img alt=”bold infinity” data-mathml='<math ><semantics><mo mathvariant=”bold”>∞</mo><annotation encoding=”application/vnd.wiris.mtweb-params+json”>{“language”:”en”,”fontFamily”:”Times New Roman”,”fontSize”:”18″,”autoformat”:true}</annotation></semantics></math>’ data-type=”finalAnswer” height=”19″ role=”math” src=”data:image/svg+xml;charset=utf8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20xmlns%3Awrs%3D%22http%3A%2F%2Fwww.wiris.com%2Fxml%2Fmathml-extension%22%20height%3D%2219%22%20width%3D%2221%22%20wrs%3Abaseline%3D%2216%22%3E%3C!–MathML%3A%20%3Cmath%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1998%2FMath%2FMathML%22%3E%3Cmo%20mathcolor%3D%22%23000%22%20mathvariant%3D%22bold%22%3E%26%23x221E%3B%3C%2Fmo%3E%3C%2Fmath%3E–%3E%3Cdefs%3E%3Cstyle%20type%3D%22text%2Fcss%22%3E%40font-face%7Bfont-family%3A’math1ae502204564aafbffb712be630’%3Bsrc%3Aurl(data%3Afont%2Ftruetype

Responses

您的邮箱地址不会被公开。 必填项已用 * 标注