蚁群算法的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
- 机器人避障
- 萤火虫GSO算法matlab代码3页
- 插值算法与matlab代码8页
- 粒子群算法的matlab代码实现5页
- 遗传算法matlab代码11页
- 粒子群算法matlab代码19页
- lle算法详解及matlab代码实现3页
- 免疫算法C代码4页
- java排序算法代码11页
- Dijkstra算法C代码4页
- 蚁群算法简单代码2页
- 常见算法代码总结4页
- C语言二分法查找算法代码2页
- 移动机器人路径规划概述 与人工势场法29页
- 移动机器人路径规划技术的现状与发展7页
- 移动机器人路径规划方法研究5页
- 基于模拟退火_人工势场法的足球机器人路径规划研究3页
- 线性规划与网络流24题 -- 08机器人路径规划问题1页
- 基于改进遗传算法的机器人路径规划4页


