def const_crowding_distance(individuals, fitnesses):
 distances = collections.defaultdict((lambda : 0))
 individuals = list(individuals)
 n_obj = len(fitnesses[individuals[0]][0])
 for i in range(n_obj):
  individuals.sort(key=(lambda x: fitnesses[x][0][i]))
  normalization = float((fitnesses[individuals[0]][0][i] - fitnesses[individuals[(-1)]][0][i]))
  distances[individuals[0]] = 1e+100
  distances[individuals[(-1)]] = 1e+100
  tripled = list(zip(individuals, individuals[1:(-1)], individuals[2:]))
  for (pre, ind, post) in tripled:
   distances[ind] += ((fitnesses[pre][0][i] - fitnesses[post][0][i]) / normalization)
 return distances

def const_crowding_distance ( individuals , fitnesses ) : distances = collections . defaultdict ( ( lambda : 0 ) ) individuals = list ( individuals ) n_obj = len ( fitnesses [ individuals [ 0 ] ] [ 0 ] ) for i in range ( n_obj ) : individuals . sort ( key = ( lambda x : fitnesses [ x ] [ 0 ] [ i ] ) ) normalization = float ( ( fitnesses [ individuals [ 0 ] ] [ 0 ] [ i ] - fitnesses [ individuals [ ( - 1 ) ] ] [ 0 ] [ i ] ) ) distances [ individuals [ 0 ] ] = 1e+100 distances [ individuals [ ( - 1 ) ] ] = 1e+100 tripled = list ( zip ( individuals , individuals [ 1 : ( - 1 ) ] , individuals [ 2 : ] ) ) for ( pre , ind , post ) in tripled : distances [ ind ] += ( ( fitnesses [ pre ] [ 0 ] [ i ] - fitnesses [ post ] [ 0 ] [ i ] ) / normalization ) return distances
crowding distance-measure for multiple objectives .