## CS 340 Spring 2008: Project 2

In this project you will build on your first project and extend it to compute the shortest path between arbitrary points in your state (or states) of choice.

The final goal is to be able to click with the mouse on the map to select two nodes, compute the shortest path between them, and display the path in a different color on the screen.

To select a node with a mouse, you will need to research into mouse call-back functions in OpenGL. Essentially a mouse click will return the coordinates of the clicked point on screen, which you'll be able to map into a point in your region. The fact that you dont use any GL transformations (translation, rotation, scaling, projection), will make this easier.

Then you'll have to find the nearest node of that point which is a node in the TIGER/Line dataset of your region. For this use the straightforward approach, a linear scan through the nodes; or better, use the bounding box of the county (maybe Project 3 will extend this with a nearest-neighbor structure).

Once the two nodes are selected, you'll implement Dijkstra's algorithm to find the shortest path (SP) between the nodes. For this step, you will need to think of and represent the TIGER/Line dataset as a graph. The TIGER/Line dataset claims to form a topologically consistent network; that is, any intersection of two segments, of whatever type, is marked with a node. You will need to transform (your representation of) the chains into a graph having as vertices the nodes of the chains (the endpoints of chains); for any chain between node n1 and n2 , you will add an edge from n1 to n2. Note that the graph will completely ignore the shape points of a chain.

Put it differently: for Project 1, your representation of the TIGER/Line chains contained only geometry: you kept the coordinates of the start and end points of chains. Now, you will need to add topology, that is, connectivity information: what chains are connected to what chains. In the end you will need a structure that will store for every node its geometric coordinates and its adjacent edges (that is, chains), together with whatever information may be necessary for an edge(like, weight, TLID, etc). My advice is to store this as an array of nodes, each entry containing a list of adjacent edges.

Note that for Project 1, you had a chain-based structure. For this project you will need a node-based structure.

I estimate that this part, adding topology on top of your array/list of chains, will be the hardest part of the project. Once you have the graph, implementing Dijkstra will be "easy". The code for Dijkstra should be less than 50 lines. I will give you a priority queue implementation here.

For the SP of the project you will not need shape points of chains. Once you know the chains that constitute the SP, it would be nice to display each chain correctly (showing its shape points). However, if you want to ignore shape points completely, that is fine too.

#### Programming

As you write code for this project, remember that the goal is not to get the job done! Really. The goal is to learn to write code that is readable, debuggable and maintanable. And, last but not least, to enjoy doing this. Programming is rewarding (most of the times), if you do it the right way. (Now really, didn't you feel great when you saw the roads pop up on the screen?)

Think before you start writing the code. Have the overall structure of your program clear, and how different parts will interact with each other. Use small functions, with well-defined behaviour. Test each function that you write before you go to the next one!

If this is not enough motivation, keep in mind that the amount of help I can give you is directly proportional with the style of your code (yet another irony..). The faster I can understand how your program works, the easier it is to figure out what is wrong. If you show me a 3-screen long function, with globals, and pointers to pointers, and everything in a single file...

As usual, start early, don't procrastinate, and..keep it fun!