Sei sulla pagina 1di 3

___________________________________________

*
Copyright is held by the author/owner.
253
A DIJKSTRA'S ALGORITHM SHORTEST PATH ASSIGNMENT
USING THE GOOGLE MAPS API
*
POSTER SESSION
James D. Teresco
Visiting Associate Professor of Computer Science
Mount Holyoke College
South Hadley, MA 01075
(413) 538-3253
jteresco@mtholyoke.edu
An assignment involving a hands-on implementation of Dijkstra's Algorithm for
computing single-source shortest paths is a useful supplement to a class discussion and
readings about graph structures and algorithms in a data structures course. Ideally, the
graph data used needs to be small enough to be manageable, but large enough to be
interesting. This might consist of a small road system, airline schedules, or even the
layout of a campus or building. This poster presents a variation on a Dijkstra's Algorithm
assignment that uses the Google Maps API [2] and highway routing data from the
Clinched Highway Mapping (CHM) Project [3] that allows students to compute and
display, in Google Maps, real routings between locations.
The CHM Project allows road and travel enthusiasts to track the highways on which
they have travelled. Project collaborators have gathered and continue to gather data about
a variety of highway systems in North America and Europe for use in the project. The
data consists of a set of waypoints for each highway included in the project. A
waypoint consists of a place name and its coordinates (latitude/longitude). Most
waypoints are at major intersections, but others are included primarily to help define the
shape of the route more accurately. The granularity is not sufficient to provide a perfect
representation of a highway's route, but is fine enough to be reasonably accurate and
coarse enough, leaving out route details and insignificant intersections, to avoid
overwhelming the tools and the users. The CHM data is used by a Highway Browser that
allows project participants to view the highway's route so they can create lists of the
highway segments they have travelled. These lists are then used to generate statistics and
maps of the participants' travels.
For the purposes of this assignment, the mapping data is treated in its raw form: the
individual highway data files (lists of waypoints) that make up a highway system. The
JCSC 25, 6 (June 2010)
254
highway data files are used as input to the support programs developed by the author to
generate a set of composite highway data for a given highway system. The composite
highway data is stored in a format convenient for use in this assignment, and is readily
processed by student programs to construct a graph structure for a highway system.
During the Fall 2009 semester, the highway systems made available to students included
small systems that are useful during development and debugging such as the Interstate
highway system in Hawaii (47 waypoints/vertices, 48 connections/edges) and the Yukon
Provincial highway system (351 waypoints, 354 connections), and larger systems such
as the set of all Interstate, U.S., and state highways in New York state (7265 waypoints,
8416 connections). Several other highway systems are available from the CHM Project,
with many more under construction.
The CHM data provides real and appropriately-sized input for an academic study
of Dijkstra's Algorithm. The Google Maps API provides a fun and useful way to
visualize the data and the results. The Google Maps API is free to use, but a domain-
specific API key must be obtained and specified in the plotting program. Points and
routes can be plotted in a browser window, much like that done by Google Maps and
other mapping sites. The students' Java programs produce output files consisting of
points to be plotted, with connections optionally drawn between successive points.
Students upload their output files to the course web server, where they can visualize their
results in map form. Students are encouraged to examine the Javascript program that
generates the maps, but they need not modify it.
Students are provided with a starter program with a few methods left as stubs to be
filled in. Students are required to implement methods that construct an appropriate graph
structure, print the graph data to the screen or into files suitable for display using the
mapping scripts, and compute shortest paths using Dijkstra's Algorithm and print them
to the screen or into mapping data files. Students base their implementation of Dijkstra's
Algorithm on the one provided as an example by Bailey's free textbook, Java Structures
[1], the primary text for the course. Students are also provided with input data format
descriptions, output format requirements, and instructions to upload files and view results
in the Google Maps environment.
Student reaction to the assignment was very positive. They were excited to be able
to work on a program that would produce results that they could display with the mapping
scripts. Students were allowed to work in groups of 2 or 3 for this assignment, and were
given about a week and a half to complete the assignment. Students formed 4 groups, 3
of which made submissions that were complete and correct or nearly so.
This assignment will continue to be improved for use in future offerings of data
structures. Additional development will improve the pre-processing tools and further
automate the process of displaying mapping data. Improved processing of the CHM data
will result in more user friendly highway data. For example, the junction of New York
state routes 29 and 30 would currently receive the waypoint name
@NY29: NY30@NY30: NY29, a simpler name such as NY29/ NY30 could be generated
automatically and would be easier to work with. Waypoints that are not at important
intersections but are included only for route shaping (typically prefixed by +in the CHM
data) could be folded into adjacent edges. Improvements to the map display will allow
more control over the points to be plotted and will further automate the visualization
CCSC: Northeastern Conference
255
process. Ideally, a student will be able to upload results through a web form rather than
separate steps to copy to the server and to enter an appropriate URL, as is currently
required.
Support materials, handouts, and sample solutions are available on request from the
author.
REFERENCES
[1] Bailey, D. A., Java Structures, Data Structures in Java for the Principled
Programmer, sqrt(7) edition,
http://www.cs.williams.edu/~bailey/JavaStructures/Welcome.html, Williams
College, 2007.
[2] Google, Inc., Google Maps API Reference, 2010,
http://code.google.com/apis/maps/, retrieved January 10, 2010.
[3] Reichard, T., The Clinched Highway Mapping Project, 2010, http://cmap.m-
plex.com/, retrieved January 10, 2010.

Potrebbero piacerti anche