• 大小: 5KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-06-02
  • 语言: 其他
  • 标签: 蚁群算法  

资源简介

设定障碍物,通过蚁群算法完成路径规划!

资源截图

代码片段和文件信息

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Ant system (AS) for TSP.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

clear all;
close all
clc;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Data
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
nodesLocation = LoadNodesLocations();
trackWidth = 5;
numberOfSection = length(nodesLocation)/trackWidth;
nodesFriction =  ones(150);
i = [11 12 19 20 26 27 33 34 47 48 49 50];
nodesFriction(i) = 99;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Parameters
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
numberOfAnts = 50;  % To do: Set to appropriate value.
alpha = 1.0;        % To do: Set to appropriate value.
beta = 5.0;         % To do: Set to appropriate value.
rho = 0.5;          % To do: set to appropriate value.

nearestNeighbourPathLength = GetNearestNeighbourPathLength(nodesLocation nodesFriction trackWidth);
tau0 = numberOfAnts/nearestNeighbourPathLength;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Initialization
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

range = [0 20 0 20];
tspFigure = InitializeTspPlot(nodesLocation range);
connection = InitializeConnections(nodesLocation nodesLocation nodesFriction);
pheromoneLevel = InitializePheromoneLevels(length(nodesLocation) tau0); 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Main loop
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
minimumPathLength = inf;

iIteration = 0;
targetPathLength = 0;

while (minimumPathLength > targetPathLength)
 iIteration = iIteration + 1;

 %%%%%%%%%%%%%%%%%%%%%%%%%%
 % Generate paths:
 %%%%%%%%%%%%%%%%%%%%%%%%%%

 pathCollection = [];
 pathLengthCollection = [];
 for k = 1:numberOfAnts
  [path pathLength] = GeneratePath(pheromoneLevel alpha beta trackWidth nodesLocation nodesFriction);
                 
  if (pathLength < minimumPathLength)
    minimumPathLength = pathLength;
    disp(sprintf(‘Iteration %d ant %d: path length = %.5f‘iIterationkminimumPathLength));
    PlotPath(connectionnodesLocationpath trackWidth);
    bestPath = path;
  end
  pathCollection = [pathCollection; path];           
  pathLengthCollection = [pathLengthCollection; pathLength];
 end

 %%%%%%%%%%%%%%%%%%%%%%%%%%
 % Update pheromone levels
 %%%%%%%%%%%%%%%%%%%%%%%%%%

 deltaPheromoneLevel = ComputeDeltaPheromoneLevels(pathCollectionpathLengthCollection trackWidth);  % To do: write the ComputeDeltaPheromoneLevels function
 pheromoneLevel = UpdatePheromoneLevels(pheromoneLeveldeltaPheromoneLevelrho);          % To do: write the UpdatePheromoneLevels function

end







 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       2555  2018-02-06 20:00  AntRace-master\AntRace-master\AntSystem.m

     文件        824  2018-02-06 20:00  AntRace-master\AntRace-master\ComputeDeltaPheromoneLevels.m

     文件         88  2018-02-06 20:00  AntRace-master\AntRace-master\EuclidianDistance.m

     文件        668  2018-02-06 20:00  AntRace-master\AntRace-master\GeneratePath.m

     文件        853  2018-02-06 20:00  AntRace-master\AntRace-master\GetNearestNeighbourPathLength.m

     文件       1360  2018-02-06 20:00  AntRace-master\AntRace-master\GetNode.m

     文件        280  2018-02-06 20:00  AntRace-master\AntRace-master\InitializeConnections.m

     文件        136  2018-02-06 20:00  AntRace-master\AntRace-master\InitializePheromoneLevels.m

     文件        355  2018-02-06 20:00  AntRace-master\AntRace-master\InitializeTspPlot.m

     文件        177  2018-02-06 20:00  AntRace-master\AntRace-master\LoadNodesLocations.m

     文件        751  2018-02-06 20:00  AntRace-master\AntRace-master\NearestNeighbourg.m

     文件        311  2018-02-06 20:00  AntRace-master\AntRace-master\PlotPath.m

     文件        392  2018-02-06 20:00  AntRace-master\AntRace-master\README.md

     文件        162  2018-02-06 20:00  AntRace-master\AntRace-master\UpdatePheromoneLevels.m

     目录          0  2018-09-28 08:08  AntRace-master\AntRace-master

     目录          0  2018-09-28 08:08  AntRace-master

----------- ---------  ---------- -----  ----

                 8912                    16


评论

共有 条评论