1 简介
遗传算法(Genetic Algorithm,GA)是进化计算的一部分,是模拟达尔文的遗传选择和自然淘汰的生物进化过程的计算模型,是一种通过模拟自然进化过程搜索最优解的方法。该算法简单、通用,鲁棒性强,适于并行处理。
2 部分代码
%清空运行空间
clc;
clear;
close all;
wmax=0.9;
wmin=0;%速度的上限及下限
itmax=50;%迭代代数
%速度更新参数
c1=2;
c2=2;
for iter=1:itmax
W(iter)=wmax-((wmax-wmin)/itmax)*iter;
end;
a=-1;
b=2;
N=200;
D=2;
m=0.1;
n=3;
tcl=0.05;
f='x.*sin(4*pi.*x)-y.*sin(4*pi.*y+pi+1)';
[x,y]=meshgrid(a:tcl:b,a:tcl:b);
vxp=x;
vyp=y;
vzp=eval(f);
x=[];
vmfit=[];
x=a+(b-a)*rand(N,D,1);
V=wmin+(wmax-wmin)*rand(N,D,1);
gbest(1,:,itmax)
Fbest(1,1,itmax)
%Random deployment algorithm
sx=a+(b-a)*rand(N,D,1);
sy=a+(b-a)*rand(N,D,1);
sz=a+(b-a)*rand(N,D,1);
%
%Gradient direction algorithm
figure(1);
mesh(vxp,vyp,vzp);
hold on;
plot3(x(:,1,1),x(:,2,1),F(:,1,1),'k*')
title('Gradient direction algorithm hydrophone distribution');
%Left view
%view(-90,0)
xlabel('Simulated underwater area width(kilometre)');
ylabel('Simulated underwater area length(kilometre)');
zlabel('Simulated water depth(kilometre)');
grid on;
figure(2)
mesh(vxp,vyp,vzp);
hold on;
plot3(sx,sy,sz,'k*','MarkerSize',5)
title('Random deployment algorithm hydrophone distribution');
%Left view
%view(-90,0)
xlabel('Simulated underwater area width(kilometre)');
ylabel('Simulated underwater area length(kilometre)');
zlabel('Simulated water depth(kilometre)');
grid on;
figure(3);
i_draw4=1:itmax;
Fbest1(i_draw4)=Fbest(1,1,i_draw4);
i_draw4=i_draw4';
plot(i_draw4,Fbest1);
hold on;
plot(vmfit,'r');
hold off;
title('Optimal, average function value change trend');
xlabel('Generations');
ylabel('J(\theta)');
grid on;
3 仿真结果
4 参考文献
[1]刘鲭洁,陈桂明,杨旗. (2008). 基于matlab工具的遗传算法求解有约束最优化问题. 兵工自动化, 27(11), 2.
**部分理论引用网络文献,若有侵权联系博主删除。*