forked from Lianghao93/NSGA-II
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnd_sort.py
35 lines (32 loc) · 1.11 KB
/
nd_sort.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env python
# encoding: utf-8
import numpy as np
def nd_sort(pop_obj, n_sort):
"""
:rtype:
:param n_sort:
:param pop_obj: objective vectors
:return: [FrontNo, MaxFNo]
"""
n, m_obj = np.shape(pop_obj)
a, loc = np.unique(pop_obj[:, 0], return_inverse=True)
index = pop_obj[:, 0].argsort()
new_obj = pop_obj[index, :]
front_no = np.inf * np.ones(n)
max_front = 0
while np.sum(front_no < np.inf) < min(n_sort, len(loc)):
max_front += 1
for i in range(n):
if front_no[i] == np.inf:
dominated = False
for j in range(i, 0, -1):
if front_no[j - 1] == max_front:
m = 2
while (m <= m_obj) and (new_obj[i, m - 1] >= new_obj[j - 1, m - 1]):
m += 1
dominated = m > m_obj
if dominated or (m_obj == 2):
break
if not dominated:
front_no[i] = max_front
return front_no[loc], max_front