The Second Agent: In Bordo

The Second Agent: In Bordo

The cheapest fare from Ajo is to Bordo, at $50. So you hire a passerby and send him to Bordo, where he’ll be your agent. When he’s there, he calls you by telephone and tells you that the Bordo stationmaster says it costs $60 to ride to Colina and $90 to Danza.

Doing some quick arithmetic, you figure it must be $50 plus $60, or $110 to go from Ajo to Colina via Bordo, so you modify the entry for Colina. You also can see that, going via Bordo, it must be $50 plus $90, or $140, from Ajo to Danza. However—and this is a key point—you already know it’s only $80 going directly from Ajo to Danza. You care only about the cheapest route from Ajo, so you ignore the more expensive route, leaving this entry as it was. The resulting notebook entries are shown as the last row in Table 14.3. Figure 14.7 shows the situation geographically.

D Danza

E Erizo

Towns with Agents

Fringe towns

Unknown towns

(Vertices in tree)

(Not in tree)

(Not in tree)

FIGURE 14.7 Following step 2 in the shortest-path algorithm.

The Shortest-Path Problem 691

TABLE 14.3 Step 2: Agents at Ajo and Bordo From Ajo to→

Step 1 50 (via Ajo)

inf Step 2

inf

80 (via Ajo)

50 (via Ajo)*

110 (via Bordo)

80 (via Ajo)

inf

After we’ve installed an agent in a town, we can be sure that the route taken by the agent to get to that town is the cheapest route. Why? Consider the present case. If there were a cheaper route than the direct one from Ajo to Bordo, it would need to go through some other town. But the only other way out of Ajo is to Danza, and that ride is already more expensive than the direct route to Bordo. Adding additional fares to get from Danza to Bordo would make the Danza route still more expensive.

From this we decide that from now on we won’t need to update the entry for the cheapest fare from Ajo to Bordo. This fare will not change, no matter what we find out about other towns. We’ll put a * next to it to show that there’s an agent in the town and that the cheapest fare to it is fixed.

Three Kinds of Towns

As in the minimum spanning tree algorithm, we’re dividing the towns into three categories:

1. Towns in which we’ve installed an agent; they’re in the tree.

2. Towns with known fares from towns with an agent; they’re on the fringe.

3. Unknown towns. At this point Ajo and Bordo are category 1 towns because they have agents there.

Category 1 towns form a tree consisting of paths that all begin at the starting vertex and that each end on a different destination vertex. (This is not the same tree, of course, as a minimum spanning tree.)

Some other towns have no agents, but you know the fares to them because you have agents in adjacent category 1 towns. You know the fare from Ajo to Danza is $80 and from Bordo to Colina is $60. Because the fares to them are known, Danza and Colina are category 2 (fringe) towns.

You don’t know anything yet about Erizo, it’s an “unknown” town. Figure 14.7 shows these categories at the current point in the algorithm.

As in the minimum spanning tree algorithm, this algorithm moves towns from the unknown category to the fringe category, and from the fringe category to the tree, as it goes along.

692 CHAPTER 14 Weighted Graphs