遗传算法选址代码.txt资料文档下载

上传人:wj 文档编号:4643371 上传时间:2023-05-03 格式:TXT 页数:7 大小:6.83KB
下载 相关 举报
遗传算法选址代码.txt资料文档下载_第1页
第1页 / 共7页
遗传算法选址代码.txt资料文档下载_第2页
第2页 / 共7页
遗传算法选址代码.txt资料文档下载_第3页
第3页 / 共7页
遗传算法选址代码.txt资料文档下载_第4页
第4页 / 共7页
遗传算法选址代码.txt资料文档下载_第5页
第5页 / 共7页
遗传算法选址代码.txt资料文档下载_第6页
第6页 / 共7页
遗传算法选址代码.txt资料文档下载_第7页
第7页 / 共7页
亲,该文档总共7页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

遗传算法选址代码.txt资料文档下载

《遗传算法选址代码.txt资料文档下载》由会员分享,可在线阅读,更多相关《遗传算法选址代码.txt资料文档下载(7页珍藏版)》请在冰点文库上搜索。

遗传算法选址代码.txt资料文档下载

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,:

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 党团工作 > 入党转正申请

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2