def optimize(self, graph):
for center in self.centers:<EOL><INDENT>shortest_routes = shortest_path(graph, center)[<NUM_LIT:1>]<EOL>for node, weight in list(shortest_routes.items()):<EOL><INDENT>self.nodes.setdefault(node, []).append(weight)<EOL><DEDENT><DEDENT>
Build a dictionary mapping each pair of nodes to a number (the distance between them).

@type  graph: graph
@param graph: Graph.