8.3 How Are Shortest Paths Found?

shortest path the route that corresponds to the lowest cumulative transit cost between stops in a network

When you leave your home to go to work, you probably have several different ways you can go. Some of them are pretty direct and some of them are more roundabout, but you have plenty of options available. If you want to take the “shortest” path from home to work, you’ll probably focus on some of the more direct routes and eliminate some of the longer or more circuitous routes. However, a shortest path can mean different things. For instance, driving through city streets may be the shortest physical driving distance (in terms of mileage), but if those streets have lots of stop lights and traffic congestion, then this “shortest path” could easily take longer in terms of the time spent driving than a longer distance on a highway that doesn’t have these impediments. If you want to minimize the time spent driving, the highway route will probably get you to work faster, but you’d actually be traveling a longer distance. Major city streets can take a long time to navigate at rush hour, but you’ll probably sail through them much quicker if you make the same journey late at night.

All of these things have to be considered when you’re figuring out the shortest path (or “best route”) to take when traveling from an origin to a destination. People have their own decision-making criteria and stick to their own rules when it comes to determining what they judge to be the shortest path from one place to another—things like “always keep to the main roads,” or “use highways whenever you can,” or “never make a left turn.” This is why vehicle navigation systems often offer multiple options, such as “shortest distance” or “shortest driving time,” and sometimes apply conditions like “avoid highways” to compute the best route between points.

transit cost a value that represents how many units (of time or distance, for example) are used in moving along a network edge

Within a vehicle navigation system (or GIS), each line segment has a transit cost (or impedance) assigned to it. The transit cost reflects how many units (of things like distance or travel time) it takes to go the length of a particular edge. The transit cost may reflect the actual distance in miles from one junction to another along the edge. The transit cost could also be the equivalent time it takes to drive that particular segment. Whatever transit cost is used, that value will be utilized in the shortest path computation. Other impedance attributes can be modeled as well—segments could have different transit costs under certain conditions (such as heavy traffic or construction). These types of impedance factors can help in making a network more realistic for use.

256

algorithm a set of steps used in a process designed to solve a particular type of problem (for example, the steps used in computing a shortest path)

Dijkstra’s Algorithm an algorithm used in calculating the shortest path between an origin node and other destination nodes in a network

The shortest path is then calculated using an algorithm, a step-by-step mathematical procedure designed to solve a particular kind of problem—in this case to determine the overall lowest transit cost to move along the network from a starting point to a destination. There are various types of shortest path algorithms, including Dijkstra’s Algorithm (see Hands-on Application 8.3: Solve Your Network Problems with Dijkstra for more information on how to use this algorithm), which will compute the path of lowest cost to travel from a starting point to any destination in the network. For instance, say you have three different destinations you plan to travel to (work, the pizza shop, and the grocery store). Dijkstra’s Algorithm will evaluate the overall transit cost from your home to each destination, and find the shortest path from your home to work, from your home to the pizza shop, and from your home to the grocery store.

Whatever type of algorithm is used, the system will compute the shortest path, given the constraints of the network (such as transit cost or directionality of things like one-way streets). The system can then generate directions for you by translating the selected path into the various turns and names of streets that you’ll take as you follow the path through to your destination. See Figure 8.7 for an example of using an online geospatial technology utility to compute the shortest path or best route between two locations. Also check out Hands-on Application 8.4: Online Mapping and Routing Applications and Shortest Paths for some other Web tools for online directions and routing.

FIGURE 8.7 The blue line marks the shortest path from the White House to Georgetown University in Washington, D.C. (computed from MapQuest).(Source: MapQuest, Navteq, and Intermap)

257

!geo! HANDS-ON APPLICATION 8.3

Solve Your Network Problems with Dijkstra

The inner workings of Dijkstra’s Algorithm are beyond the scope of this book, but there’s an excellent free online resource that allows you to construct a sample network, then run the Dijkstra Algorithm to find the shortest path. The algorithm will walk through the shortest path step-by-step and describe the actions it’s taking (and how the shortest paths are created). Open your Web browser and go to http://www.dgp.toronto.edu/people/JamesStewart/270/9798s/Laffra/DijkstraApplet.html. On this Website, you can set up a series of nodes (junctions) and links (edges), assign weights (transit costs) and directions to them, and run the algorithm to find the shortest path between the origin and all destinations on the network. Use the interactive interface to construct a sample network (or use the pre-made example) and use Dijkstra to set up the shortest paths for you. From the pull-down menu on the left, select draw nodes, then click in the large window to place the nodes (there are also options for moving nodes to other locations or removing them altogether). Next, select the draw arrows option to place connections between the nodes. By selecting the change weights option, you can slide the arrow up and down a connector to alter the weight between two nodes. Click on the Run button on the right-hand side of the screen to execute the algorithm.

Expansion Questions:

  • Question

    Exh2SSoHeH8ubBM15pTCICSIs6H2FDWj6xQgLVOtkYfNHCyjpkIkr00M4dSA4V0/hkVUag/cbJil9OH9xpSnMkznoPI6Uu6kLWnhea5P7iMSLfpdBelpxdL9WDCKKoy/yDrMLyLYZOxsYoMBOavJCGI89MJro8SuR01m7wFAyNtETos7svVe7aW8N4AzBg7bqQ0mI281Jn7IWtaOzSwOtC+kSIHq1WV+VbUee1PI3nd6FUNjRIiaBdqIkE92OQWUZmZbN3oyOX+k10UY5l1SkRiWqwUqPijcFw2zh+gSFzR7JVXf
  • Question

    rcpwIyx9gCyXbI0paPE0wHFslW53cUy2ETvvlT1XP9ohSTmCJuqx5E39BQGzIEfgJoiWdT7eInldyjdPZKpu4aPJPriqW9E6azPaX0vUDxGW5vJWLuqvEnK4GtY12GMXfWeBB2FeHE+QeOTooGjSvP5cmcTmxoA2LDF6tYd/CVtiobam6LCryAn0VWpuJElMrNVEztYLhi7lxGjqVVS7mDMcaR4RMeZ+e6M0VQNNJnElc3M+D7yf1gX1n7Di7hC8GOctsLGJWi9HNNdNCfH22HVvQ6Xy72s3rOF8wWBGFRbCoEi+

