ImageVerifierCode 换一换
格式:DOCX , 页数:17 ,大小:19.53KB ,
资源ID:5171416      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/5171416.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(NSGAII源程序.docx)为本站会员(b****5)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

NSGAII源程序.docx

1、NSGAII源程序function f = crowding_distance(x,problem)% This function calculates the crowding distanceN,M = size(x);switch problem case 1 M = 2; V = 6; case 2 M = 3; V = 12;end% Crowding distance for each frontfor i = 1 : length(F(front).f) y(i,:) = x(F(front).f(i),:);endfor i = 1 : M sorted(i).individu

2、al,sorted(i).index = sort(y(:,V + i); distance(sorted(i).index(1).individual = Inf; distance(sorted(i).index(length(sorted(i).index).individual = Inf;endnum,len = size(y);% Initialize all the distance of individuals as zero.for i = 1 : M for j = 2 : num - 1 distance(j).individual = 0; end objective(

3、i).range = . sorted(i).individual(length(sorted(i).individual) - . sorted(i).individual(1); % Maximum and minimum objectives value for the ith objectiveend% Caluclate the crowding distance for front one.for i = 1 : M for j = 2 : num - 1 distance(j).individual = distance(j).individual + . (sorted(i).

4、individual(j + 1) - sorted(i).individual(j - 1)/. objective(i).range; y(sorted(i).index(j),M + V + 2) = distance(j).individual; endend/PRE Published with MATLAB 7.0function f = genetic_operator(parent_chromosome,pro,mu,mum);% This function is utilized to produce offsprings from parent chromosomes.%

5、The genetic operators corssover and mutation which are carried out with% slight modifications from the original design. For more information read% the document enclosed.N,M = size(parent_chromosome);switch pro case 1 M = 2; V = 6; case 2 M = 3; V = 12;endp = 1;was_crossover = 0;was_mutation = 0;l_li

6、mit = 0;u_limit = 1;for i = 1 : N if rand(1) 0.9 child_1 = ; child_2 = ; parent_1 = round(N*rand(1); if parent_1 1 parent_1 = 1; end parent_2 = round(N*rand(1); if parent_2 1 parent_2 = 1; end while isequal(parent_chromosome(parent_1,:),parent_chromosome(parent_2,:) parent_2 = round(N*rand(1); if pa

7、rent_2 1 parent_2 = 1; end end parent_1 = parent_chromosome(parent_1,:); parent_2 = parent_chromosome(parent_2,:); for j = 1 : V % SBX (Simulated Binary Crossover) % Generate a random number u(j) = rand(1); if u(j) u_limit child_1(j) = u_limit; elseif child_1(j) u_limit child_2(j) = u_limit; elseif

8、child_2(j) l_limit child_2(j) = l_limit; end end child_1(:,V + 1: M + V) = evaluate_objective(child_1,pro); child_2(:,V + 1: M + V) = evaluate_objective(child_2,pro); was_crossover = 1; was_mutation = 0; else parent_3 = round(N*rand(1); if parent_3 1 parent_3 = 1; end % Make sure that the mutation d

9、oes not result in variables out of % the search space. For both the MOPs the range for decision space % is 0,1. In case different variables have different decision % space each variable can be assigned a range. child_3 = parent_chromosome(parent_3,:); for j = 1 : V r(j) = rand(1); if r(j) u_limit ch

10、ild_3(j) = u_limit; elseif child_3(j) l_limit child_3(j) = l_limit; end end child_3(:,V + 1: M + V) = evaluate_objective(child_3,pro); was_mutation = 1; was_crossover = 0; end if was_crossover child(p,:) = child_1; child(p+1,:) = child_2; was_cossover = 0; p = p + 2; elseif was_mutation child(p,:) =

11、 child_3(1,1 : M + V); was_mutation = 0; p = p + 1; endendf = child;Published with MATLAB 7.0function f = initialize_variables(N,problem)% function f = initialize_variables(N,problem)% N - Population size% problem - takes integer values 1 and 2 where,% 1 for MOP1% 2 for MOP2% This function initializ

12、es the population with N individuals and each% individual having M decision variables based on the selected problem.% M = 6 for problem MOP1 and M = 12 for problem MOP2. The objective space% for MOP1 is 2 dimensional while for MOP2 is 3 dimensional.% Both the MOPs has 0 to 1 as its range for all the

13、 decision variables.min = 0;max = 1;switch problem case 1 M = 6; K = 8; case 2 M = 12; K = 15;endfor i = 1 : N % Initialize the decision variables for j = 1 : M f(i,j) = rand(1); % i.e f(i,j) = min + (max - min)*rand(1); end % Evaluate the objective function f(i,M + 1: K) = evaluate_objective(f(i,:)

14、,problem);end/PRE Published with MATLAB 7.0 Non-Donimation SortThis function sort the current popultion based on non-domination. All the individuals in the first front are given a rank of 1, the second front individuals are assigned rank 2 and so on. After assigning the rank the crowding in each fro

15、nt is calculated. N,M = size(x);switch problem case 1 M = 2; V = 6; case 2 M = 3; V = 12;endfront = 1;% There is nothing to this assignment, used only to manipulate easily in% MATLAB.F(front).f = ;individual = ;for i = 1 : N % Number of individuals that dominate this individual individual(i).n = 0;

16、% Individuals which this individual dominate individual(i).p = ; for j = 1 : N dom_less = 0; dom_equal = 0; dom_more = 0; for k = 1 : M if (x(i,V + k) x(j,V + k) dom_less = dom_less + 1; elseif (x(i,V + k) = x(j,V + k) dom_equal = dom_equal + 1; else dom_more = dom_more + 1; end end if dom_less = 0

17、& dom_equal = M individual(i).n = individual(i).n + 1; elseif dom_more = 0 & dom_equal = M individual(i).p = individual(i).p j; end end if individual(i).n = 0 x(i,M + V + 1) = 1; F(front).f = F(front).f i; endend% Find the subsequent frontswhile isempty(F(front).f) Q = ; for i = 1 : length(F(front).

18、f) if isempty(individual(F(front).f(i).p) for j = 1 : length(individual(F(front).f(i).p) individual(individual(F(front).f(i).p(j).n = . individual(individual(F(front).f(i).p(j).n - 1; if individual(individual(F(front).f(i).p(j).n = 0 x(individual(F(front).f(i).p(j),M + V + 1) = . front + 1; Q = Q in

19、dividual(F(front).f(i).p(j); end end end end front = front + 1; F(front).f = Q;endtemp,index_of_fronts = sort(x(:,M + V + 1);for i = 1 : length(index_of_fronts) sorted_based_on_front(i,:) = x(index_of_fronts(i),:);endcurrent_index = 0;% Find the crowding distance for each individual in each frontfor

20、 front = 1 : (length(F) - 1) objective = ; distance = 0; y = ; previous_index = current_index + 1; for i = 1 : length(F(front).f) y(i,:) = sorted_based_on_front(current_index + i,:); end current_index = current_index + i; % Sort each individual based on the objective sorted_based_on_objective = ; fo

21、r i = 1 : M sorted_based_on_objective, index_of_objectives = . sort(y(:,V + i); sorted_based_on_objective = ; for j = 1 : length(index_of_objectives) sorted_based_on_objective(j,:) = y(index_of_objectives(j),:); end f_max = . sorted_based_on_objective(length(index_of_objectives), V + i); f_min = sor

22、ted_based_on_objective(1, V + i); y(index_of_objectives(length(index_of_objectives),M + V + 1 + i). = Inf; y(index_of_objectives(1),M + V + 1 + i) = Inf; for j = 2 : length(index_of_objectives) - 1 next_obj = sorted_based_on_objective(j + 1,V + i); previous_obj = sorted_based_on_objective(j - 1,V +

23、i); if (f_max - f_min = 0) y(index_of_objectives(j),M + V + 1 + i) = Inf; else y(index_of_objectives(j),M + V + 1 + i) = . (next_obj - previous_obj)/(f_max - f_min); end end end distance = ; distance(:,1) = zeros(length(F(front).f),1); for i = 1 : M distance(:,1) = distance(:,1) + y(:,M + V + 1 + i)

24、; end y(:,M + V + 2) = distance; y = y(:,1 : M + V + 2); z(previous_index:current_index,:) = y;endf = z();Published with MATLAB 7.0Main FunctionMain program to run the NSGA-II MOEA. Read the corresponding documentation to learn more about multiobjective optimization using evolutionary algorithms. in

25、itialize_variables has two arguments; First being the population size and the second the problem number. 1 corresponds to MOP1 and 2 corresponds to MOP2. ContentsInitialize the variables Sort the initialized population Start the evolution process Result Visualize Initialize the variablesDeclare the

26、variables and initialize their values pop - population gen - generations pro - problem numberpop = 200;gen = 1;pro = 1;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

27、 % objective space is just two dimensional. V = 6; case 2 M = 3; V = 12;end% Initialize the populationchromosome = initialize_variables(pop,pro);Sort the initialized populationSort the population using non-domination-sort. This returns two columns for each individual which are the rank and the crowd

28、ing distance corresponding to their position in the front they belong. 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 Selectionfor i = 1 : gen % Sel

29、ect 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 siz

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1