www.pudn.com > anttsp.rar > tourlength_iterbest.m, change:2008-04-20,size:630b


function [iter_best,ant]=tourlength_iterbest(ant_num,city_num,dist,ant) 
%计算每只蚂蚁的路径长度并返回当前迭代最优路径 
for i=1:ant_num                                            %蚂蚁路径长度 
    ant(i).tour(city_num+1)=ant(i).tour(1); 
    ant(i).length=0; 
    for j=1:city_num 
        ant(i).length=ant(i).length+dist(ant(i).tour(j),ant(i).tour(j+1)); 
    end 
end 
iter_best.tour=ant(1).tour;                                %当前迭代最优路径 
iter_best.length=ant(1).length; 
for i=1:ant_num 
    if ant(i).length<iter_best.length 
        iter_best.tour=ant(i).tour; 
        iter_best.length=ant(i).length; 
    end 
end