← All projectsCOSC 1 / Software

Campus pathfinder

Finding and drawing routes across a campus map.

Dartmouth campus map with a blue graph and a red route between selected locations
Original COSC 1 screenshot: the selected path is red, with the full campus graph in blue. View full size (new tab): Dartmouth campus map with a blue graph and a red route between selected locations

Choosing a route

Click a location to set the start, then move the pointer over another vertex to choose a destination. The program redraws the route on top of the campus map. The map is a graph: locations are vertices and the connections between them are edges.

Breadth-first search

A queue holds the frontier of the search. As vertices are discovered, a backpointer records where each came from. Once the search has reached the goal, following those pointers reconstructs a path from the destination to the start. Because the graph is unweighted, this finds a route with the fewest edges; it does not minimize walking distance.

A second campus-map screenshot with a different route highlighted in red
A different pair of selected locations produces a new path. View full size (new tab): A second campus-map screenshot with a different route highlighted in red

Drawing and data

The graph loader creates vertex objects from a text file, and the graphics loop draws the vertices and their adjacency lists. Mouse handling, graph search, and drawing are separate parts of the program. The supplied cs1lib library handles the graphics window.

Mithun RameshkumarDartmouth College