def const_crowding_distance(individuals, fitnesses):
    """ Crowding distance-measure for multiple objectives. """
    distances = collections.defaultdict(lambda: 0)
    individuals = list(individuals)
    # Infer the number of objectives by looking at the fitness of the first.
    n_obj = len(fitnesses[individuals[0]][0])
    
    for i in range(n_obj):
        individuals.sort(key=lambda x: fitnesses[x][0][i])
        # normalization between 0 and 1.
        normalization = float(fitnesses[individuals[0]][0][i] - fitnesses[individuals[-1]][0][i])
        # Make sure the boundary points are always selected.
        distances[individuals[0]] = 1e100
        distances[individuals[-1]] = 1e100
        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
dataset/ETHPy150Open pybrain/pybrain/pybrain/tools/nondominated.py/const_crowding_distance/original