基本信息
源码名称:基于蜂群算法的TSP问题研究
源码大小:2.36KB
文件格式:.zip
开发语言:MATLAB
更新时间:2023-12-27
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
使用蜂群算法对TSP问题进行研究,代码使用matlab编写,欢迎下载
%计算适应度函数值
for i = 1:FoodNumber
route = Foods(i,:);
Fitness(i) = calculateFitness(route);
end
% 初始化搜索次数,用于和Limit比较
trial=zeros(1,FoodNumber);
%找出适应度函数值的最小值
BestInd = find(Fitness == min(Fitness));
BestInd = BestInd(end);
GlobalMin = Fitness(BestInd);
GlobalParams = Foods(BestInd,:);
%迭代开始
iter = 1;
j = 1;
while ((iter <= maxCycle)),
%%%%%%%%采蜜蜂模式 %%%%%%%%
for i = 1:FoodNumber
%随机交换3个城市的顺序,改变此时的路线
route_next = Foods(i,:);
l = round(2 12*rand());
m = round(2 12*rand());
n = round(2 12*rand());
temp = route_next(l);
route_next(l) = route_next(m);
route_next(m) = route_next(n);
route_next(n) = temp;
%计算新蜜源的适应度函数值
FitnessSol = calculateFitness(route_next);
%使用贪婪准则,寻找最优蜜源
if (FitnessSol < Fitness(i))
Foods(i,:) = route_next;
Fitness(i) = FitnessSol;
trial(i) = 0;
else
使用蜂群算法对TSP问题进行研究,代码使用matlab编写,欢迎下载
%计算适应度函数值
for i = 1:FoodNumber
route = Foods(i,:);
Fitness(i) = calculateFitness(route);
end
% 初始化搜索次数,用于和Limit比较
trial=zeros(1,FoodNumber);
%找出适应度函数值的最小值
BestInd = find(Fitness == min(Fitness));
BestInd = BestInd(end);
GlobalMin = Fitness(BestInd);
GlobalParams = Foods(BestInd,:);
%迭代开始
iter = 1;
j = 1;
while ((iter <= maxCycle)),
%%%%%%%%采蜜蜂模式 %%%%%%%%
for i = 1:FoodNumber
%随机交换3个城市的顺序,改变此时的路线
route_next = Foods(i,:);
l = round(2 12*rand());
m = round(2 12*rand());
n = round(2 12*rand());
temp = route_next(l);
route_next(l) = route_next(m);
route_next(m) = route_next(n);
route_next(n) = temp;
%计算新蜜源的适应度函数值
FitnessSol = calculateFitness(route_next);
%使用贪婪准则,寻找最优蜜源
if (FitnessSol < Fitness(i))
Foods(i,:) = route_next;
Fitness(i) = FitnessSol;
trial(i) = 0;
else