蚁群算法求函数最大值程序Word格式.doc

上传人:聆听****声音 文档编号:966502 上传时间:2023-04-29 格式:DOC 页数:4 大小:16KB
下载 相关 举报
蚁群算法求函数最大值程序Word格式.doc_第1页
第1页 / 共4页
蚁群算法求函数最大值程序Word格式.doc_第2页
第2页 / 共4页
蚁群算法求函数最大值程序Word格式.doc_第3页
第3页 / 共4页
蚁群算法求函数最大值程序Word格式.doc_第4页
第4页 / 共4页
亲,该文档总共4页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

蚁群算法求函数最大值程序Word格式.doc

《蚁群算法求函数最大值程序Word格式.doc》由会员分享,可在线阅读,更多相关《蚁群算法求函数最大值程序Word格式.doc(4页珍藏版)》请在冰点文库上搜索。

蚁群算法求函数最大值程序Word格式.doc

%转移概率常数

lower_1=-1;

%设置搜索范围

upper_1=1;

%

lower_2=-1;

upper_2=1;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%

fori=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=0.05;

f='

-(x.^2+2*y.^2-0.3*cos(3*pi*x)-0.4*cos(4*pi*y)+0.7)'

;

[x,y]=meshgrid(lower_1:

step:

upper_1,lower_2:

upper_2);

z=eval(f);

figure

(1);

mesh(x,y,z);

holdon;

plot3(X(:

1),X(:

2),tau,'

k*'

text(0.1,0.8,-0.1,'

蚂蚁的初始分部位置'

xlabel('

x'

);

ylabel('

y'

zlabel('

f(x,y)'

fort=1:

times

lamda=1/t;

[tau_best(t),bestindex]=max(tau);

fori=1:

ant

p(t,i)=(tau(bestindex)-tau(i))/tau(bestindex);

%计算状态转移概率

ifp(t,i)<

p0%局部搜索

temp1=X(i,1)+(2*rand-1)*lamda;

temp2=X(i,2)+(2*rand-1)*lamda;

else%全局搜索

temp1=X(i,1)+(upper_1-lower_1)*(rand-0.5);

temp2=X(i,2)+(upper_2-lower_2)*(rand-0.5);

%%%%%%%%%%%%%%%%%%%%%%越界处理

iftemp1<

lower_1

temp1=lower_1;

iftemp1>

upper_1

temp1=upper_1;

iftemp2<

lower_2

temp2=lower_2;

iftemp2>

upper_2

temp2=upper_2;

%%%%%%%%%%%%%%%%%%%%%%%

ifF(temp1,temp2)>

F(X(i,1),X(i,2))

%判断蚂蚁是否移动

X(i,1)=temp1;

X(i,2)=temp2;

tau(i)=(1-rou)*tau(i)+F(X(i,1),X(i,2));

%更新信息量

figure

(2);

x=X(:

1);

y=X(:

2);

plot3(x,y,eval(f),'

蚂蚁的最终分布位置'

),zlabel('

[max_value,max_index]=max(tau);

maxx=X(max_index,1);

maxy=X(max_index,2);

maxvalue=F(X(max_index,1),X(max_index,2));

function[F]=F(x1,x2)%目标函数

F=-(x1.^2+2*x2.^2-0.3*cos(3*pi*x1)-0.4*cos(4*pi*x2)+0.7);

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

当前位置:首页 > IT计算机 > 电脑基础知识

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

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