next up previous contents
Next: Common Characteristics Up: A Tutorial on Dynamic Previous: First Example

A second example

Dynamic programming may look somewhat familiar. Both our shortest path algorithm and our method for CPM project scheduling have a lot in common with it.

Let's look at a particular type of shortest path problem. Suppose we wish to get from A to J in the road network of Figure 2.

   figure156
Figure 2: Road Network

The numbers on the arcs represent distances. Due to the special structure of this problem, we can break it up into stages. Stage 1 contains node A, stage 2 contains nodes B, C, and D, stage 3 contains node E, F, and G, stage 4 contains H and I, and stage 5 contains J. The states in each stage correspond just to the node names. So stage 3 contains states E, F, and G.

If we let S denote a node in stage j and let tex2html_wrap_inline946 be the shortest distance from node S to the destination J, we can write

displaymath952

where tex2html_wrap_inline954 denotes the length of arc SZ. This gives the recursion needed to solve this problem. We begin by setting tex2html_wrap_inline958 . Here are the rest of the calculations:

Stage 4.
During stage 4, there are no real decisions to make: you simply go to your destination J. So you get:

Stage 3.
Here there are more choices. Here's how to calculate tex2html_wrap_inline966 . From F you can either go to H or I. The immediate cost of going to H is 6. The following cost is tex2html_wrap_inline962 . The total is 9. The immediate cost of going to I is 3. The following cost is tex2html_wrap_inline964 for a total of 7. Therefore, if you are ever at F, the best thing to do is to go to I. The total cost is 7, so tex2html_wrap_inline972 .

The next table gives all the calculations:

tabular421

You now continue working back through the stages one by one, each time completely computing a stage before continuing to the preceding one. The results are:
Stage 2.

tabular433

Stage 1.

tabular442


next up previous contents
Next: Common Characteristics Up: A Tutorial on Dynamic Previous: First Example

Michael A. Trick
Sun Jun 14 13:05:46 EDT 1998