class graph (object) : def __init__(self, n) : """constructor for the graph class. takes a single parameter which is the number of nodes in the graph """ # set the number of nodes self.n = n # the number of edges self.m = 0 # the adjacency matrix self.matrix = [ [0 for i in range(n)] for i in range(n) ] # a dictionary that maps node ids to their indices self.node_id_map = {} def __len__(self) : return self.n def num_paths(self, node1, node2, k) : """ returns the number of paths of length AT MOST k between node1 and node2 node1 and node2 are the names of the two nodes as they appear in the input file that contains the graph """ pass def load_dot(file_name) : file_handle = open(file_name, 'U') file_handle.readline() n = 0 # the number of nodes # first you need to process the dot file to determine # the number of nodes in the graph g = graph(n) file_handle.seek(0) # go back to the beginning of the file file_handle.readline() for line in file_handle : pass # process each edge return g if __name__ == '__main__' : g = load_dot('test.dot') print g.num_paths('a', 'b', 2)