def findDiameter(): diameter = 0 for node in g.nodes: length = search(node, {}, {}) if(length > diameter): diameter = length return diameter def search(source, colors, dist): length = 0 for xy in g.nodes: colors[xy.name] = "white" dist[xy.name] = 0 list = [] list += [source] colors[source.name] = "grey" while(len(list) > 0): node = list[len(list)-1] del list[len(list)-1] for nodeTwo in node.getNeighbors(): if(colors[nodeTwo.name] == "white"): colors[nodeTwo.name] = "grey" dist[nodeTwo.name] = dist[node.name] + 1 list += [nodeTwo] colors[node] = "black" for xy in g.nodes: if(dist[xy.name] > length): length = dist[xy.name] return length