模型一程序
clear;clc;
AB=140;BC=255;CD=255;DE=65;
x_obj=input('x_Obj=');
y_obj=input('y_Obj=');
z_obj=input('z_Obj=');
obj=[x_obj,y_obj,z_obj];
%=========Theta取值范围====
max_range=[180 125+90 138 270 133.5+90];
min_range=[-180 -125+90 -138 -270 -120+90];
%=========Theta取值范围end====
M=400;T=5000;pc=0.8;pm=0.1;%M为种群规模,T为迭代次数,PC为交叉率,PM为变异率
for i=1:M
for j=1:5
pop(i,j)=round(((min_range(j)+(max_range(j)-min_range(j))*rand))*10)*0.1;%每个种群的取值
end
E(i,1)=-(BC*cos(pop(i,2)*(pi/180))+CD*cos(pop(i,3)*(pi/180)))*sin(pop(i,1)*(pi/180))-DE*cos(pop(i,5)*(pi/180))*sin(pop(i,4)*(pi/180));
E(i,2)=(BC*cos(pop(i,2)*(pi/180))+CD*cos(pop(i,3)*(pi/180)))*cos(pop(i,1)*(pi/180))+DE*sin(pop(i,5)*(pi/180));
E(i,3)=BC*sin(pop(i,2)*(pi/180))+AB+CD*sin(pop(i,3)*(pi/180))-DE*cos(pop(i,5)*(pi/180))*cos(pop(i,4)*(pi/180));
end
%=======误差作为目标函数=====
for i=1:M
Objfun(i,1)=0.99*sqrt((obj(1)-E(i,1)).^2+(obj(2)-E(i,2)).^2+(obj(3)-E(i,3)).^2)+0.01*round(0.5*round(max(abs(pop(i,:)))));%round(0.5*round(max(abs(BestofPop(:)))))
end
%=======误差作为目标函数end=====
for t=1:T
FitnV=ranking(Objfun);
parent_pop=select('rws',pop,FitnV);
child_pop=gafk_operator(parent_pop,t,T,pc,pm,min_range,max_range);
com_pop=round([parent_pop;child_pop]*10)*0.1;
[N,temp]=size(com_pop);
for i=1:N
E(i,1)=-(BC*cos(com_pop(i,2)*(pi/180))+CD*cos(com_pop(i,3)*(pi/180)))*sin(com_pop(i,1)*(pi/180))-DE*cos(com_pop(i,5)*(pi/180))*sin(com_pop(i,4)*(pi/180));
E(i,2)=(BC*cos(com_pop(i,2)*(pi/180))+CD*cos(com_pop(i,3)*(pi/180)))*cos(com_pop(i,1)*(pi/180))+DE*sin(com_pop(i,5)*(pi/180));
E(i,3)=BC*sin(com_pop(i,2)*(pi/180))+AB+CD*sin(com_pop(i,3)*(pi/180))-DE*cos(com_pop(i,5)*(pi/180))*cos(com_pop(i,4)*(pi/180));
Objfun_mind(i,1)=0.99*sqrt((obj(1)-E(i,1)).^2+(obj(2)-E(i,2)).^2+(obj(3)-E(i,3)).^2)+0.01*round(0.5*round(max(abs(com_pop(i,:)))));
end
[sorted_obj,index_obj]=sort(Objfun_mind);
for k=1:M
pop(k,:)=com_pop(index_obj(k),:);
Objfun(k,:)=Objfun_mind(index_obj(k),:);
end
[best_obj(t,1),index]=min(Objfun);
best_pop(t,:)=pop(index,:);
best_E(t,:)=E(index,:);
end
[JofObj,daishu]=min(best_obj(:,1));
BestofPop=best_pop(daishu,:);
BestofE=best_E(daishu,:);
error=sqrt((obj(1)-BestofE(1)).^2+(obj(2)-BestofE(2)).^2+(obj(3)-BestofE(3)).^2);%误差
step=round(0.5*round(max(abs(BestofPop(:)))));%步子数
plot(best_obj(:,1),'-')
www.xszlw.com 求大神帮忙哈,急用!!!!
一周热门 更多>