

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A programming project for cse 331 students during the fall semester, 2001. The goal is to implement a trip planner using dijkstra's algorithm to find the shortest path between two points in a graph. Students are required to submit their implementation using the 'handin' system before 11:59pm on november 18, 2001. An overview of the project, the input format, and the driver program.
Typology: Study Guides, Projects, Research
1 / 3
This page cannot be seen from the preview
Don't miss anything!


In this project you will implement a trip planner. You will implement Dijkstra’s Algorithm, which finds the shortest path between two points in a graph. Submit your work using the “handin” system before 11:59pm on Sunday, November 18. Submit all of your .cpp and .h files, and a makefile. You should not submit any of the provided code.
The graph “map” will be stored in a file. The format of the file is as follows:
VERTICES id1 name1 comment id2 name2 comment id3 name3 comment ... EDGES id_a id_b distance name id_c id_d distance name ...
Most of the input code is provided. Each vertex has a positive integer id, a name, and a comment. The comments are ”none”, ”scenic” or ”bigcity”. Each edge is described by a pair of vertex ids, a distance between them, and a name. We will assume that the graph is symmetric. We will assume that the input is correct.
The driver will read the graph in from a file specified by the command line argument. It will then read in commands from the standard input. There are three commands.
The Algorithm
Dijkstra’s algorithm is described in the book in considerable detail. See pages 289-298. The basic trip command is just a straightforward application of Dijkstra’s algorithm. To determine the actual shortest path, you start at the final vertex, and trace the path taken back to the starting vertex. In order to print out the path in the correct order, we can push the edges taken onto a stack. You do not have to use a stack, but it is an obvious choice. To implement the ruraltrip command, we just apply Dijkstra’s algorithm to the set of vertices whose comment is other than ”bigcity”. Everything else is the same. The scenictrip is the hardest. To caculate this, we need to calculate the shortest path from the starting point to a scenic point, and then the shortest path from that scenic point to the end point. We need to do this for all scenic points in the graph, and take the minimum. The psuedo code for this looks like
scenictour(int start, int end) { for each x (x is a scenic point) { // // P1,P2 and currentBest are all paths. A path has a length. // You do not actually need to implement a path class // calculate P1=trip(start, x) calculate P2=trip(x, end) if (P1.length+P2.length < currentBest.length) { currentBest=P1+P2; } } }