资源描述:
《蚁群算法的matlab源码》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、该程序试图对具有31个城市的VRP进行求解,已知的最优解为784.1,我用该程序只能优化到810左右,应该是陷入局部最优,但我不知问题出在什么地方。请用过蚁群算法的高手指教。蚁群算法的matlab源码,同时请指出为何不能优化到已知的最好解%%% theprocedureofantcolonyalgorithmforVRP%% % % % % % % % % % %%initializetheparametersofantcolonyalgorithmsloaddata.txt;d=data(:,2:3);g=dat
2、a(:,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; %initialpheromonelevelvalueQV=100; %车辆容量vehicle_best=round(sum(g)/QV)+1; %所完成任务所需的最少车数V=40;%计算两点的距离fori=1:32; forj=1:32; dist(i,j)=sqrt((d(i
3、,1)-d(j,1))^2+(d(i,2)-d(j,2))^2); end;end;%给taomiu赋初值fori=1:32; forj=1:32; ifi~=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;fork=1:32; fork=1:32;
4、 deltao(i,j)=0; end;end; best_cost=10000; forn_gen=1:50; print_head(n_gen); fori=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; %由蚂蚁产生的路径数量
5、 M_vehicle=500; t=0; %最佳路径数组的元素数为0 whilesumload<=QV; fork=1:length(rn); ifsumload+g(rn(k))<=QV; gama(cur_pos(i),rn(k))=(sumload+g(rn(k)))/QV; A(n)=rn(k); n=n+1; end; end;
6、 fid=fopen('out_customer.txt','a+'); fprintf(fid,'%s %it','thecurrentpositionis:',cur_pos(i)); fprintf(fid,'%s','thepossiblecustomersetis:') fprintf(fid,'t%i',A); fprintf(fid,'------------------------------'); fclose(fid); p=c
7、ompute_prob(A,cur_pos(i),tao,miu,alpha,belta,gama,lmda,i); maxp=1e-8; na=length(A); forj=1:na; ifp(j)>maxp maxp=p(j); index_max=j; end; end;