Topological Sort ( Due 07 May 2017 )

In this assignment you will be creating a graph from an input gif file called dag.gif. You will complete the topo.txt file.

The first line in that file will be a single integer v. This number will denote the number of vertices to follow. The next v lines will be the labels for the vertices in alphabetical order. There will be one label to a line. The labels are unique. The next line after the labels for vertices will be a single number e. This number will denote the number of edges to follow. There will be one edge per line. Each edge will be of the form - fromVertex and toVertex. Assign a default weight of 1 to each edge.

Here is the outline of the code that we developed in class that you will be modifying. You will use topo.txt instead of graph.txt as your input file. You can add an Edge class if you want to. You may use any of the functions that you wrote for the GraphTraversal class in your last assignment. You can add more functions as needed. You will first test if the given Graph does not contain a cycle and then do a topological sort on that Graph. For your output, the vertices on a given level must be printed in alphabetical order.

def Graph (object):
  # determine if a directed graph has a cycle
  def hasCycle (self):

  # return a list of vertices after a topological sort
  def toposort (self):

def main():
  # test if a directed graph has a cycle

  # test topological sort

main()

For this assignment you may work with a partner. Both of you must read the paper on Pair Programming. .

The file that you will be uploading will be called TopoSort.py. We are looking for clean and structured design. The file will have a header of the following form:

#  File: TopoSort.py

#  Description:

#  Student Name:

#  Student UT EID:

#  Partner Name:

#  Partner UT EID:

#  Course Name: CS 313E

#  Unique Number: 

#  Date Created:

#  Date Last Modified:

If you are working with a partner both of you will be submitting a single program (from either account) but make sure that you have your partner's name and eid in your program. If you are working alone, then remove the two lines that has the partner's name and eid in the header.

Use the Canvas system to submit your TopoSort.py file. We should receive your work by 11 PM on Sunday, 07 May 2017. There is no extension to this deadline. There will be substantial penalties if you do not adhere to the guidelines. Remember Python is case sensitive. The name of your file must match exactly what we have specified.