Project 0: Graph Warmup

For this project, you will read from a file containing a description of a graph and let the user ask which vertices are connected to which edges. This project is intended to let you review the concepts involved with graphs so that you will be prepared for Project 1.

The graph text files

Each text file contains a description of a set of roads in Memphis. The text file is split into two sections: the "locations" section, and the "roads" section. Here is a sample of how a file might look:
location|203792386|-90.0020975|35.1606029
location|203841564|-90.0142355|35.1582919
location|1782970695|-89.9816435|35.1509496
location|203829293|-89.9948465|35.1590589
  ... more lines here ...
road|203792386|203848891|45|Jackson Avenue
road|203670568|203690459|25|North Idlewild Street
road|203659739|203659741|25|Hawthorne Street
road|203874737|203874738|25|Tutwiler Avenue
road|203785561|203785562|25|Mignon Avenue
  ... more lines here ...
All the "locations" come first. Each line that begins with "location" contains a description of an intersection where at least two roads meet. For each location, you are given a unique integer identifier (up to ten digits), then the longitude of the location, then the latitude. Because Memphis is in the Western Hemisphere, all of the longitudes will be negative numbers (they will all be close to -90).

After all of the locations, the file will lists all of the "roads." A road is any sort of straight-line connection between two locations. This covers any kind of surface a car can drive on. Roads with curves are approximated by multiple "road" listings, since a single "road" instance only represents a straight line. Each road is described by the identifiers of the locations that it connects, the speed limit on the road (in mph), and the name of the road.

For example, in the file above, the road Jackson Avenue connects the locations with the IDs 203792386 and 203848891, and has a speed limit of 45 miles per hour.

All roads are assumed to be bi-directional (no one-way streets), but each road is only listed once in the file. In other words, if there is a line in the file that looks like

road|x|y|....
then there will not be a line that looks like
road|y|x|....
even though your program should assume that you can travel in either direction between locations x and y.

Use these files for testing: west-of-rhodes.txt all-memphis.txt

What your program should do

Your program should ask the user for a filename, read the file, and then let the user type in the identifier for as many locations as they want. For each location, print the roads that are directly connected to that location, along with their speed limits and names. Keep asking the user for IDs until they type a zero, then quit.

Example Run

Enter a filename: west-of-rhodes.txt

Enter a location or zero to quit: 203744902
Location 203744902 has edges leading to:
   203744900 35 mph North McLean Boulevard
   203874090 25 mph Lyndale Avenue
   203744903 35 mph North McLean Boulevard

Enter a location or zero to quit: 204000748
Location 204000748 has edges leading to:
   761690915 35 mph University Street
   424696634 35 mph University Street

Enter a location or zero to quit: 203804462
Location 203804462 has edges leading to:
   1782962464 25 mph North Evergreen Street
   203848835 25 mph North Evergreen Street
   203659689 25 mph Forrest Avenue
   203804459 25 mph Forrest Avenue

Enter a location or zero to quit: 203821515
Location 203821515 has edges leading to:
   203874118 35 mph University Street
   2471207719 35 mph University Street
   203785186 25 mph Snowden Avenue

Enter a location or zero to quit: 203744908
Location 203744908 has edges leading to:
   203744906 35 mph North McLean Boulevard
   203690459 45 mph Jackson Avenue
   203670571 35 mph North McLean Boulevard
   203761725 45 mph Jackson Avenue
   
Enter a location or zero to quit: 203744906
Location 203744906 has edges leading to:
   203659729 25 mph Crump Avenue
   203744904 35 mph North McLean Boulevard
   203744908 35 mph North McLean Boulevard

Enter a location or zero to quit: 0

Additional information

The order of the roads printed for each location entered does not matter.

Hints

You should construct a graph data structure to represent the road network. Locations are vertices, and the roads are edges. If you do this using the standard techniques from CS241, this program should be straightforward.

What to turn in

Through Moodle, upload your source code in Python or C++.

Extra details you may or may not care about

All of the files were created by downloading data from OpenStreetMap. I wrote a program to guess the speed limits based on the OpenStreetMap data for roads that didn't have speed limits encoded in the data, so some of the speeds probably aren't correct in reality.