遗传算法选址代码_精品文档.txt资料文档下载
- 文档编号:14440784
- 上传时间:2022-10-22
- 格式:TXT
- 页数:7
- 大小:6.83KB
遗传算法选址代码_精品文档.txt资料文档下载
《遗传算法选址代码_精品文档.txt资料文档下载》由会员分享,可在线阅读,更多相关《遗传算法选址代码_精品文档.txt资料文档下载(7页珍藏版)》请在冰豆网上搜索。
22.11412.617;
23.67019.639;
23.16723.413;
22.80427.228;
28.4007.940;
28.87012.820;
28.86618.521;
28.29023.690;
28.30427.915;
33.97623.961;
37.89716.702;
39.27011.630;
43.50014.700;
39.8547.780;
52.9309.170];
%%�����һ�����е�ȫ�������
S1=0;
form=1:
26
S1=S1+sqrt((18.450-a(m,1))^2+(17.420-a(m,2))^2);
end
%%������ʼ���Ӻ��ٶ�
fori=1:
popsize
%�������һ����Ⱥ
GApop(i,:
)=Code(lenchrom,bound);
%������Ӧ��
fitness(i)=fun(GApop(i,:
),a);
%����õ
�Ⱦɫ��
[bestfitnessbestindex]=min(fitness);
zbest=GApop(bestindex,:
);
gbest=GApop;
fitnessgbest=fitness;
fitnesszbest=bestfitness;
%%����Ѱ��
fori=1:
maxgen
i;
%��Ⱥ����GA
GApop=Select(GApop,fitness,popsize);
%�������GA
GApop=Cross(pc,lenchrom,GApop,popsize,bound);
clear%ɾ��workplace����
%��Ⱥ��ģ
%�����ִ�����
%��Ⱥ
Pz2=0;
Pz2=Pz2+55/((18.450-a(m,1))^2+(17.420-a(m,2))^2);
[bestfitnessbestindex]=max(fitness);
GApop=Mutation(pm,lenchrom,GApop,popsize,[imaxgen],bound);
pop=GApop;
forj=1:
Pz1=fun(pop(j,:
ifPz2<
Pz1
fitness(j)=fun(pop(j,:
end
%�������Ÿ���
iffitness(j)<
fitnessgbest(j)
gbest(j,:
)=pop(j,:
fitnessgbest(j)=fitness(j);
end
%Ⱥ�����Ÿ���
fitnesszbest
zbest=pop(j,:
fitnesszbest=fitness(j);
yy(i)=fitnesszbest;
%%���
disp'
*************bestcoordinate***********'
zbest
plot(yy,'
linewidth'
2);
title(['
��Ӧ������'
'
��ֹ����='
num2str(maxgen)]);
xlabel('
��������'
ylabel('
��Ӧ��'
gridon
%%��Ӧ�Ⱥ���
functionPz1=fun(x,a)
Pz1=0;
Pz1=Pz1+33/((x
(1)-a(m,1))^2+(x
(2)-a(m,2))^2);
%Ⱦɫ������㷨���£
�
functionret=Code(lenchrom,bound)
%�����������������Ⱦɫ�壬���������ʼ��һ����Ⱥ
%lenchrominput:
Ⱦɫ�峤��
%boundinput:
������ȡֵ��Χ
%retoutput:
Ⱦɫ��ı���ֵ
flag=0;
whileflag==0
pick=rand(1,lenchrom);
ret=bound(:
1)'
+(bound(:
2)-bound(:
1))'
.*pick;
flag=test(lenchrom,bound,ret);
%ѡ�����ӳ������£
functionret=Select(individuals,fitness,sizepop)
%��������ÿ
һ����Ⱥ�е�Ⱦɫ�����ѡ���Խ��к���Ľ���ͱ���
%individualsinput:
��Ⱥ��Ϣ
%fitnessinput����Ӧ��
%sizepopinput����Ⱥ��ģ
%optsinput:
ѡ�
���ѡ��
%retoutput:
����ѡ������Ⱥ
fitness=1./(fitness);
sumfitness=sum(fitness);
sumf=fitness./sumfitness;
index=[];
fori=1:
sizepop
pick=rand;
whilepick==0
pick=rand;
end
forj=1:
pick=pick-sumf(j);
ifpick<
index=[indexj];
break;
individuals=individuals(index,:
fitness=fitness(index);
ret=individuals;
%��������MATLAB��������;
functionret=Cross(pcross,lenchrom,chrom,sizepop,bound)
%��������ɽ������
%pcrossinput:
�������
%lenchrominput��Ⱦɫ��ij���
%chrominput��Ⱦɫ��Ⱥ
%sizepopinput:
��Ⱥ��ģ
%retoutput:
������Ⱦɫ��
fori=1:
sizepop
%���ѡ������Ⱦɫ����н���
pick=rand(1,2);
whileprod(pick)==0
pick=rand(1,2);
end
index=ceil(pick.*sizepop);
%������ʾ����Ƿ���н���
pick=rand;
whilepick==0
end
ifpick>
pcross
continue;
end
whileflag==0
%���ѡ�
��
whilepick==0
pick=rand;
pos=ceil(pick.*sum(lenchrom));
%���濪ʼ
v1=chrom(index
(1),pos)
v2=chrom(index
(2),pos)
chrom(index
(1),pos)=pick*v2+(1-pick)*v1;
chrom(index
(2),pos)=pick*v1+(1-pick)*v2;
flag1=test(lenchrom,bound,chrom(index
(1),:
));
flag2=test(lenchrom,bound,chrom(index
(2),:
ifflag1*flag2==0
flag=0;
elseflag=1;
ret=chrom;
%����Ⱦɫ������Գ������£
functionflag=test(lenchrom,bound,code)
%lenchrominput:
Ⱦɫ�峤��
%boundinput��������ȡֵ��Χ
%codeoutput��Ⱦɫ��ı���ֵ
%��ʼ����
flag=1;
[n,m]=size(code);
fori=1:
n
ifcode(i)<
bound(i,1)||code(i)>
bound(i,2)
flag=0;
%�������ӳ������£
functionret=Mutation(pmutation,lenchrom,chrom,sizepop,pop,bound)
%��������ɱ������
%pmutationinput:
�������
%lenchrominput��Ⱦɫ��ij���
%chrominput��Ⱦɫ��Ⱥ
%sizepopinput:
��Ⱥ��ģ
%popinput����ǰ��Ⱥ�Ľ������������Ľ���������Ϣ
%retoutput:
������Ⱦɫ��
%���ѡ��һ��Ⱦɫ����б���
pick=rand;
index=ceil(pick*sizepop);
%������ʾ�������ѭ���Ƿ���б���
pmutation
%�����
pos=ceil(pick*sum(lenchrom));
v=chrom(i,pos);
v1=v-bound(pos,1);
v2=bound(pos,2)-v;
ifpick>
0.5
delta=v2*(1-pick^((1-pop
(1)/pop
(2))^2));
chrom(i,pos)=v+delta;
else
delta=v1*(1-pick^((1-pop
(1)/pop
(2))^2));
chrom(i,pos)=v-delta;
flag=test(lenchrom,bound,chrom(i,:
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 遗传 算法 选址 代码 精品 文档
![提示](https://static.bdocx.com/images/bang_tan.gif)