def calBest(self): # 计算全局最优解 N = 10000 # 设置所要生成的全局最优解的个数 Point, num = ea.crtup(self.M, N) # 生成N个在各目标的单位维度上均匀分布的参考点 M = self.M c = np.ones((num, M)) for i in range(num): for j in range(1, M): temp = Point[i, j] / Point[i, 0] * np.prod(1 - c[i, M - j:M - 1]) c[i, M - j - 1] = (temp**2 - temp + np.sqrt(2 * temp)) / (temp**2 + 1) x = np.arccos(c) * 2 / np.pi temp = (1 - np.sin( np.pi / 2 * x[:, [1]])) * Point[:, [M - 1]] / Point[:, [M - 2]] a = np.linspace(0, 1, 10000 + 1) for i in range(num): E = np.abs(temp[i] * (1 - np.cos(np.pi / 2 * a)) - 1 + a * np.cos(5 * np.pi * a)**2) rank = np.argsort(E, kind='mergesort') x[i, 0] = a[np.min(rank[0:10])] Point = convex(x) Point[:, [M - 1]] = disc(x) [levels, criLevel] = ea.ndsortESS(Point, None, 1) # 非支配分层,只分出第一层即可 Point = Point[np.where(levels == 1)[0], :] # 只保留点集中的非支配点 globalBestObjV = np.tile(np.array([list(range(2, 2 * self.M + 1, 2))]), (Point.shape[0], 1)) * Point return globalBestObjV
def calReferObjV(self): # 设定目标数参考值(本问题目标函数参考值设定为理论最优值,即“真实帕累托前沿点”) N = 10000 # 生成10000个参考点 ObjV1 = np.linspace(0, 1, N) ObjV2 = 1 - ObjV1**0.5 - ObjV1 * np.sin(10*np.pi * ObjV1) f = np.array([ObjV1, ObjV2]).T levels, criLevel = ea.ndsortESS(f, None, 1) referenceObjV = f[np.where(levels == 1)[0]] return referenceObjV
def calBest(self): N = 10000 # 生成10000个参考点 ObjV1 = np.linspace(0, 1, N) ObjV2 = 1 - ObjV1**0.5 - ObjV1 * np.sin(10 * np.pi * ObjV1) realBestObjV = np.array([ObjV1, ObjV2]).T levels, criLevel = ea.ndsortESS(realBestObjV, None, 1) realBestObjV = realBestObjV[np.where(levels == 1)[0]] return realBestObjV
def calBest(self): # 计算全局最优解 N = 10000 # 生成10000个参考点 ObjV1 = np.linspace(0, 1, N) ObjV2 = 1 - ObjV1**0.5 - ObjV1 * np.sin(10 * np.pi * ObjV1) f = np.array([ObjV1, ObjV2]).T levels, criLevel = ea.ndsortESS(f, None, 1) globalBestObjV = f[np.where(levels == 1)[0]] return globalBestObjV