This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
%Generic Algorithm for function f(x1,x2,x3,........) optimum UAV Trajectories Allocation over Different Intruder Paths with Random Starting Points. Dx_Time=0;Dx10_Time=0;Dx20_Time=0;Dx30_Time=0;Dx4_Time=0;Dx0_Time=0;Dx11_Time=0;Dx21_Time=0;Dx31_Time=0;Dx41_Time=0;Dx1_Time=0;Dx12_Time=0;Dx22_Time=0;Dx32_Time=0;Dx42_Time=0;Dx2_Time=0;Dx13_Time=0;Dx23_Time=0;Dx33_Time=0;Dx43_Time=0;Dx3_Time=0;Dx14_Time=0;Dx24_Time=0;Dx34_Time=0;Dx44_Time=0; %Parametersmar=40;mar1=50;mar2=50;Size=40; G=5; CodeL=10; W0_max=20000/2; W0_min=10000/2; W1_max=20000/2; W1_min=10000/2; W2_max=20000/2; W2_min=10000/2; W3_max=20000/2; W3_min=10000/2; W4_max=20000/2; W4_min=10000/2; L0_max=100000/2; L0_min=20000/2;
%plot(x+shift_x,f1+shift_y,x1+shift_x1,f11+shift_y1,x2+shift_x2,f12+shift_y2,x3+shift_x3,f13+shift_y3,x4+shift_x4,f14+shift_y4,x5+shift_x5,f15+shift_y5)%plot(x,f1,x1,f11,x2,f12,x3,f13,x4,f14,x5,f15)%plot(u,f,x,f1) RT0_x0=0; RT1_x0=0; RT2_x0=0; RT3_x0=0; RT4_x0=0; RT5_x0=0; RT0_y0=0; RT1_y0=0; RT2_y0=0; RT3_y0=0; RT4_y0=0; RT5_y0=0; RT0_v=35; RT1_v=35; RT2_v=35; RT3_v=35; RT4_v=35; RT5_v=35; RT0_D=RT0_v*Ts; RT1_D=RT1_v*Ts; RT2_D=RT2_v*Ts; RT3_D=RT3_v*Ts; RT4_D=RT4_v*Ts; RT5_D=RT5_v*Ts; R0=W0/2;R1=W1/2;R2=W2/2;R3=W3/2;R4=W4/2; Q0=L0/2;Q1=L1/2;Q2=L2/2;Q3=L3/2;Q4=L4/2; RTG=0; RTG1=0; RTG2=0; RTG3=0; RTG4=0; for W=1:1:4 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Next location on the first flight path if RT0_y0>=0
KK=0; T=length(RTG); while Q0-RT0_x0>0.1 && RT0_x0+Q0>0.1|| -RT0_x0+Q0<0.1 KK=KK+1; if RT0_x0>=0 && RT0_x0<=(Q0-R0) RT0_xn=RT0_x0-RT0_D; RT0_yn=R0; else if RT0_x0<0 && RT0_x0>(Q0-R0)*(-1) if (RT0_x0+(Q0-R0))<=mar RT0_xn=-1*(Q0-R0); RT0_yn=R0; else RT0_xn=RT0_x0-RT0_D; RT0_yn=R0; end else if RT0_x0>(Q0-R0) && RT0_x0<Q0 if (RT0_x0-(Q0-R0))<=mar1 RT0_xn=(Q0-R0); RT0_yn=R0; else RT0_xn= R0*cos((RT0_D/R0)+acos(((RT0_x0)-(Q0-R0))/R0))+(Q0-R0); RT0_yn=((R0)^2-(RT0_xn-(Q0-R0))^2)^0.5; end else if RT0_x0<=(-1)*(Q0-R0) && RT0_x0>-Q0 RT0_xn= -R0*cos(((-1)*RT0_D/R0)+acos((((-1)*RT0_x0)-(Q0-R0))/R0))-(Q0-R0); RT0_yn=((R0)^2-((-RT0_xn)-(Q0-R0))^2)^0.5; else end end
end end RT0_x0=RT0_xn; RT(KK)=RT0_xn; RTY(KK)=RT0_yn; RTG(T+KK-1)=RT(KK); RTYG(T+KK-1)=RTY(KK); RTG(T+KK-1)=(RTG(T+KK-1)*cos(th0)-RTYG(T+KK-1)*tan(th0)*cos(th0))+long0; RTYG(T+KK-1)=(RTG(T+KK-1)*cos(th0)-RTYG(T+KK-1)*tan(th0)*cos(th0))*tan(th0)+RTYG(T+KK-1)/cos(th0)+lat0; if RT0_yn<mar RT0_y0=-1; else end end elseif RT0_y0<0 T=length(RTG);KK=0; while (Q0-RT0_x0>0.1 && RT0_x0+Q0>0.1)|| RT0_x0+Q0<0.1 % for KK=1:1:2928 KK=KK+1; if RT0_x0>=0 && RT0_x0<=(Q0-R0) if (RT0_x0+(Q0-R0))<=mar RT0_xn=(Q0-R0); RT0_yn=-R0; else RT0_xn=RT0_x0+RT0_D; RT0_yn=-R0; end else
if RT0_x0<0 && RT0_x0>=(Q0-R0)*(-1) RT0_xn=RT0_x0+RT0_D; RT0_yn=-R0; else if RT0_x0>=(Q0-R0) && RT0_x0<Q0 RT0_xn= R0*cos((-RT0_D/R0)+acos(((RT0_x0)-(Q0-R0))/R0))+(Q0-R0); RT0_yn=-((R0)^2-(RT0_xn-(Q0-R0))^2)^0.5; else if RT0_x0<=(-1)*(Q0-R0) && RT0_x0>-Q0 if (RT0_x0+(Q0-R0))>=-mar1 RT0_xn=-(Q0-R0); RT0_yn=-R0; else RT0_xn= -R0*cos((RT0_D/R0)+acos((((-1)*RT0_x0)-(Q0-R0))/R0))-(Q0-R0); RT0_yn=-((R0)^2-((-RT0_xn)-(Q0-R0))^2)^0.5; end else end end end end
RT0_x0=RT0_xn; RT1(KK)=RT0_xn; RTY1(KK)=RT0_yn; RTG(T+KK-1)=RT1(KK); RTYG(T+KK-1)=RTY1(KK); RTG(T+KK-1)=(RTG(T+KK-1)*cos(th0)-RTYG(T+KK-1)*tan(th0)*cos(th0))+long0; RTYG(T+KK-1)=(RTG(T+KK-1)*cos(th0)-RTYG(T+KK-1)*tan(th0)*cos(th0))*tan(th0)+RTYG(T+KK-1)/cos(th0)+lat0; if RT0_yn>-mar2 RT0_y0=1; else end end end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Next location on the second flight path if RT1_y0>=0 KK=0; T1=length(RTG1); while Q1-RT1_x0>0.1 && RT1_x0+Q1>0.1|| -RT1_x0+Q1<0.1 % for KK=1:1:2928 KK=KK+1; if RT1_x0>=0 && RT1_x0<=(Q1-R1) RT1_xn=RT1_x0-RT1_D; RT1_yn=R1; else if RT1_x0<0 && RT1_x0>(Q1-R1)*(-1) if (RT1_x0+(Q1-R1))<=mar RT1_xn=-1*(Q1-R1); RT1_yn=R1;
else RT1_xn=RT1_x0-RT1_D; RT1_yn=R1; end else if RT1_x0>(Q1-R1) && RT1_x0<Q1 if (RT1_x0-(Q1-R1))<=mar1 RT1_xn=(Q1-R1); RT1_yn=R1; else RT1_xn= R1*cos((RT1_D/R1)+acos(((RT1_x0)-(Q1-R1))/R1))+(Q1-R1); RT1_yn=((R1)^2-(RT1_xn-(Q1-R1))^2)^0.5; end else if RT1_x0<=(-1)*(Q1-R1) && RT1_x0>-Q1 RT1_xn= -R1*cos(((-1)*RT1_D/R1)+acos((((-1)*RT1_x0)-(Q1-R1))/R1))-(Q1-R1); RT1_yn=((R1)^2-((-RT1_xn)-(Q1-R1))^2)^0.5; else end end end end RT1_x0=RT1_xn; RT2(KK)=RT1_xn; RTY2(KK)=RT1_yn; RTG1(T1+KK-1)=RT2(KK); RTYG1(T1+KK-1)=RTY2(KK); RTG1(T1+KK-1)=(RTG1(T1+KK-1)*cos(th1)-RTYG1(T1+KK-1)*tan(th1)*cos(th1))+long1; RTYG1(T1+KK-1)=(RTG1(T1+KK-1)*cos(th1)-RTYG1(T1+KK-1)*tan(th1)*cos(th1))*tan(th1)+RTYG1(T1+KK-1)/cos(th1)+lat1;
if RT1_yn<mar2 RT1_y0=-1; else end end elseif RT1_y0<0 T1=length(RTG1); KK=0; while (Q1-RT1_x0>0.1 && RT1_x0+Q1>0.1)|| RT1_x0+Q1<0.1 % for KK=1:1:2928 KK=KK+1; if RT1_x0>=0 && RT1_x0<=(Q1-R1) if (RT1_x0+(Q1-R1))<=mar RT1_xn=(Q1-R1); RT1_yn=-R1; else RT1_xn=RT1_x0+RT1_D; RT1_yn=-R1; end else if RT1_x0<0 && RT1_x0>=(Q1-R1)*(-1) RT1_xn=RT1_x0+RT1_D; RT1_yn=-R1; else if RT1_x0>=(Q1-R1) && RT1_x0<Q1 RT1_xn= R1*cos((-RT1_D/R1)+acos(((RT1_x0)-(Q1-R1))/R1))+(Q1-R1); RT1_yn=-((R1)^2-(RT1_xn-(Q1-R1))^2)^0.5; else if RT1_x0<=(-1)*(Q1-R1) && RT1_x0>-Q1 if (RT1_x0+(Q1-R1))>=-mar1 RT1_xn=-(Q1-R1);
RT1_yn=-R1; else RT1_xn= -R1*cos((RT1_D/R1)+acos((((-1)*RT1_x0)-(Q1-R1))/R1))-(Q1-R1); RT1_yn=-((R1)^2-((-RT1_xn)-(Q1-R1))^2)^0.5; end else end end end end RT1_x0=RT1_xn; RT3(KK)=RT1_xn; RTY3(KK)=RT1_yn; RTG1(T1+KK-1)=RT3(KK); RTYG1(T1+KK-1)=RTY3(KK); RTG1(T1+KK-1)=(RTG1(T1+KK-1)*cos(th1)-RTYG1(T1+KK-1)*tan(th1)*cos(th1))+long1; RTYG1(T1+KK-1)=(RTG1(T1+KK-1)*cos(th1)-RTYG1(T1+KK-1)*tan(th1)*cos(th1))*tan(th1)+RTYG1(T1+KK-1)/cos(th1)+lat1; if RT1_yn>-mar2 RT1_y0=1; else end end
end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Next location on the third flight path if RT2_y0>=0 KK=0; T2=length(RTG2); while Q2-RT2_x0>0.1 && RT2_x0+Q2>0.1|| -RT2_x0+Q2<0.1 % for KK=1:1:2928 KK=KK+1; if RT2_x0>=0 && RT2_x0<=(Q2-R2) RT2_xn=RT2_x0-RT2_D; RT2_yn=R2; else if RT2_x0<0 && RT2_x0>(Q2-R2)*(-1) if (RT2_x0+(Q2-R2))<=mar RT2_xn=-1*(Q2-R2); RT2_yn=R2; else RT2_xn=RT2_x0-RT2_D; RT2_yn=R2; end else if RT2_x0>(Q2-R2) && RT2_x0<Q2 if (RT2_x0-(Q2-R2))<=mar1 RT2_xn=(Q2-R2); RT2_yn=R2; else RT2_xn= R2*cos((RT2_D/R2)+acos(((RT2_x0)-(Q2-R2))/R2))+(Q2-R2); RT2_yn=((R2)^2-(RT2_xn-(Q2-R2))^2)^0.5; end else if RT2_x0<=(-1)*(Q2-R2) && RT2_x0>-Q2
RT2_xn= -R2*cos(((-1)*RT2_D/R2)+acos((((-1)*RT2_x0)-(Q2-R2))/R2))-(Q2-R2); RT2_yn=((R2)^2-((-RT2_xn)-(Q2-R2))^2)^0.5; else end end end end RT2_x0=RT2_xn; RT4(KK)=RT2_xn; RTY4(KK)=RT2_yn; RTG2(T2+KK-1)=RT4(KK); RTYG2(T2+KK-1)=RTY4(KK); RTG2(T2+KK-1)=(RTG2(T2+KK-1)*cos(th2)-RTYG2(T2+KK-1)*tan(th2)*cos(th2))+long2; RTYG2(T2+KK-1)=(RTG2(T2+KK-1)*cos(th2)-RTYG2(T2+KK-1)*tan(th2)*cos(th2))*tan(th2)+RTYG2(T2+KK-1)/cos(th2)+lat2; if RT2_yn<mar2 RT2_y0=-1; else end end elseif RT2_y0<0 T2=length(RTG2); KK=0; while (Q2-RT2_x0>0.1 && RT2_x0+Q2>0.1)|| RT2_x0+Q2<0.1 % for KK=1:1:2928 KK=KK+1;
if RT2_x0>=0 && RT2_x0<=(Q2-R2) if (RT2_x0+(Q2-R2))<=mar1 RT2_xn=(Q2-R2); RT2_yn=-R2; else RT2_xn=RT2_x0+RT2_D; RT2_yn=-R2; end else if RT2_x0<0 && RT2_x0>=(Q2-R2)*(-1) RT2_xn=RT2_x0+RT2_D; RT2_yn=-R2; else if RT2_x0>=(Q2-R2) && RT2_x0<Q2 RT2_xn= R2*cos((-RT2_D/R2)+acos(((RT2_x0)-(Q2-R2))/R2))+(Q2-R2); RT2_yn=-((R2)^2-(RT2_xn-(Q2-R2))^2)^0.5; else if RT2_x0<=(-1)*(Q2-R2) && RT2_x0>-Q2 if (RT2_x0+(Q2-R2))>=-mar1 RT2_xn=-(Q2-R2); RT2_yn=-R2; else RT2_xn= -R2*cos((RT2_D/R2)+acos((((-1)*RT2_x0)-(Q2-R2))/R2))-(Q2-R2); RT2_yn=-((R2)^2-((-RT2_xn)-(Q2-R2))^2)^0.5; end else end
end end end RT2_x0=RT2_xn; RT5(KK)=RT2_xn; RTY5(KK)=RT2_yn; RTG2(T2+KK-1)=RT5(KK); RTYG2(T2+KK-1)=RTY5(KK); RTG2(T2+KK-1)=(RTG2(T2+KK-1)*cos(th2)-RTYG2(T2+KK-1)*tan(th2)*cos(th2))+long2; RTYG2(T2+KK-1)=(RTG2(T2+KK-1)*cos(th2)-RTYG2(T2+KK-1)*tan(th2)*cos(th2))*tan(th2)+RTYG2(T2+KK-1)/cos(th2)+lat2; if RT2_yn>-mar2 RT2_y0=1; else end end end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Next location on the fourth flight path if RT3_y0>=0 T3=length(RTG3); KK=0; while Q3-RT3_x0>0.1 && RT3_x0+Q3>0.1|| -RT3_x0+Q3<0.1 % for KK=1:1:2928
KK=KK+1; if RT3_x0>=0 && RT3_x0<=(Q3-R3) RT3_xn=RT3_x0-RT3_D; RT3_yn=R3; else if RT3_x0<0 && RT3_x0>(Q3-R3)*(-1) if (RT3_x0+(Q3-R3))<=mar RT3_xn=-1*(Q3-R3); RT3_yn=R3; else RT3_xn=RT3_x0-RT3_D; RT3_yn=R3; end else if RT3_x0>(Q3-R3) && RT3_x0<Q3 if (RT3_x0-(Q3-R3))<=mar1 RT3_xn=(Q3-R3); RT3_yn=R3; else RT3_xn= R3*cos((RT3_D/R3)+acos(((RT3_x0)-(Q3-R3))/R3))+(Q3-R3); RT3_yn=((R3)^2-(RT3_xn-(Q3-R3))^2)^0.5; end else if RT3_x0<=(-1)*(Q3-R3) && RT3_x0>-Q3 RT3_xn= -R3*cos(((-1)*RT3_D/R3)+acos((((-1)*RT3_x0)-(Q3-R3))/R3))-(Q3-R3); RT3_yn=((R3)^2-((-RT3_xn)-(Q3-R3))^2)^0.5; else end end end end
RT3_x0=RT3_xn; RT6(KK)=RT3_xn; RTY6(KK)=RT3_yn; RTG3(T3+KK-1)=RT6(KK); RTYG3(T3+KK-1)=RTY6(KK); RTG3(T3+KK-1)=(RTG3(T3+KK-1)*cos(th3)-RTYG3(T3+KK-1)*tan(th3)*cos(th3))+long3; RTYG3(T3+KK-1)=(RTG3(T3+KK-1)*cos(th3)-RTYG3(T3+KK-1)*tan(th3)*cos(th3))*tan(th3)+RTYG3(T3+KK-1)/cos(th3)+lat3; if RT3_yn<mar2 RT3_y0=-1; else end end elseif RT3_y0<0 T3=length(RTG3); KK=0; while (Q3-RT3_x0>0.1 && RT3_x0+Q3>0.1)|| RT3_x0+Q3<0.1 % for KK=1:1:2928 KK=KK+1; if RT3_x0>=0 && RT3_x0<=(Q3-R3) if (RT3_x0+(Q3-R3))<=mar RT3_xn=(Q3-R3); RT3_yn=-R3; else RT3_xn=RT3_x0+RT3_D; RT3_yn=-R3; end else if RT3_x0<0 && RT3_x0>=(Q3-R3)*(-1) RT3_xn=RT3_x0+RT3_D; RT3_yn=-R3;
else if RT3_x0>=(Q3-R3) && RT3_x0<Q3 RT3_xn= R3*cos((-RT3_D/R3)+acos(((RT3_x0)-(Q3-R3))/R3))+(Q3-R3); RT3_yn=-((R3)^2-(RT3_xn-(Q3-R3))^2)^0.5; else if RT3_x0<=(-1)*(Q3-R3) && RT3_x0>-Q3 if (RT3_x0+(Q3-R3))>=-mar1 RT3_xn=-(Q3-R3); RT3_yn=-R3; else RT3_xn= -R3*cos((RT3_D/R3)+acos((((-1)*RT3_x0)-(Q3-R3))/R3))-(Q3-R3); RT3_yn=-((R3)^2-((-RT3_xn)-(Q3-R3))^2)^0.5; end else end end end end RT3_x0=RT3_xn; RT7(KK)=RT3_xn; RTY7(KK)=RT3_yn; RTG3(T3+KK-1)=RT7(KK);
RTYG3(T3+KK-1)=RTY7(KK); RTG3(T3+KK-1)=(RTG3(T3+KK-1)*cos(th3)-RTYG3(T3+KK-1)*tan(th3)*cos(th3))+long3; RTYG3(T3+KK-1)=(RTG3(T3+KK-1)*cos(th3)-RTYG3(T3+KK-1)*tan(th3)*cos(th3))*tan(th3)+RTYG3(T3+KK-1)/cos(th3)+lat3; if RT3_yn>-mar2 RT3_y0=1; else end end end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Next location on the fifth flight path if RT4_y0>=0 T4=length(RTG4); KK=0; while Q4-RT4_x0>0.1 && RT4_x0+Q4>0.1|| -RT4_x0+Q4<0.1 % for KK=1:1:2928 KK=KK+1; if RT4_x0>=0 && RT4_x0<=(Q4-R4) RT4_xn=RT4_x0-RT4_D; RT4_yn=R4; else if RT4_x0<0 && RT4_x0>(Q4-R4)*(-1) if (RT4_x0+(Q4-R4))<=mar RT4_xn=-1*(Q4-R4); RT4_yn=R4; else
RT4_xn=RT4_x0-RT4_D; RT4_yn=R4; end else if RT4_x0>(Q4-R4) && RT4_x0<Q4 if (RT4_x0-(Q4-R4))<=mar1 RT4_xn=(Q4-R4); RT4_yn=R4; else RT4_xn= R4*cos((RT4_D/R4)+acos(((RT4_x0)-(Q4-R4))/R4))+(Q4-R4); RT4_yn=((R4)^2-(RT4_xn-(Q4-R4))^2)^0.5; end else if RT4_x0<=(-1)*(Q4-R4) && RT4_x0>-Q4 RT4_xn= -R4*cos(((-1)*RT4_D/R4)+acos((((-1)*RT4_x0)-(Q4-R4))/R4))-(Q4-R4); RT4_yn=((R4)^2-((-RT4_xn)-(Q4-R4))^2)^0.5; else end end end end RT4_x0=RT4_xn; RT8(KK)=RT4_xn; RTY8(KK)=RT4_yn; RTG4(T4+KK-1)=RT8(KK); RTYG4(T4+KK-1)=RTY8(KK); RTG4(T4+KK-1)=(RTG4(T4+KK-1)*cos(th4)-RTYG4(T4+KK-1)*tan(th4)*cos(th4))+long4; RTYG4(T4+KK-1)=(RTG4(T4+KK-1)*cos(th4)-RTYG4(T4+KK-1)*tan(th4)*cos(th4))*tan(th4)+RTYG4(T4+KK-1)/cos(th4)+lat4; if RT4_yn<mar2
RT4_y0=-1; else end end elseif RT4_y0<0 T4=length(RTG4); KK=0; while (Q4-RT4_x0>0.1 && RT4_x0+Q4>0.1)|| RT4_x0+Q4<0.1 % for KK=1:1:2928 KK=KK+1; if RT4_x0>=0 && RT4_x0<=(Q4-R4) if (RT4_x0+(Q4-R4))<=mar RT4_xn=(Q4-R4); RT4_yn=-R4; else RT4_xn=RT4_x0+RT4_D; RT4_yn=-R4; end else if RT4_x0<0 && RT4_x0>=(Q4-R4)*(-1) RT4_xn=RT4_x0+RT4_D; RT4_yn=-R4; else if RT4_x0>=(Q4-R4) && RT4_x0<Q4 RT4_xn= R4*cos((-RT4_D/R4)+acos(((RT4_x0)-(Q4-R4))/R4))+(Q4-R4); RT4_yn=-((R4)^2-(RT4_xn-(Q4-R4))^2)^0.5; else if RT4_x0<=(-1)*(Q4-R4) && RT4_x0>-Q4 if (RT4_x0+(Q4-R4))>=-mar1
RT4_xn=-(Q4-R4); RT4_yn=-R4; else RT4_xn= -R4*cos((RT4_D/R4)+acos((((-1)*RT4_x0)-(Q4-R4))/R4))-(Q4-R4); RT4_yn=-((R4)^2-((-RT4_xn)-(Q4-R4))^2)^0.5; end else end end end end RT4_x0=RT4_xn; RT9(KK)=RT4_xn; RTY9(KK)=RT4_yn; RTG4(T4+KK-1)=RT9(KK); RTYG4(T4+KK-1)=RTY9(KK); RTG4(T4+KK-1)=(RTG4(T4+KK-1)*cos(th4)-RTYG4(T4+KK-1)*tan(th4)*cos(th4))+long4; RTYG4(T4+KK-1)=(RTG4(T4+KK-1)*cos(th4)-RTYG4(T4+KK-1)*tan(th4)*cos(th4))*tan(th4)+RTYG4(T4+KK-1)/cos(th4)+lat4; if RT4_yn>-mar2 RT4_y0=1; else end end
Dx30_Time=0;Dx4_Time=0;Dx0_Time=0;Dx11_Time=0;Dx21_Time=0;Dx31_Time=0;Dx41_Time=0;Dx1_Time=0;Dx12_Time=0;Dx22_Time=0;Dx32_Time=0;Dx42_Time=0;Dx2_Time=0;Dx13_Time=0;Dx23_Time=0;Dx33_Time=0;Dx43_Time=0;Dx3_Time=0;Dx14_Time=0;Dx24_Time=0;Dx34_Time=0;Dx44_Time=0; while v<=(L_x-1) v=v+1; U=0; while U<=(L_RTG-1) U=U+1; if (r^2)>=((RTG(U)-x(v))^2+(RTYG(U)-f1(v))^2)&& U==v z=z+1; Dx_Time(z)=RTG(U); Dy_Time(z)=RTYG(U); else end end U=0; while U<=(L_RTG1-1) U=U+1; if (r^2)>=((RTG1(U)-x(v))^2+(RTYG1(U)-f1(v))^2)&& U==v
z=z+1; Dx10_Time(z)=RTG1(U); Dy10_Time(z)=RTYG1(U); else end end U=0; while U<=(L_RTG2-1) U=U+1; if (r^2)>=((RTG2(U)-x(v))^2+(RTYG2(U)-f1(v))^2)&& U==v z=z+1; Dx20_Time(z)=RTG2(U); Dy20_Time(z)=RTYG2(U); else end end U=0; while U<=(L_RTG3-1) U=U+1; if (r^2)>=((RTG3(U)-x(v))^2+(RTYG3(U)-f1(v))^2)&& U==v z=z+1; Dx30_Time(z)=RTG3(U); Dy30_Time(z)=RTYG3(U); else end end U=0; while U<=(L_RTG4-1) U=U+1;
if (r^2)>=((RTG4(U)-x(v))^2+(RTYG4(U)-f1(v))^2)&& U==v z=z+1; Dx4_Time(z)=RTG4(U); Dy4_Time(z)=RTYG4(U); else end end end v=0;z=0;while v<=(L_x1-1) v=v+1; U=0; while U<=(L_RTG-1) U=U+1; if (r^2)>=((RTG(U)-x1(v))^2+(RTYG(U)-f11(v))^2)&& U==v z=z+1; Dx0_Time(z)=RTG(U); Dy0_Time(z)=RTYG(U); else end end U=0; while U<=(L_RTG1-1) U=U+1; if (r^2)>=((RTG1(U)-x1(v))^2+(RTYG1(U)-f11(v))^2)&& U==v z=z+1; Dx11_Time(z)=RTG1(U); Dy11_Time(z)=RTYG1(U); else end
end U=0; while U<=(L_RTG2-1) U=U+1; if (r^2)>=((RTG2(U)-x1(v))^2+(RTYG2(U)-f11(v))^2)&& U==v z=z+1; Dx21_Time(z)=RTG2(U); Dy21_Time(z)=RTYG2(U); else end end U=0; while U<=(L_RTG3-1) U=U+1; if (r^2)>=((RTG3(U)-x1(v))^2+(RTYG3(U)-f11(v))^2)&& U==v z=z+1; Dx31_Time(z)=RTG3(U); Dy31_Time(z)=RTYG3(U); else end end U=0; while U<=(L_RTG4-1) U=U+1; if (r^2)>=((RTG4(U)-x1(v))^2+(RTYG4(U)-f11(v))^2)&& U==v z=z+1; Dx41_Time(z)=RTG4(U); Dy41_Time(z)=RTYG4(U);
else end end end v=0;z=0;while v<=(L_x2-1) v=v+1; U=0; while U<=(L_RTG-1) U=U+1; if (r^2)>=((RTG(U)-x2(v))^2+(RTYG(U)-f12(v))^2)&& U==v z=z+1; Dx1_Time(z)=RTG(U); Dy1_Time(z)=RTYG(U); else end end U=0; while U<=(L_RTG1-1) U=U+1; if (r^2)>=((RTG1(U)-x2(v))^2+(RTYG1(U)-f12(v))^2)&& U==v z=z+1; Dx12_Time(z)=RTG1(U); Dy12_Time(z)=RTYG1(U); else end end
U=0; while U<=(L_RTG2-1) U=U+1; if (r^2)>=((RTG2(U)-x2(v))^2+(RTYG2(U)-f12(v))^2)&& U==v z=z+1; Dx22_Time(z)=RTG2(U); Dy22_Time(z)=RTYG2(U); else end end U=0; while U<=(L_RTG3-1) U=U+1; if (r^2)>=((RTG3(U)-x2(v))^2+(RTYG3(U)-f12(v))^2)&& U==v z=z+1; Dx32_Time(z)=RTG3(U); Dy32_Time(z)=RTYG3(U); else end end U=0; while U<=(L_RTG4-1) U=U+1; if (r^2)>=((RTG4(U)-x2(v))^2+(RTYG4(U)-f12(v))^2)&& U==v z=z+1; Dx42_Time(z)=RTG4(U); Dy42_Time(z)=RTYG4(U); else end
end end v=0;z=0;while v<=(L_x3-1) v=v+1; U=0; while U<=(L_RTG-1) U=U+1; if (r^2)>=((RTG(U)-x3(v))^2+(RTYG(U)-f13(v))^2)&& U==v z=z+1; Dx2_Time(z)=RTG(U); Dy2_Time(z)=RTYG(U); else end end U=0; while U<=(L_RTG1-1) U=U+1; if (r^2)>=((RTG1(U)-x3(v))^2+(RTYG1(U)-f13(v))^2)&& U==v z=z+1; Dx13_Time(z)=RTG1(U); Dy13_Time(z)=RTYG1(U); else end end U=0;
while U<=(L_RTG2-1) U=U+1; if (r^2)>=((RTG2(U)-x3(v))^2+(RTYG2(U)-f13(v))^2)&& U==v z=z+1; Dx23_Time(z)=RTG2(U); Dy23_Time(z)=RTYG2(U); else end end U=0; while U<=(L_RTG3-1) U=U+1; if (r^2)>=((RTG3(U)-x3(v))^2+(RTYG3(U)-f13(v))^2)&& U==v z=z+1; Dx33_Time(z)=RTG3(U); Dy33_Time(z)=RTYG3(U); else end end U=0; while U<=(L_RTG4-1) U=U+1; if (r^2)>=((RTG4(U)-x3(v))^2+(RTYG4(U)-f13(v))^2)&& U==v z=z+1; Dx43_Time(z)=RTG4(U); Dy43_Time(z)=RTYG4(U); else end end
end v=0;z=0;while v<=(L_x4-1) v=v+1; U=0; while U<=(L_RTG-1) U=U+1; if (r^2)>=((RTG(U)-x4(v))^2+(RTYG(U)-f14(v))^2)&& U==v z=z+1; Dx3_Time(z)=RTG(U); Dy3_Time(z)=RTYG(U); else end end U=0; while U<=(L_RTG1-1) U=U+1; if (r^2)>=((RTG1(U)-x4(v))^2+(RTYG1(U)-f14(v))^2)&& U==v z=z+1; Dx14_Time(z)=RTG1(U); Dy14_Time(z)=RTYG1(U); else end end U=0; while U<=(L_RTG2-1) U=U+1;
if (r^2)>=((RTG2(U)-x4(v))^2+(RTYG2(U)-f14(v))^2)&& U==v z=z+1; Dx24_Time(z)=RTG2(U); Dy24_Time(z)=RTYG2(U); else end end U=0; while U<=(L_RTG3-1) U=U+1; if (r^2)>=((RTG3(U)-x4(v))^2+(RTYG3(U)-f14(v))^2)&& U==v z=z+1; Dx34_Time(z)=RTG3(U); Dy34_Time(z)=RTYG3(U); else end end U=0; while U<=(L_RTG4-1) U=U+1; if (r^2)>=((RTG4(U)-x4(v))^2+(RTYG4(U)-f14(v))^2)&& U==v z=z+1; Dx44_Time(z)=RTG4(U); Dy44_Time(z)=RTYG4(U); else end end end
F_P=F_P+((length(Dx_Time)+length(Dx10_Time)+length(Dx20_Time)+length(Dx30_Time)+length(Dx4_Time)))*((length(Dx0_Time)+length(Dx11_Time)+length(Dx21_Time)+length(Dx31_Time)+length(Dx41_Time)))*((length(Dx1_Time)+length(Dx12_Time)+length(Dx22_Time)+length(Dx32_Time)+length(Dx42_Time)))*((length(Dx2_Time)+length(Dx13_Time)+length(Dx23_Time)+length(Dx33_Time)+length(Dx43_Time)))*((length(Dx3_Time)+length(Dx14_Time)+length(Dx24_Time)+length(Dx34_Time)+length(Dx44_Time)))/(1000000000); %clear Dx_Time Dy_Time Dx10_Time Dy10_Time Dx20_Time Dy20_Time Dx30_Time Dy30_Time Dx4_Time Dy4_Time end F(s)=F_P;h(s)=1/F(s); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% end Ji=1./(F+1e-10);%****** Step 1 : Evaluate BestJ ******BestJ(k)=min(Ji); fi=F; %Fitness Function[Oderfi,Indexfi]=sort(fi); %Arranging fi small to biggerBestfi=Oderfi(Size); %Let Bestfi=max(fi)
BestS=E(Indexfi(Size),:); %Let BestS=E(m), m is the Indexfi belong to max(fi)bfi(k)=Bestfi; %****** Step 2 : Select and Reproduct Operation****** fi_sum=sum(fi); fi_Size=(Oderfi/fi_sum)*Size; fi_S=floor(fi_Size); %Selecting Bigger fi value kk=1; for i=1:1:Size for j=1:1:fi_S(i) %Select and Reproduce TempE(kk,:)=E(Indexfi(i),:); kk=kk+1; %kk is used to reproduce end end %************ Step 3 : Crossover Operation ************pc=0.60;n=ceil(250*rand);for i=1:2:(Size-1) temp=rand; if pc>temp %Crossover Condition for j=n:1:250 TempE(i,j)=E(i+1,j); TempE(i+1,j)=E(i,j); end endendTempE(Size,:)=BestS;E=TempE; %************ Step 4: Mutation Operation **************%pm=0.001;%pm=0.001-[1:1:Size]*(0.001)/Size; %Bigger fi, smaller Pm%pm=0.0; %No mutationpm=0.1; %Big mutation for i=1:1:Size for j=1:1:25*CodeL temp=rand; if pm>temp %Mutation Condition if TempE(i,j)==0 TempE(i,j)=1; else TempE(i,j)=0; end end end end %Guarantee TempPop(30,:) is the code belong to the best individual(max(fi))TempE(Size,:)=BestS;
E=TempE; W0(k)=W0;W1(k)=W1;W2(k)=W2;W3(k)=W3;W4(k)=W4;L0(k)=L0;L1(k)=L1;L2(k)=L2;L3(k)=L3;L4(k)=L4;th0(k)=th0;th1(k)=th1;th2(k)=th2;th3(k)=th3;th4(k)=th4;lat0(k)=lat0;lat1(k)=lat1;lat2(k)=lat2;lat3(k)=lat3;lat4(k)=lat4;long0(k)=long0;long1(k)=long1;long2(k)=long2;long3(k)=long3;long4(k)=long4; end Max_Value=BestfiBestS figure(1);plot(time,BestJ); xlabel('Times');ylabel('Best J');figure(3);plot(time,bfi);xlabel('times');ylabel('Best F');