Skip to content

Conversation

@danyoungday
Copy link
Contributor

Cleaned up the fast_non_dominated_sort function and added a unit test to test it.

@danyoungday danyoungday self-assigned this Mar 10, 2025
S = [[] for _ in range(population_size)] # Set of solutions dominated by p
n = [0 for _ in range(population_size)] # Number of solutions dominating p
front = [[]] # Final Pareto fronts
rank = [0 for _ in range(population_size)] # Rank of solution
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better documentation

# If p dominates q
if dominates(population[p], population[q]):
if q not in S[p]:
S[p].append(q)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wasn't needed since we don't have duplicates in the population. Not sure why it was here in the first place


# With this implementation the final front will be empty
del front[len(front)-1]
front.pop()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a nicer way to do this I think

if obj_max != obj_min:
for i in range(1, len(sorted_front) - 1):
dist = sorted_front[i+1].metrics[m] - sorted_front[i-1].metrics[m]
# Normalize distance by objective range
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More documentation for the distance function

true_ranks = [1, 1, 1, 2, 3, 3, 3, 4, 4, 4]
obj1 = [0.15, 0.05, 0.02, 0.18, 0.83, 0.30, 0.43, 0.37, 0.73, 0.60]
obj2 = [0.15, 0.86, 0.96, 0.18, 0.21, 0.52, 0.29, 0.95, 0.59, 0.70]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Values generated by ChatGPT, hand-verified to be correct.

@danyoungday danyoungday merged commit 8c0bdb6 into main Mar 10, 2025
1 check passed
@danyoungday danyoungday deleted the nsga-refactor branch March 10, 2025 23:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants