%解搜索函数
%===============================================
%第一种群数据
%初始化禁忌表
for i=1:ant_n_A
for j=1:city_n
tobu_A(i,j)=0;
end
end
%随机放置蚂蚁初始位置
for i=1:ant_n_A
city=round((city_n-1)*rand)+1; %随机产生初始位置城市
tobu_A(i,1)=city;
end
for i=1:ant_n_A %对每一只蚂蚁进行解构造
n=1;
for j=1:city_n-1 %每只蚂蚁进行city_n-1次探索
for k=1:city_n %临时池供选择用
temp_pool_A(k)=(hu_table(tobu_A(i,n),k)^b_A)*(ph_table_A(tobu_A(i,n),k)^a_A);
end
for k=1:n %将已经访问过的城市的选择概率置0
temp_pool_A(tobu_A(i,k))=0;
end
ada_sum=0;
for k=1:city_n
ada_sum=ada_sum+temp_pool_A(k);
end
r=rand*ada_sum; %随机产生一个数
ada_temp=0; %初始化累加值为0
h=0;
while(ada_temp<r)
h=h+1;
ada_temp=ada_temp+temp_pool_A(h);
end
%退出循环时的h值即为被选择的个体序号
n=n+1;
tobu_A(i,n)=h; %当前访问的城市加入禁忌表
end
end
%===============================================
%第二种群数据
%初始化禁忌表
for i=1:ant_n_B
for j=1:city_n
tobu_B(i,j)=0;
end
end
%随机放置蚂蚁初始位置
for i=1:ant_n_B
city=round((city_n-1)*rand)+1; %随机产生初始位置城市
tobu_B(i,1)=city;
end
for i=1:ant_n_B %对每一只蚂蚁进行解构造
n=1;
for j=1:city_n-1 %每只蚂蚁进行city_n-1次探索
for k=1:city_n %临时池供选择用
temp_pool_B(k)=(hu_table(tobu_B(i,n),k)^b_B)*(ph_table_B(tobu_B(i,n),k)^a_B);
end
for k=1:n %将已经访问过的城市的选择概率置0
temp_pool_B(tobu_B(i,k))=0;
end
ada_sum=0;
for k=1:city_n
ada_sum=ada_sum+temp_pool_B(k);
end
r=rand*ada_sum; %随机产生一个数
ada_temp=0; %初始化累加值为0
h=0;
while(ada_temp<r)
h=h+1;
ada_temp=ada_temp+temp_pool_B(h);
end
%退出循环时的h值即为被选择的个体序号
n=n+1;
tobu_B(i,n)=h; %当前访问的城市加入禁忌表
end
end ...