當前位置:編程學習大全網 - 編程軟體 - 如何設計出使用最少次數的比較大小來求解5個城市的TSP問題的算法

如何設計出使用最少次數的比較大小來求解5個城市的TSP問題的算法

該程序試圖對具有31個城市的VRP進行求解,已知的最優解為784.1,我用該程序只能優化到810左右,應該是陷入局部最優,但我不知問題出在什麽地方。請用過蟻群算法的高手指教。蟻群算法的matlab源碼,同時請指出為何不能優化到已知的最好解%%%theprocedureofantcolonyalgorithmforVRP%%%%%%%%%%%%%initializetheparametersofantcolonyalgorithmsloaddata.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;%initialpheromonelevelvalueQV=100;%車輛容量vehicle_best=round(sum(g)/QV)+1;%所完成任務所需的最少車數V=40;%計算兩點的距離fori=1:32;forj=1:32;dist(i,j)=sqrt((d(i,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;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;%由螞蟻產生的路徑數量M_vehicle=500;t=0;%最佳路徑數組的元素數為0whilesumloadmaxpmaxp=p(j);index_max=j;end;end;old_pos=cur_pos(i);ifrand(1)

  • 上一篇:如何編制新的數控程序
  • 下一篇:電腦插入U盤後裏面的文件變成快捷方式怎麽辦
  • copyright 2024編程學習大全網