test.py
import numpy as np
import matplotlib.pyplot as plt
class Utils:
@staticmethod
def is_dominate(obj_a, obj_b, num_obj, ):
if type(obj_a) is not np.ndarray:
obj_a, obj_b = np.array(obj_a), np.array(obj_b)
res = np.array([np.sign(k) for k in obj_a - obj_b])
res_ngt0, res_eqf1 = np.argwhere(res <= 0), np.argwhere(res == -1)
if res_ngt0.shape[0] == num_obj and res_eqf1.shape[0] > 0:
return True
return False
class Pareto:
def __init__(self, pop_size, pop_obj, ):
self.pop_size = pop_size
self.pop_obj = pop_obj
self.num_obj = pop_obj.shape[1]
self.f = []
self.sp = [[] for _ in range(pop_size)]
self.np = np.zeros([pop_size, 1], dtype=int)
self.rank = np.zeros([pop_size, 1], dtype=int)
self.cd = np.zeros([pop_size, 1])
def __index(self, i, ):
return np.delete(range(self.pop_size), i)
def __is_dominate(self, i, j, ):
return Utils.is_dominate(self.pop_obj[i], self.pop_obj[j], self.num_obj)
def __f1_dominate(self, )