Program Assignment 3: Graph Shortest Path Problems, Assignments of Computer Science

A programming assignment for a university course, cop 3503h, where students are required to implement graph data structures in java and run dijkstra's and ford's algorithms to find the shortest path in a graph. The assignment includes instructions on how to implement the graph data structure, input and output specifications, and restrictions. Students are expected to write a complete program, including comments with their name, assignment title, and date.

Typology: Assignments

Pre 2010

Uploaded on 11/08/2009

koofers-user-fxt
koofers-user-fxt 🇺🇸

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
42
Title: “Program Assignment 3: Graph Shortest Path Problems”
Points: 100 points – 60pts for coded portion, 40 points for written analysis
Due Date: Monday December 2, 2002 (last day of class)
Objectives: (1) To implement graph data structures in Java. (2) To implement two classical graph
shortest path algorithms.
Description: Create a Java program that will produce the shortest path through (1) a positively
weighted directed graph using Dijkstra’s algorithm and (2) a directed graph with negative weights
using Ford’s algorithm. Note: Ford’s algorithm works for either positive or negative edge weights,
for our purposes here, use only Dijkstra for positively weighted graphs and use Ford exclusively for
negatively weighted graphs. Do this according to the steps shown below:
1. You will need to implement a graph data structure capable of storing the weights of the
edges in the graph. See Day 22 notes for graph implementation techniques, your choice of
which technique to use.
2. For each graph containing only positive weights, run Dijkstra’s algorithm on the graph and
produce the shortest path through the graph, given start and destination vertices. Your
program should print the vertices in the path as well as the length of this path.
3. For each graph that contains a negatively weighted edge, run Ford’s algorithm on the graph
and produce the shortest path through the graph, given start and destination vertices. Your
program should print the vertices in the path as well as the length of this path.
References:
Notes: Lecture Notes for Days 22 & 23
Restrictions:
Your source file shall begin with comments containing the following information:
/* Name:
COP 3503H
Assignment title:
Date:
*/
Input Specification: I will place on the website a set of graphs that will be used as input for your
program. Use any graph you want for testing purposes, but the runs you
submit for grading must use the graphs on the website. Rather than require
everyone to use the same rigid input format, I will leave it up to you as to
how to input the graph information. I will supply it to you in the following
format: (emanating vertex, incident vertex, weight). As an example, the
following set of data would produce the graph shown below:
(A, B, 4) (C, D, -3) (B, D, 5) (D, E, 2) (C, A, 3) (E, B, 2) (D, A, 4)
Page 1
COP 3503H – Programming Assignment #3 – Fall 2002
A B
pf2

Partial preview of the text

Download Program Assignment 3: Graph Shortest Path Problems and more Assignments Computer Science in PDF only on Docsity!

Title: “Program Assignment 3: Graph Shortest Path Problems” Points: 100 points – 60pts for coded portion, 40 points for written analysis Due Date: Monday December 2, 2002 (last day of class) Objectives: (1) To implement graph data structures in Java. (2) To implement two classical graph shortest path algorithms. Description: Create a Java program that will produce the shortest path through (1) a positively weighted directed graph using Dijkstra’s algorithm and (2) a directed graph with negative weights using Ford’s algorithm. Note: Ford’s algorithm works for either positive or negative edge weights, for our purposes here, use only Dijkstra for positively weighted graphs and use Ford exclusively for negatively weighted graphs. Do this according to the steps shown below:

  1. You will need to implement a graph data structure capable of storing the weights of the edges in the graph. See Day 22 notes for graph implementation techniques, your choice of which technique to use.
  2. For each graph containing only positive weights, run Dijkstra’s algorithm on the graph and produce the shortest path through the graph, given start and destination vertices. Your program should print the vertices in the path as well as the length of this path.
  3. For each graph that contains a negatively weighted edge, run Ford’s algorithm on the graph and produce the shortest path through the graph, given start and destination vertices. Your program should print the vertices in the path as well as the length of this path. References: Notes: Lecture Notes for Days 22 & 23 Restrictions: Your source file shall begin with comments containing the following information: / Name: COP 3503H Assignment title: Date: / Input Specification: I will place on the website a set of graphs that will be used as input for your program. Use any graph you want for testing purposes, but the runs you submit for grading must use the graphs on the website. Rather than require everyone to use the same rigid input format, I will leave it up to you as to how to input the graph information. I will supply it to you in the following format: (emanating vertex, incident vertex, weight). As an example, the following set of data would produce the graph shown below: (A, B, 4) (C, D, -3) (B, D, 5) (D, E, 2) (C, A, 3) (E, B, 2) (D, A, 4) Page 1

COP 3503H – Programming Assignment #3 – Fall 2002

A B

Output Specification: For each graph in the input, your program must select the appropriate shortest path algorithm (Dijkstra or Ford, and indicate which was selected) to execute on the graph and produce a listing of the shortest path in the graph (in proper order) as well as the length (weight) of this path. For example, given the graph shown above and assuming the start vertex was A and the destination vertex was E, your program should output the following: Ford’s algorithm was selected Shortest path is: A, B, D, E Length (weight) of this path is: 11 Deliverables: (1) Source code file on a floppy disk with the following information: Your name, COP 3503H, Assignment title, and Date. (2) The write-up for this assignment described in other parts of this document. (3) Place hard copies of (1) and (2) along with your disk in a large envelope, so that you do not need to fold the printouts or your report. CLEARLY, label the envelope with the following information: your name, COP 3503H, Assignment title, and the date. Write-up: A complete write-up is one of the deliverables for this assignment. A separate document (see the course web-site) describes the make-up of this write-up. In this write-up there will be no order analysis as we have done in the past. This time you will need to describe the approach you took to implement this assignment. Describe any difficulties that you encountered. If you had to do the program again, what would you change, if anything, about your implementation? Page 2

D

C

E