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
404 stars 158 forks source link

Some questions hoping for answering #11

Open Hermione-2020 opened 2 years ago

Hermione-2020 commented 2 years ago

Hello Haris, First of all thank you very much for sharing your work! I have some questions regarding the code.

  1. In line 136, the output of non_dominated_sorted_solution2_1 will always be 0,1,2... for every i, so it seems that the code is meaningless. I think what we should do is to align crowding distance and front order, which seems not to appear in the code.

The code below is the original code which seems not to achieve the target aligning crowding distance and front order.

for i in range(0,len(non_dominated_sorted_solution2)):
non_dominated_sorted_solution2_1 = [index_of(non_dominated_sorted_solution2[i][j], non_dominated_sorted_solution2[i] ) for j in range(0,len(non_dominated_sorted_solution2[i]))]
  1. In line 22, the definition of index_of(a,list) is not rigorous. If there are two same values which equal to a in the list, the function only outputs the first position. Thus, using the list.index(a) perhaps is a better choice.
    def index_of(a,list):
    for i in range(0,len(list)):
        if list[i] == a:
            return i
    return -1
  2. The operations of mutation and crossover are strange, because it seems the parent is not correlated with children at all. From the code, we can see no matter which the selected individuals a, b are, the crossover will give a new random solution.
    
    def crossover(a,b):
    r=random.random()
    if r>0.5:
        return mutation((a+b)/2)
    else:
        return mutation((a-b)/2)

def mutation(solution): mutation_prob = random.random() if mutation_prob <1: solution = min_x+(max_x-min_x)*random.random() return solution


4. The crowding distance was also miscalculated and should have been calculated for each target and then added up, which has mentioned by other many times.
Aaron2Woo commented 9 months ago

great job, maybe you can adjust this code and share it with your page