haris989 / NSGA-II

This is a python implementation of NSGA-II algorithm. NSGA is a popular non-domination based genetic algorithm for multi-objective optimization. It is a very effective algorithm but has been generally criticized for its computational complexity, lack of elitism and for choosing the optimal parameter value for sharing parameter σshare. A modified version, NSGA II was developed, which has a better sorting algorithm , incorporates elitism and no sharing parameter needs to be chosen a priori.
MIT License
380 stars 158 forks source link

Crowding Distance #7

Open ayushmankd opened 4 years ago

ayushmankd commented 4 years ago

There is an error in Crowding Distance function. It should be values1[i-1] - values1[i+i] and values2[i-1] - values2[i+1]

Arexh commented 3 years ago

I agree.

XuhuaYY commented 2 years ago

I think it's not just this error sorted1 = sort_by_values(front, values1[:]) sorted2 = sort_by_values(front, values2[:]) the obtained two ordinal lists must be opposite, because front is a non-dominated solution, then their distance calculations have been misplaced, and should be changed to:


def crowding_distance(values1, values2, front):
distance = [0 for i in range(0,len(front))]
sorted1 = sort_by_values(front, values1[:])
# sorted2 = sort_by_values(front, values2[:])
distance[0] = 4444444444444444
distance[len(front) - 1] = 4444444444444444
for k in range(1,len(front)-1):
distance[k] = abs(values1[sorted1[k+1]] - values1[sorted1[k-1]])/(max(values1)-min(values1))
distance[k] = distance[k]+ abs(values2[sorted1[k+1]] - values2[sorted1[k-1]])/(max(values2)-min(values2))
return distance