def load_map(mapFilename): """ Parses the map file and constructs a directed graph Parameters: mapFilename : name of the map file Assumes: Each entry in the map file consists of the following four positive integers, separated by a blank space: From To TotalDistance DistanceOutdoors e.g. 32 76 54 23 This entry would become an edge from 32 to 76. Returns: a directed graph representing the map """ # TODO print "Loading map from file..." result = WeightedDigraph() with open(mapFilename, 'r') as inFile: for line in inFile.readlines(): print 'line:', line s, toNode, totalDist, distOut = line.split() fromNode = int(s) #print 'type', type(fromNode) node1 = W_Node(int(fromNode)) node2 = W_Node(int(toNode)) weightedEdge = WeightedEdge(node1, node2, int(totalDist), int(distOut)) print 'weightedEdge', weightedEdge if node1 not in result.nodes: result.addNode(node1) if node2 not in result.nodes: result.addNode(node2) result.addWeightedEdge(weightedEdge) print result