多目标遗传算法代码
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
.
% function nsga_2(pro)
%% Main Function
% Main program to run the NSGA-II MOEA.
% Read the corresponding documentation to learn more about multiobjective % optimization using evolutionary algorithms.
% initialize_variables has two arguments; First being the population size % and the second the problem number. '1' corresponds to MOP1 and '2' % corresponds to MOP2.
%inp_para_definition=input_parameters_definition;
%% Initialize the variables
% Declare the variables and initialize their values
% pop - population
% gen - generations
% pro - problem number
%clear;clc;tic;
pop = 100; % 每一代的种群数
gen = 100; % 总共的代数
pro = 2; % 问题选择1或者2,见switch
switch pro
case 1
% M is the number of objectives.
M = 2;
% V is the number of decision variables. In this case it is
% difficult to visualize the decision variables space while the % objective space is just two dimensional.
V = 6;
case 2
M = 3;
V = 12;
case 3 % case 1和case 2 用来对整个算法进行常规验证,作为调试之用;case 3
为本工程所需;
M = 2; %(output parameters 个数)
V = 8; %(input parameters 个数)
K = 10;
end
% Initialize the population
chromosome = initialize_variables(pop,pro);
%% Sort the initialized population
% Sort the population using non-domination-sort. This returns two columns % for each individual which are the rank and the crowding distance
% corresponding to their position in the front they belong. 真是牛 X了。chromosome = non_domination_sort_mod(chromosome,pro);
%% Start the evolution process
.
.
% The following are performed in each generation
% Select the parents
% Perfrom crossover and Mutation operator
% Perform Selection
for i = 1 : gen
% Select the parents
% Parents are selected for reproduction to generate offspring. The % original NSGA-II uses a binary tournament selection based on the % crowded-comparision operator. The arguments are
% pool - size of the mating pool. It is common to have this to be half the
% population size.
% tour - Tournament size. Original NSGA-II uses a binary tournament % selection, but to see the effect of tournament size this is kept
% arbitary, to be choosen by the user.
pool = round(pop/2);
tour = 2;
%下面进行二人锦标赛配对,新的群体规模是原来群体的一半
parent_chromosome = tournament_selection(chromosome,pool,tour);
% Perfrom crossover and Mutation operator
% The original NSGA-II algorithm uses Simulated Binary Crossover (SBX) and
% Polynomial crossover. Crossover probability pc = 0.9 and mutation % probability is pm = 1/n, where n is the number of decision variables. % Both real-coded GA and binary-coded GA are implemented in the original % algorithm, while in this program only the real-coded GA is considered. % The distribution indeices for crossover and mutation operators as mu = 20
% and mum = 20 respectively.
mu = 20;
mum = 20;
% 针对对象是上一步产生的新的个体parent_chromosome
%对parent_chromosome 每次操作以较大的概率进行交叉(产生两个新的候选人),或
者较小的概率变异(一个新的候选人)操作,这样
%就会产生较多的新个体
offspring_chromosome =
genetic_operator(parent_chromosome,pro,mu,mum);