!geo! HANDS-ON APPLICATION 8.4

Online Mapping and Routing Applications and Shortest Paths

There are many online applications available for creating a map of an address, and then generating a shortest path and directions from that address to another one. Examine the functionality of some of the following online mapping sites:

  1. Google Maps: http://maps.google.com
  2. MapQuest: http://www.mapquest.com
  3. Yahoo! Maps: http://maps.yahoo.com
  4. Bing Maps: http://www.bing.com/maps

Try inputting the same pair of locations (origin and destination) into each Web service and compare the shortest paths and routes they generate (some of them may be similar, some may be different, and some will likely give you more than one option for the “shortest path”). In addition, the services will also allow you to alter the route interactively by moving and repositioning junctions of the path, so you can tailor the route more to your liking.

Expansion Questions:

  • Question

    J2IS+uZT5qHi2RRbazytE1jJunmDeobD6UR8XOh7xSWWHKvX+A8f7+5APcAMM7VQEiEPF89LjCYSgsufOlCGi/cmlaZeQONmtNPtc7l4oKOpDh7BcDRLUb6FPW2d3fIu4YJrxRgOjLDStd6Bx6FER05tCEPeV1jz02H3MTSVI0V+fXcjEJgu+daKm2GERHNVwut1oBE295zTL8dvX08dp1GZt8FQgFKFWupMTEvAvGqRqLD8FwH2up/aD3VUQrc/lORV3OpNZSRtnqdPlqClIWjN6ydaQkeovAeN/j60a+P2JKH0sPNOUey7InDkdJQ/LokxCuOV9nKdPuJUdn6czaMuS6S0q8KKSKX0DZ3W8JmkaMF5+HNFnelY6w3n5wh4ADuhAYYSGLM0IJgaoqq5pXlRJvFxeHKqeRJmAOFBGI4i4otXpJ0sEecsd65M/2L7Jqm/TdiAInmJkayqUEB0FacbF72iVFBStoNXgsO6rco1GN8o9b1xnJTi13pUwVy6SbdHQA==
  • Question

    QQk/ChDpsxgEwG4sT6hncMSXvZy8xpriGy29uAq1pC868SyagkJMRy+mIfNjP4pich27o1uEn3ckrYWB9eKXhr/eBpv3EGhNrE97yFIprYJ4tUw8G07M9XRpHeudFbpS20C1NhKjfEF0h/mAzsZp0xpgVhRYoFoJaCrQydSEl3d7f8f0TqrsmOdmpZsp2BKFb+eAyV0EPQxHWMiu90nJatakkLjgcKRWJZjoQtnmamkqAeEPqdlIDvn4FHhHIJzPnTMLpWLxlkD9ncFSGI63gHSNVm9bRfKlkRWR+VGQmoFVB132SZZ7rKBRM1HelsvK

258

stops destinations to visit on a network

Of course, sometimes you have more than one destination to visit—say you have three places you want to stop at (shoe store, music store, and bookstore) and you want to drive the overall shortest route to hit all three places. When you’re using geospatial technology to compute a shortest route between several of these stops, there are two types of scenario to choose from:

  1. In the first scenario you need to find the shortest path when you’re going to be visiting stops in a pre-defined order: This means you have to stop at the shoe store first, the music store second, and the bookstore last. In this case, you’d want to find the shortest paths from your house to the shoe store, from the shoe store to the music store, and finally from the music store to the bookstore.
  2. The second scenario involves finding the shortest path when you can arrange the order of visiting the stops: For instance, if the bookstore and the shoe store are near each other, it makes sense to rearrange your travels, so you visit them one after the other, and then drive to the music store.

Geospatial technology applications can help determine some solutions to both of these scenarios. To visit stops in a pre-determined order, the system will find the shortest route (of all possible routes) from the origin to the first stop, then choose the shortest route to travel from the first stop to the second stop, and so on. An example of this in vehicle navigation systems is being able to set up a “Via Point” (another stop) between your origin and final destination—the device will then calculate the route from the origin (or current location) to the Via Point, then from the Via Point to the final destination.

With the ability to rearrange the order of stops, a system will evaluate options by changing the order of visiting stops to produce the overall shortest route. See Figure 8.8 for an example of how the “shortest path” changes between visiting stops in order as opposed to being able to rearrange the order of visiting the stops. Additional constraints can be placed on the problem—for instance, you may have to return home (the starting point) after visiting all of the stops. In that scenario, when you rearrange the stops, the starting point also becomes the last stop, and this may affect how the reordering is done. Conversely, you may want to have your starting point and ending point different from one another, and these types of parameters will have to be placed on the problem. Keep in mind that if you can arrange the order of stops, the program will likely give a decent solution to the problem; however, the only way to truly identify which configuration is the best is for the program to work through every possible arrangement—something that would be impossible with a larger number of stops.

FIGURE 8.8 Two different shortest paths through Youngstown, Ohio, both involving multiple stops at public libraries. The stops on the first path are made in a predetermined order (from #1 through #5 on the map). In the second map, the library visits are rearranged to find the shortest route (without a fixed starting or ending point).(Source: Esri)

259