
CS 302 Assignment 7:
Due date: Friday, November 30, 2018, midnight.
Implementating Dijkstra's Algorithm
-
Write a program which implements Dijkstra's algorithm for the
single source minimum path problem on a weighted directed graph
with no negative weights.
-
-
Here is the suggested outline of your program.
Read a weighted directed graph from your directory.
Copy a small graph to get started.
-
The first line of the file is an integer giving n, the number of vertices
of the graph. The vertices of the graph will be named 0 ... n-1.
The source vertexi is 0.
-
You will need an array to hold the vertices.
-
Each of the remaining lines encodes one arc.
-
The line "i j w" encodes an arc (i,j) of weight w.
-
All weights will be non-negative integers.
Store the edges a an array of outneighbor lists. I suggest using linked
The outneighborlist for node i consists of nodes each of which must
have at least two integer, the name of the neighbor and the weight of
the arc.
-
Implement an updatable min-queue. The items on that queue are vertices
which are partially processed.
-
In the array of vertices, each vertex must store its id, an integer
between 0 and n-1, its distance to the source vertex, and its back pointer,
as well as the linked list of its outneighbors.
-
Initially, the queue contains exactly the source vertex.
-
At each step:
-
Delete the item of minimum distance in the queue. Call that i; i is now
finished.
-
For each outneighbor j of i, there are four possibilities.
j is fully processed: do nothing.
j is partially processed and no shorter path from 0 to j is found:
Do nothing.
j is partially processed and there is a shorter path from 0 to j which
is through i: Update the value of dist, set the value of back to i.
j is unprocessed: Insert j into the queue and assign its distance, and
let back be i.
-
Write the shortest path from 0 to i for each vertex i.
Your program must be written in C++ and must run on bobby.cs.unlv.edu.
My output files for the two smaller graphs show every step of the algorithm.
But if I do the same thing for the larger graph, the output has 1040187 lines.
You don't want to do that. The assignment does not require printing out every
step, although it's a useful debugging tool.
Write C++