NSGAii代码分析

来源:互联网 发布:臣妾做不到网络歌曲 编辑:程序博客网 时间:2024/05/22 05:19

1. 算法简介

NSGA2(带精英策略的非支配排序的遗传算法)是对NSGA(非支配排序遗传算法)的改进,都是基于遗传算法的多目标优化算法。论文A Fast and Elitist Multiobjective Genetic Algorithm: NSGA-II在这里不进行解读。

2. 文件目录

Kalyanmoy Deb

3. 代码解读

3.1 nsga2.c

/* This is a Multi-Objective GA program.***********************************************************************  This program is the implementation of the NSGA-2 proposed by      **                                                                    **  Prof. Kalyanmoy Deb and his students .                            **                                                                    **  copyright Kalyanmoy Deb**********************************************************************

1、这是一个多目标GA程序,是对Kalyanmoy Deb提出的NSGA2算法的实现,版权归Kalyanmoy Deb所有。

18.08.2003: The keepaliven.h file is modified to have normalized            crowding distance calculation. The previous version of             the code did not have this feature. This way, maintaining            a good distribution of solutions in problems having quite            a different range of objective functions were difficult.            Hopefully, with this modification, such difficulties will            not appear. --  K. Deb18.08.2003: Also the dfit.h file is deleted. It was not needed any way.

2、keepaliven.h文件为了加入标准化的拥挤距离计算而有所改变。原来的版本没有标准化。如果没有标准化,在问题的多个目标函数值值域相差较大时保持解的良好的分布就很困难。改进后这样的困难就被克服了。dfit.h文件被删除了,因为不再需要这个文件了。

The user have to give the input manualy or through a data file.he user have to give the input manualy or through a data file.The user needs to enter objective functions in func-con.hThe code can also take care of the constraints. Enter the constraintsin the space provided in the func-con.h file.Constraints must be of the following type:g(x) >= 0.0Also normalize all constraints (see the example problem in func-con.h)If your program asks you to increase the values of some parameters in theprogram come to main program and accordingly changed the values which aredefined against #define ...

3、使用者需要手动或通过文件给出输入,需要在func-con.h中添入目标函数。代码可以处理约束,在func-con.h中添入约束。约束必须符合g(x) >= 0.0的形式。也要标准化所有约束,参考在func-con.h中的例子(没看懂)。如果程序让你增加某些参数值,找到主程序,根据情况改变在define中定义的值。

The program generates few output files. These are described as1.output.out*           This file has the detailed record for all the variables,*           the fitness values, constraint values, overall constraint            violation (penalty)  and their ranks for all the members*           of old population in the left hand side of the |**|*           and of new population in the right hand side.

4、这个程序产生几个输出文件,他们具体是:

output.out:这个文件记录了所有变量、适应性函数值、约束值、总体约束违背值(惩罚项)以及他们在所有旧群体和新群体中的rank

2.all_fitness.out*         This file prints the record of all the fitness values for*         different individual of new popultion created at all*         generations.3.g_rank_record.out*        This file maintains the record of individuals in global pop-*        -ulation at different ranks for all the generations.4.ranks.out*         This file prints the number of individual at different ranks*          in old and new population and finds rank ratios

5、all_fitness.out:这个文件记录了所有代所有新群体的所有适应性函数值。
g_rank_record.out:这个文件记录了所有代的群体中的个体和rank值。
ranks.out:这个文件记录新旧群体中不同rank的个体的数目并且找到rank比率(不懂)

5.final_fitness.out*                 This file has the fitness value of all feasible and                  non-dominated individuals at the final generation6.final_var.out*                 This file has the all the variables of the feasible                  and non-dominated individuals at the final generation.                  The i-th solutions here corresponds to the i-th solution                  in the final_fitness.out file. 7.plot.out        This file contains gnuplot-based file for plotting                  the non-dominated feasible solutions obtained by the code.

6、final_fitness.out:这个文件包含最后一代可行并且non-dominated个体的适应性函数值。
final_var.out:这个文件记录最后一代可行并且non-dominated的个体的值。这里第i个解对应final_fitness.out文件中第i组适应性函数值。
plot.out :这个文件包含基于gnuplot的文件,为了标绘代码运行得到的non-dominated并且可行的解。

*         This is recommended to delete or rename all the *.out files*         obtained from the previous runs as some files are opened in*         append mode so they give false resemblence of data if the*         user is not carefulCompilation procedure:  gcc nsga2.c -lmRun ./a.out with or without an input fileInput data files: Three files are included, but at one time one is neededdepending on the type of variables used:inp-r (template file input-real)  : All variables are real-codedinp-b (template file input-binary): All variables are binary-codedinp-rb(template file input-rl+bin): Some variables are real and some are binary  */