百度文库- 让每个人平等地提升自我
function [maxx,maxy,maxvalue]=antcolony
% 蚁群算法求函数最大值的程序%%%%%%%%%%%%%%%%%%%%%%%%%%% 初始化ant=200; % 蚂蚁数量
times=50; % 蚂蚁移动次数
rou=; % 信息素挥发系数
p0=; % 转移概率常数
lower_1=-1; % 设置搜索范围
upper_1=1; %
lower_2=-1; %
upper_2=1; % %%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i=1 : ant
X(i,1)=(lower_1+(upper_1-lower_1)*rand);
%随机设置蚂蚁的初值位置X(i,2)=(lower_2+(upper_2-lower_2)*rand);
tau(i)=F(X(i,1),X(i,2));
end
step=;
f='-(x.^2+2*y.^*cos(3*pi*x)*cos(4*pi*y)+';
[x,y]=meshgrid(lower_1:step:upper_1,lower_2:step:upper_2);
z=eval(f);
figure(1);
mesh(x,y,z);
hold on;
plot3(X(:,1),X(:,2),tau,'k*')
hold on;
text,,,'蚂蚁的初始分部位置')
xlabel('x');ylabel('y');zlabel('f(x,y)');
for t=1:times
lamda=1/t;
[tau_best(t),bestindex]=max(tau);
for i=1:ant
p(t,i)=(tau(bestindex)-tau(i))/tau(bestindex);
% 计算状态转移概率
end
for i=1:ant
if p(t,i)