蚁群算法的matlab仿真

车辆路径问题 蚁群算法采用matlab开发的仿真平台:算法实现,路径显示,人机交互控制等 希望对你有帮助!

Data.txt的格式是4列

第一列是序号,中间两列是点坐标数据,后一列是需求量。
d=data(:,2:3);
g=data(:,4);
这里就可以看出,d是车辆路径问题的所有坐标。


蚁群算法采用matlab开发的仿真平台:算法实现,路径显示,人机交互控制等
希望对你有帮助!
是可以运行的
% the procedure of ant colony algorithm for VRP
%
% % % % % % % % % % %

%initialize the parameters of ant colony algorithms
load data.txt;
d=data(:,2:3);
g=data(:,4);
m=31; % 蚂蚁数
alpha=1;
belta=4;% 决定tao和miu重要性的参数
lmda=0;
rou=0.9; %衰减系数
q0=0.95;
% 概率
tao0=1/(31*841.04);%初始信息素
Q=1;% 蚂蚁循环一周所释放的信息素
defined_phrm=15.0; % initial pheromone level value
QV=100; % 车辆容量
vehicle_best=round(sum(g)/QV)+1; %所完成任务所需的最少车数
V=40;
% 计算两点的距离
for i=1:32;
for j=1:32;
dist(i,j)=sqrt((d(i,1)-d(j,1))^2+(d(i,2)-d(j,2))^2);
end;
end;
%给tao miu赋初值
for i=1:32;
for j=1:32;
if i~=j;
%s(i,j)=dist(i,1)+dist(1,j)-dist(i,j);
tao(i,j)=defined_phrm;
miu(i,j)=1/dist(i,j);
end;
end;
end;

for k=1:32;
for k=1:32;
deltao(i,j)=0;
end;
end;
best_cost=10000;
for n_gen=1:50;
print_head(n_gen);
for i=1:m;
%best_solution=[];
print_head2(i);
sumload=0;
cur_pos(i)=1;
rn=randperm(32);
n=1;
nn=1;
part_sol(nn)=1;
%cost(n_gen,i)=0.0;
n_sol=0; % 由蚂蚁产生的路径数量
M_vehicle=500;
t=0; %最佳路径数组的元素数为0

while sumload<=QV;

for k=1:length(rn);
if sumload+g(rn(k))<=QV;
gama(cur_pos(i),rn(k))=(sumload+g(rn(k)))/QV;
A(n)=rn(k);
n=n+1;
end;
end;
fid=fopen('out_customer.txt','a+');
fprintf(fid,'%s %i\t','the current position is:',cur_pos(i));
fprintf(fid,'\n%s','the possible customer set is:')
fprintf(fid,'\t%i\n',A);
fprintf(fid,'------------------------------\n');
fclose(fid);

p=compute_prob(A,cur_pos(i),tao,miu,alpha,belta,gama,lmda,i);
maxp=1e-8;
na=length(A);
for j=1:na;
if p(j)>maxp
maxp=p(j);
index_max=j;
end;
end;

old_pos=cur_pos(i);
if rand(1)<q0
cur_pos(i)=A(index_max);
else
krnd=randperm(na);
cur_pos(i)=A(krnd(1));
bbb=[old_pos cur_pos(i)];
ccc=[1 1];
if bbb==ccc;
cur_pos(i)=A(krnd(2));
end;
end;

tao

你可能喜欢

  • 算法matlab代码
  • 算法代码
  • 机器人路径规划
  • 遗传算法matlab
  • 机器人避障

蚁群算法的matlab仿真相关文档

最新文档

返回顶部