File tree Expand file tree Collapse file tree 1 file changed +5
-5
lines changed Expand file tree Collapse file tree 1 file changed +5
-5
lines changed Original file line number Diff line number Diff line change @@ -79,20 +79,20 @@ def crowding_distance(front):
7979 obj_sorted = sorted (obj , key = lambda x : x [1 ])
8080
8181 # Get the minimum and maximum values for the current objective.
82- obj_min_val = obj_sorted [ 0 ][ 1 ]
83- obj_max_val = obj_sorted [ - 1 ][ 1 ]
82+ obj_min_val = min ( population [:, obj_idx ])
83+ obj_max_val = max ( population [:, obj_idx ])
8484 denominator = obj_max_val - obj_min_val
8585 # To avoid division by zero, set the denominator to a tiny value.
8686 if denominator == 0 :
8787 denominator = 0.0000001
88-
88+
8989 # Set the crowding distance to the first and last solutions (after being sorted) to infinity.
90- inf_val = 999999999
90+ inf_val = float ( 'inf' )
9191 # crowding_distance[0] = inf_val
9292 obj_sorted [0 ][2 ] = inf_val
9393 # crowding_distance[-1] = inf_val
9494 obj_sorted [- 1 ][2 ] = inf_val
95-
95+
9696 # If there are only 2 solutions in the current front, then do not proceed.
9797 # The crowding distance for such 2 solutions is infinity.
9898 if len (obj_sorted ) <= 2 :
You can’t perform that action at this time.
0 commit comments