蟻群優(yōu)化算法源代碼1、蟻群算法的優(yōu)化計算-旅行商問題(TSP)優(yōu)化-MATLAB源代碼; 2、基于蟻群算法的二維路徑規(guī)劃算法-MATLAB源代碼; 3、基于蟻群算法的三維路徑規(guī)劃算法-MATLAB源代碼;
0.png (49.38 KB, 下載次數(shù): 27)
下載附件
2018-11-15 15:47 上傳
matlab源程序如下:
- %% 該函數(shù)用于演示基于蟻群算法的三維路徑規(guī)劃算法
- %% 清空環(huán)境
- clc
- clear
- %% 數(shù)據(jù)初始化
- %下載數(shù)據(jù)
- load HeightData HeightData
- %網(wǎng)格劃分
- LevelGrid=10;
- PortGrid=21;
- %起點終點網(wǎng)格點
- starty=10;starth=4;
- endy=8;endh=5;
- m=1;
- %算法參數(shù)
- PopNumber=10; %種群個數(shù)
- BestFitness=[]; %最佳個體
- %初始信息素
- pheromone=ones(21,21,21);
- %% 初始搜索路徑
- [path,pheromone]=searchpath(PopNumber,LevelGrid,PortGrid,pheromone, ...
- HeightData,starty,starth,endy,endh);
- fitness=CacuFit(path); %適應度計算
- [bestfitness,bestindex]=min(fitness); %最佳適應度
- bestpath=path(bestindex,:); %最佳路徑
- BestFitness=[BestFitness;bestfitness]; %適應度值記錄
-
- %% 信息素更新
- rou=0.2;
- cfit=100/bestfitness;
- for i=2:PortGrid-1
- pheromone(i,bestpath(i*2-1),bestpath(i*2))= ...
- (1-rou)*pheromone(i,bestpath(i*2-1),bestpath(i*2))+rou*cfit;
- end
-
- %% 循環(huán)尋找最優(yōu)路徑
- for kk=1:100
-
- %% 路徑搜索
- [path,pheromone]=searchpath(PopNumber,LevelGrid,PortGrid,...
- pheromone,HeightData,starty,starth,endy,endh);
-
- %% 適應度值計算更新
- fitness=CacuFit(path);
- [newbestfitness,newbestindex]=min(fitness);
- if newbestfitness<bestfitness
- bestfitness=newbestfitness;
- bestpath=path(newbestindex,:);
- end
- BestFitness=[BestFitness;bestfitness];
-
- %% 更新信息素
- cfit=100/bestfitness;
- for i=2:PortGrid-1
- pheromone(i,bestpath(i*2-1),bestpath(i*2))=(1-rou)* ...
- pheromone(i,bestpath(i*2-1),bestpath(i*2))+rou*cfit;
- end
-
- end
- %% 最佳路徑
- for i=1:21
- a(i,1)=bestpath(i*2-1);
- a(i,2)=bestpath(i*2);
- end
- figure(1)
- x=1:21;
- y=1:21;
- [x1,y1]=meshgrid(x,y);
- mesh(x1,y1,HeightData)
- axis([1,21,1,21,0,2000])
- hold on
- k=1:21;
- plot3(k(1)',a(1,1)',a(1,2)'*200,'--o','LineWidth',2,...
- 'MarkerEdgeColor','k',...
- 'MarkerFaceColor','g',...
- 'MarkerSize',10)
- plot3(k(21)',a(21,1)',a(21,2)'*200,'--o','LineWidth',2,...
- 'MarkerEdgeColor','k',...
- 'MarkerFaceColor','g',...
- 'MarkerSize',10)
- text(k(1)',a(1,1)',a(1,2)'*200,'S');
- text(k(21)',a(21,1)',a(21,2)'*200,'T');
- xlabel('km','fontsize',12);
- ylabel('km','fontsize',12);
- zlabel('m','fontsize',12);
- title('三維路徑規(guī)劃空間','fontsize',12)
- set(gcf, 'Renderer', 'ZBuffer')
- hold on
- plot3(k',a(:,1)',a(:,2)'*200,'--o')
- %% 適應度變化
- figure(2)
- plot(BestFitness)
- title('最佳個體適應度變化趨勢')
- xlabel('迭代次數(shù)')
- ylabel('適應度值')
復制代碼
所有資料51hei提供下載:
蟻群優(yōu)化算法源代碼1、蟻群算法的優(yōu)化計算-旅行商問題(TSP)優(yōu)化-MATLAB源代碼; 2、.rar
(11.71 KB, 下載次數(shù): 45)
2018-11-15 14:20 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|