資源簡介
NSGA2算法實現 Python
代碼片段和文件信息
#?Program?Name:?NSGA-II.py
#?Description:?This?is?a?python?implementation?of?Prof.?Kalyanmoy?Deb‘s?popular?NSGA-II?algorithm
#?Author:?Haris?Ali?Khan?
#?Supervisor:?Prof.?Manoj?Kumar?Tiwari
#Importing?required?modules
import?math
import?random
import?matplotlib.pyplot?as?plt
#First?function?to?optimize
def?function1(x):
????value?=?-x**2
????return?value
#Second?function?to?optimize
def?function2(x):
????value?=?-(x-2)**2
????return?value
#Function?to?find?index?of?list
def?index_of(alist):
????for?i?in?range(0len(list)):
????????if?list[i]?==?a:
????????????return?i
????return?-1
#Function?to?sort?by?values
def?sort_by_values(list1?values):
????sorted_list?=?[]
????while(len(sorted_list)!=len(list1)):
????????if?index_of(min(values)values)?in?list1:
????????????sorted_list.append(index_of(min(values)values))
????????values[index_of(min(values)values)]?=?math.inf
????return?sorted_list
#Function?to?carry?out?NSGA-II‘s?fast?non?dominated?s
- 上一篇:Python主成分分析
- 下一篇:百度圖片識別
評論
共有 條評論