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

加入VIP,免费下载
 

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

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

下载须知

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

版权提示 | 免责声明

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

多目标遗传算法代码.docx

1、多目标遗传算法代码. % 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

2、 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; % 每一代的种群数

3、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;

4、 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

5、 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 pa

6、rents % 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 - si

7、ze 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; %下面进行二人锦标赛配对

8、,新的群体规模是原来群体的一半 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

9、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

10、 = 20; % 针对对象是上一步产生的新的个体parent_chromosome %对parent_chromosome 每次操作以较大的概率进行交叉(产生两个新的候选人),或者较小的概率变异(一个新的候选人)操作,这样 %就会产生较多的新个体 offspring_chromosome = genetic_operator(parent_chromosome,pro,mu,mum); % Intermediate population % Intermediate population is the combined population of parents and % offspring

11、s of the current generation. The population size is almost 1 and % half times the initial population. main_pop,temp=size(chromosome); offspring_pop,temp=size(offspring_chromosome); intermediate_chromosome(1:main_pop,:)=chromosome; . . intermediate_chromosome(main_pop+1:main_pop+offspring_pop,1:M+V)=

12、offspring_chromosome; %intermediate_chromosome=inter_chromo(chromosome,offspring_chromosome,pro); % Non-domination-sort of intermediate population % The intermediate population is sorted again based on non-domination sort % before the replacement operator is performed on the intermediate % populatio

13、n. intermediate_chromosome = . non_domination_sort_mod(intermediate_chromosome,pro); % Perform Selection % Once the intermediate population is sorted only the best solution is % selected based on it rank and crowding distance. Each front is filled in % ascending order until the addition of populatio

14、n size is reached. The % last front is included in the population based on the individuals with % least crowding distance chromosome = replace_chromosome(intermediate_chromosome,pro,pop); if mod(i,10) fprintf(%dn,i); end end % Result % Save the result in ASCII text format. save solution.txt chromoso

15、me -ASCII % Visualize % The following is used to visualize the result for the given problem. switch pro case 1 plot(chromosome(:,V + 1),chromosome(:,V + 2),y+); title(MOP1 using NSGA-II); xlabel(f(x_1); ylabel(f(x_2); case 2 plot3(chromosome(:,V + 1),chromosome(:,V + 2),chromosome(:,V + 3),*); title

16、(MOP2 using NSGA-II); xlabel(f(x_1); ylabel(f(x_2); zlabel(f(x_3); end %disp(run time is:) %toc; % function 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

17、function initializes 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

18、 its range for all the decision variables. min = 0; max = 1; switch problem case 1 M = 6; K = 8; % k=决策变量(M=6)+目标变量(K-M=2)=8 case 2 M = 12; K = 15; case 3 % case 1和case 2 用来对整个算法进行常规验证,作为调试之用;case 3 为本工程所需; M = 8; %(input parameters 个数) K = 10; end for i = 1 : N % Initialize the decision variables f

19、or 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,:),problem); end % function f = evaluate_objective(x,problem) % Function to evaluate the objective functions for the given input vector % x. x has the

20、 decision variables switch problem case 1 f = ; % Objective function one f(1) = 1 - exp(-4*x(1)*(sin(6*pi*x(1)6; sum = 0; . . for i = 2 : 6 sum = sum + x(i)/4; end % Intermediate function g_x = 1 + 9*(sum)(0.25); % Objective function one f(2) = g_x*(1 - (f(1)/(g_x)2); case 2 f = ; % Intermediate fun

21、ction g_x = 0; for i = 3 : 12 g_x = g_x + (x(i) - 0.5)2; end % Objective function one f(1) = (1 + g_x)*cos(0.5*pi*x(1)*cos(0.5*pi*x(2); % Objective function two f(2) = (1 + g_x)*cos(0.5*pi*x(1)*sin(0.5*pi*x(2); % Objective function three f(3) = (1 + g_x)*sin(0.5*pi*x(1); case 3 f = ; % Objective fun

22、ction one f(1) = 0; % Objective function one f(2) = 0; end % % Non-Donimation Sort %按照目标函数最小了好 % This 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 assig

23、ning the rank the % crowding in each front is calculated. function f = non_domination_sort_mod(x,problem) N,M = size(x); switch problem case 1 M = 2; V = 6; case 2 M = 3; V = 12; case 3 % case 1和case 2 用来对整个算法进行常规验证,作为调试之用;case 3 为本工程所需; . . M = 2; %(output parameters 个数) V = 8; %(input parameters 个

24、数) K = 10; end front = 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 支配i的解的个数 individual(i).n = 0; % Individuals which this individual dominate 被i支配的解 individual(

25、i).p = ; for j = 1 : N dom_less = 0; dom_equal = 0; dom_more = 0; for k = 1 : M if (x(i,V + k) return a increasing orer data sequence temp,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),:); % 对解(染色体)进行排序,按照front分层 end %到这里分层结束,下面就是计算距离了 current_index = 0; % Find the crowding distance for each individual in each front % ,计算不同层的拥挤距离是没有意义的 for front = 1 : (length(F) - 1) objective = ; distance = 0; y = ;

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

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