Vous êtes sur la page 1sur 4

Kth Shortest Path Example

Matt Redmond January 28, 2010

Introduction

The Shortest Path problem is very common and has many solutions. Here I present the inner working details of the Kth shortest path problem. This has been written out in other places, but I hope to reveal how it works to the nner details.

2
2.1

The Example Problem


Problem

Given the following network:

Based on Professor Jays Lecture which is loosly based o Larson and Ordonis book, Urban Operations Research mredmond@uci.edu

In the network gure above, the circles with the numbers inside are the numbered nodes. The directional arrows that are connecting the nodes are the links, which have a certain travel time (distance/length) associated with them. We are asked to nd the shortest path to all the other nodes, with our orgin at 1.

2.2

Solution

To start we initilize our rst length (or distance) label from position 1 as well as all the predicessor labels. This is simply: l1 l2 l3 l4 l5 = {0, , , } = {, , , } = {, , , } = {, , , } = {, , , } P1 P2 P3 P4 P5 ={ ={ ={ ={ ={ , , , , , , , , , , , , , , , } } } } } (1) (2) (3) (4) (5)

We then close the smallest label, l1 (1)=0. Then go exploring to the other nodes connected to 1 and try to ll in the s and blanks . l2 l3 l4 l5 = {1, , , } = {2, , , } = {1.5, , , } = {, , , } P2 = {1, P3 = {1, P4 = {1, P5 = { , , , , , , , , , } } } } (6) (7) (8) (9)

We then nd the minimum value over all the labels, which is: l2 (1) = 1. So we close this path. Since this is the shortest path out of node 1, we will denote this by putting a box around this rst minuver to show it is closed. l2 = { 1 , , , } We then go exploring again. From node 2 we will move to nodes 3 and 5, where l2 will remain unchanged. l3 = {2, 2.5, , } l5 = {2, , , } P3 = {1, 2, , } P5 = {2, , , } (10) (11)

Notice that these values for the length are the cummulative lengths from node 1 to node ln . We can see here from this formulation, (10), that the 2

second shortest path for node 3, comes from node 2. We then look at the minimum of all the lengths and close that node. Seeing that l4 (1) has the minimum distance of 1.5, we will choose this node to close next. l4 (1) = { 1.5 , , , } Going exploring from node 4 we nd that we can only go to nodes 3 and 5. So we update our Length and Precident labels for nodes 3 and 5 only. l3 = {2, 2.5, 4.5, } l5 = {2, 3.5, , } P3 {1, 2, 4, } P5 {2, 4, , } (12) (13)

Again, we look for the minimum distance among all the lengths that are still open. So between , 2, , 2 (in order of l2 to l5 ), we have a tie. In case of a tie simply choose either node arbitrailly. So Ill choose node 5 just for kicks! We see that l5 (1)=2. Closing node 5 we have: l5 = { 2 , 3.5, , } We then try to go exploring but we nd no connected nodes. To proceed we choose the minimum length distance again. Since we had a tie last time, this time we know it will be l3 . So we close l3 as well. l3 = { 2 , 2.5, 4.5, } We then go exploring from node 3. We can go to nodes 2,4 and 5. Doing so we tally up the total trip lengths from node 1 to each of these nodes. For example, from node 1 to 3, we have a length of 2. We add this length of 2 to the other link length of 2.5 if we are going to node 2. So in the label for node 2, we replace the next symbol with this new length of 4.5 (=2+2.5). Similarly, we ll in the next blank in the Predicessor label, which is simply the last node we are comming from; node 3 in this case. l2 = { 1 , 4.5, , } l4 = { 1.5 , 4, , } l5 = { 2 , 3.5, 5, } P2 = {1, 3, , } P4 = {1, 3, , } P5 = {2, 4, 3, } (14) (15) (16)

So of all the nodes that are still open (not with the box around them) we nd the smallest value. This again is node 3, for it has a length of 2.5 in the second position of its length label. Therefore we close it. l3 = { 2 , 2.5 , 4.5, } 3

Again we go exploring from this node that was just closed. Doing so we nd new travel distances to nodes 2,4 and 5 again. Filling in the new trip lengths and predicessor node values we obtain the following. l2 = { 1 , 4.5, 5, } l4 = { 1.5 , 4, 4.5, } l5 = { 2 , 3.5, 5, 5.5} P2 = {1, 3, 3, } P4 = {1, 3, 3, } P5 = {2, 4, 3, 3} (17) (18) (19)

Notice here that for node 2 we have 2 shortest paths that both come from node 3. This is due to a loop in the network. For node 2, the second fastest way to get there is to go from Node 1 to Node 3 and then from node 3 to go to node 2. The third fastest path to get there is to go from node 1 to node 2, and then to go to node 3, and then from node 3 go BACK to node 2. We then look for the smallest unclosed node among our link length values. This will be the length of 3.5, found at: l5 (2)=3.5. So we close it. l5 = { 2 , 3.5 , 5, 5.5} So again, from node 5 we are unable to go exploring, because all the nodes point to it, and none leave it. So we go back to the list of lengths and choose the next smallest length that is not closed already. We nd that l4 (2)=4, is our smallest value, so we close it. l4 = {1.5, 4, 4.5, } From node 4 then, we go exploring. We ll in the new link lengths for connected nodes 3 and 5. Continuing on we would choose the smallest link length and close that node, then go exploring from it. Rinse lather and repeat untill all the nodes are closed.

Conclusion

This was an attempt to bring the algorithm for the 1st , 2nd , 3rd kth shortest paths. I tried to provide as much explination as possible between steps so the process becomes more intuitive to grasp. Hope it helps, and good luck nding the shortest path to where ever you may be going in this journey we call life.

Vous aimerez peut-être aussi