CSE 331 Programming Project: A Trip Planner - Implementing Dijkstra's Algorithm, Study Guides, Projects, Research of Computer Science

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

Pre 2010

Uploaded on 07/28/2009

koofers-user-cwr
koofers-user-cwr 🇺🇸

10 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CSE 331
Programming Project #4: A Trip Planner
Fall Semester, 2001
Overview
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.
Input
The graph “map” will be stored in a file. The format of the file is as follows:
VERTICES
id1 name1 comment1
id2 name2 comment2
id3 name3 comment3
...
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.
Driver
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.
1
pf3

Partial preview of the text

Download CSE 331 Programming Project: A Trip Planner - Implementing Dijkstra's Algorithm and more Study Guides, Projects, Research Computer Science in PDF only on Docsity!

CSE 331

Programming Project #4: A Trip Planner

Fall Semester, 2001

Overview

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.

Input

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.

Driver

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.

  • trip start end. Calculate the shortest path from the vertex named start to the vertex named end.
  • ruraltrip start end. Calculate the shortest path from the vertex named start to the vertex named end that does not pass through a big city.
  • scenictrip start end. Calculate the shortest path from the vertex named start to the vertex named end that passes through a scenic spot.

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; } } }