標籤:cut 開啟 ted 遺傳演算法 語言 fprintf div flush 編碼
NSGA(非支配排序遺傳演算法)、NSGA-II(帶精英策略的快速非支配排序遺傳演算法),都是基於遺傳演算法的多目標最佳化演算法,是基於pareto最優解討論的多目標最佳化。
在官網:
http://www.iitk.ac.in/kangal/codes.shtml
可以下載到 NSGA-II 的C語言版源碼,下載最新版後開啟如下:
其中,nsga2r.c 為主檔案,開啟後找到核心代碼,如下:
1 for (i=2; i<=ngen; i++) 2 { 3 selection (parent_pop, child_pop); 4 mutation_pop (child_pop); 5 decode_pop(child_pop); 6 evaluate_pop(child_pop); 7 merge (parent_pop, child_pop, mixed_pop); 8 fill_nondominated_sort (mixed_pop, parent_pop); 9 /* Comment following three lines if information for all10 generations is not desired, it will speed up the execution */11 fprintf(fpt4,"# gen = %d\n",i);12 report_pop(parent_pop,fpt4);13 fflush(fpt4);14 printf("\n gen = %d",i);15 fflush(stdout);16 }
由第1行代碼可知,初始化產生代碼為第一代,其後的操作為第 2 代到設定的迭代次數 ngen
由第3行代碼可知,selection 函數 (二元錦標賽選擇,SBX交叉)等功能的實現封裝在一起。
由第4行代碼可知, mutation_pop 函數 對新種群( child_pop ) 進行變異操作。
由第5行代碼可知,decode_pop 函數 為對二進位編碼的遺傳個體進行解碼操作。
由第6行代碼可知,evaluate_pop 函數 是對新種群( child_pop ) 進行多目標函數值的計算。
由第7行代碼可知,merge 函數 將 父種群 和 子種群 合并成臨時種群(mixed_pop)。
由第8行代碼可知,fill_nondominated_sort 對臨時種群(mixed_pop) 非支配排序,擁擠距離判斷。
由第12行代碼可知, report_pop 對 父種群(parent_pop)中的個體的多目標函數值,支配層,擁擠距離,個體編碼進行列印。
多目標遺傳演算法 ------ NSGA-II (部分源碼解析)介紹