基于ACO蚁群优化算法的栅格地图避障路线规划matlab仿真
1.算法描述
蚁群算法是通过对自然界中真实蚂蚁的集体行为的观察,模拟而得到一种仿生优化算法,它具有很好的并行性,分布性.根据蚂蚁群体不同的集体行为特征,蚁群算法可分为受蚂蚁觅食行为启发的模型和受孵化分类启发的模型,受劳动分工和协作运输启发的模型.本文重点研究了前两种蚁群算法模型. 受蚂蚁觅食行为启发的模型又称为蚁群优化算法(ACO),是继模拟退火算法,遗传算法,禁忌搜索等之后又一启发式智能优化算法.目前它已成功应用于求解TSP问题,地图着色,路径车辆调度等优化问题.本文针对蚁群算法收敛时间长,易陷入局部最优的缺点,通过对路径上信息素的更新方式作出动态调整,建立信息素平滑机制,进而使得不同路径上的信息素的更新速度有所不同,从而使改进后算法能够有效地缩短搜索的时间,并能对最终解进行优化,避免过早的陷入局部最优. 聚类是数据挖掘的重要技术之一,它可按照某种规则将数据对象划分为多个类或簇,使同一类的数据对象有较高的相似度,而不同类的数据对象差异较大.
算法基本思想:
(1)根据具体问题设置多只蚂蚁,分头并行搜索。
(2)每只蚂蚁完成一次周游后,在行进的路上释放信息素,信息素量与解的质量成正比。
(3)蚂蚁路径的选择根据信息素强度大小(初始信息素量设为相等),同时考虑两点之间的距离,采用随机的局部搜索策略。这使得距离较短的边,其上的信息素量较大,后来的蚂蚁选择该边的概率也较大。
(4)每只蚂蚁只能走合法路线(经过每个城市1次且仅1次),为此设置禁忌表来控制。
(5)所有蚂蚁都搜索完一次就是迭代一次,每迭代一次就对所有的边做一次信息素更新,原来的蚂蚁死掉,新的蚂蚁进行新一轮搜索。
(6)更新信息素包括原有信息素的蒸发和经过的路径上信息素的增加。
(7)达到预定的迭代步数,或出现停滞现象(所有蚂蚁都选择同样的路径,解不再变化),则算法结束,以当前最优解作为问题的最优解。
将各个蚂蚁随机地置于不同的出发地,对每个蚂蚁k ( k = 1 , 2 , ⋯ , m ) ,按照轮盘赌法得到下面的转移概率公式计算其下一个待访问的城市,直到所有蚂蚁访问完所有的城市。
2.仿真效果预览
matlab2022a仿真结果如下:
3.MATLAB核心程序
%% -----------iteration time is k, ant number is M-------------------- for k=1:K disp(k); for m=1:M %% First step: status initialization W=S;%set current point as the starting point Path=S;%initialize the passing route PLkm=0;%initialize the passing length TABUkm=ones(1,N);%initialize the forbbiden table TABUkm(S)=0;% eliminate this point for it is the starting point DD=D;%initialize adjacency matrix %% Second Step:Choose the nodes that can step forward DW=DD(W,:); DW1=find(DW<inf); for j=1:length(DW1) if TABUkm(DW1(j))==0 DW(j)=inf; end end LJD=find(DW<inf);% set of points can be selected Len_LJD=length(LJD);%number of points can be selected %% Colony stop condition:there is no food or go into a impass while W~=E&&Len_LJD>=1 %% Third Step:the method to choose the next step PP=zeros(1,Len_LJD); for i=1:Len_LJD PP(i)=(Tau(W,LJD(i))^Alpha)*(Eta(LJD(i))^Beta); end PP=PP/(sum(PP));%construct probability distributing Pcum=cumsum(PP); Select=find(Pcum>=rand); to_visit=LJD(Select(1));%the next step node %% Fourth Step:status update and record Path=[Path,to_visit];%Paths accumulation PLkm=PLkm+DD(W,to_visit);%Path length accumulation W=to_visit;%move to the next point for kk=1:N if TABUkm(kk)==0 DD(W,kk)=inf; DD(kk,W)=inf; end end TABUkm(W)=0;%eliminate the travelled point in the forbidden table DW=DD(W,:); DW1=find(DW<inf); for j=1:length(DW1) if TABUkm(DW1(j))==0 DW(j)=inf; end end LJD=find(DW<inf);%set of optional points Len_LJD=length(LJD);%number of optional points end %% Fifth Step:record the pate and length that every ant for every %% iteration passes ROUTES{k,m}=Path; if Path(end)==E PL(k,m)=PLkm; else PL(k,m)=inf; end end %% Sixth Step: update pheromone Delta_Tau=zeros(N,N);%initialize updating ammount for m=1:M if PL(k,m)<inf ROUT=ROUTES{k,m}; TS=length(ROUT)-1; PL_km=PL(k,m); for s=1:TS x=ROUT(s); y=ROUT(s+1); Delta_Tau(x,y)=Delta_Tau(x,y)+Q/PL_km; Delta_Tau(y,x)=Delta_Tau(y,x)+Q/PL_km; end end end Tau=(1-Rho).*Tau+Delta_Tau;%pheromone evaporates some and accumulates some end %% ---------------------------PLOT-------------------------------- plotif=1;%control parameter, determine if plot or not if plotif==1 %plot convergence curve meanPL=zeros(1,K); minPL=zeros(1,K); for i=1:K PLK=PL(i,:); Nonzero=find(PLK<inf); PLKPLK=PLK(Nonzero); meanPL(i)=mean(PLKPLK); minPL(i)=min(PLKPLK); end