code: def optimize(self, graph):
          
          for start in graph.nodes():
              for end in graph.nodes():
                  for each in graph.node_attributes(start):
                      if (each[0] == 'position'):
                          start_attr = each[1]
                          break
                  for each in graph.node_attributes(end):
                      if (each[0] == 'position'):
                          end_attr = each[1]
                          break
                  dist = 0
                  for i in range(len(start_attr)):
                      dist = dist + (float(start_attr[i]) - float(end_attr[i]))**2
                  self.distances[(start,end)] = dist
docs: Build a dictionary mapping each pair of nodes to a number (the distance between them).
          
          @type  graph: graph
          @param graph: Graph.