This lab has several important differences from the earlier labs:
The Oracle of Bacon searches a movie database to find a path between Kevin Bacon and other actors using a graph defined by the co-star relationship: two actors are connected by an edge if those two actors co-starred in a movie together. An actor's Bacon number is the length of the shortest path between that actor and Kevin Bacon. For example, the Oracle of Bacon might report that Kevin Bacon is connected to Kurt Russell with a length-2 path:
Kurt Russell was in Mean Season, The (1985) with Andy Garcia Andy Garcia was in Air I Breathe, The (2007) with Kevin Bacon Kurt Russell has a Kevin Bacon number of 2
In this lab you will first implement several graph algorithms and then use the Graph and other data structures from this course to respond to queries about movies and actors.
As usual, you can get the initial files for this lab by running update35. The new files are listed here, and the files that you will need to edit are highlighted in red:
You may work with a partner for this lab, but if you work with a partner you and your partner must work together using pair programming.
The basic idea of pair programming is simple: both you and your partner must always be present while working on the lab, with one of you typing and the other watching and helping. To pair program you and your partner must contribute equally, switching roles frequently so that you and your partner both implement similar fractions of the lab.
We will not accept "partner" work for which one partner was not present or did not make a substantial contribution; if you work with a partner, never code alone. Before starting to work with a partner, please ensure that you and your partner have compatible work schedules with adequate available time to meet and complete the lab.
You should start by reviewing our implementation of the Graph class. Our Graph uses an edge-list representation: for each vertex we store a list (an STL vector, actually) of the outgoing edges from that vertex. The edge-list data for all vertices is stored in a single HashTable, using vertices as the keys and their edge-lists as the values.
Please complete each function marked with a TODO comment in graph-algorithms.inl. You must test each function you implement using the testGraph program.
Your main work for this lab is to implement oracle.cc. This program should first read a movie database file, then provide an interactive menu that allows the user to request information from your movie database. Specifically, your program should support the following queries:
Your program should allow the user to repeatedly select a menu option until they select a "Quit" option or type CTRL-D. When possible, you should gracefully handle incorrect input such as when the user enters an actor or movie name not in the database.
The data files for this lab are in the /usr/local/doc directory, accessible from the CS lab computers. Some of these files are moderately large. We strongly urge you to test your program using the smaller files, and only use the larger files when you are confident that your program works. The files are:
You might find the following hints more or less helpful:
totalDistance = 0.0 numVertices = 0.0 component = Use BFS to find all vertices in v's component For each vertex u in component: totalDistance += distance(v, u) numVertices += 1 return totalDistance / numVerticesThis is needlessly inefficient because many computations of distance(v,u) might each search O(n) other vertices. (Given that, what is the total running time of this pseudocode?) Instead, you should directly compute the distance between v and each other vertex during a single breadth-first search of the graph.
Once you are satisfied with your program, hand it in by typing handin35 at the unix prompt. You and your partner should handin just one copy of your lab.
You may run handin35 as many times as you like, and only the most recent submission will be recorded. This is useful if you realize after handing in some programs that you'd like to make a few more changes to them.