[Path planning] Three-dimensional path planning based on ant colony algorithm [Matlab 042]

1. Introduction

Ant colony algorithm is also one of optimization algorithms. Ant colony algorithm is good at solving combinatorial optimization problems. Ant colony algorithm can effectively solve the well-known traveling salesman problem (TSP), and more than that, it has also achieved certain results in other fields, such as process sequencing problems, graph coloring problems, network routing problems, and so on. Next, I will briefly introduce the basic ideas of ant colony algorithm.

Ant colony algorithm, as the name suggests, is an algorithm derived from the foraging behavior of ant colonies. The foraging behavior of a single ant seems chaotic, but according to the observation of entomologists, the ant colony can always find the closest route to the food when foraging. What is the reason? In fact, the eyesight of ants is not very good, but by what area do they find the shortest path to food? Through research, it is found that each ant releases a substance called pheromone along the way when foraging. Other ants will be aware of this substance, therefore, this substance will affect the foraging behavior of other ants. When there are more ants on some paths, the pheromone concentration on this path will be higher, and the more likely it is for other ants to choose this path, thereby increasing the pheromone concentration on this path. Of course, the concentration of pheromone on a path will also decrease over time. This selection process is called ant's autocatalytic behavior, which is a positive feedback mechanism, and the entire ant colony can also be identified as an enhanced learning system.

In order to let everyone better understand the foraging behavior of the ant colony mentioned above, here is a picture to illustrate the foraging behavior of the ant colony.

As shown in the figure, point A is an ant nest, and there are two ants in it, ant 1 and ant 2. Point B is where the food is, and point C is just a point on the path. Suppose ABC forms an equilateral triangle, and the moving speeds of two ants are the same.

At time t0, two ants are in the nest, and there are two ways to choose between them, namely AB or AC. Two ants choose randomly. We assume that ant 1 chooses path AC, and ant 2 chooses path AB.

At time t1, ant 1 walks to point C, and ant 2 walks to point B, where the food is located. They release pheromones on their path, which is indicated by dotted lines on the way. Ant 2 then transports the food to the ant nest and is still releasing pheromones along the way, while Ant 1 heads from point C to point B.

At time t2, ant 2 reached point A of ant nest, and ant 1 reached point B where the food was. At this time, ant 2 set out to carry food again. It found that the pheromone concentration on the AB path was higher than that on the AC path. Pheromone concentration (there are two dotted lines on the AB path and only one dotted line on the AC path). Therefore, Ant 2 chooses the AB path to carry food, and Ant 1 gets the food at point B and then returns to the ant nest. However, it also has two options, one is to return on the same route, and the other is to follow the route AB. Ant 1 finds that the pheromone concentration on the AB path is higher than the pheromone concentration on the AC path, so it will choose AB to return to the nest.

In this way, the pheromone concentration of the AC path will be lower and lower, and the pheromone concentration of the AB path will be higher and higher, so there will be no ants on the AC path to pass again, and both ants will only choose the shorter path AB Line to carry food.

Second, the source code

%% 清空环境
clc;clear
 
%% 障碍物数据
position = load('barrier.txt');
plot([0,200],[0,200],'.');
hold on
B = load('barrier.txt');
xlabel('km','fontsize',12)
ylabel('km','fontsize',12)
title('二维规划空间','fontsize',12)
%% 描述起点和终点
S = [20,180];
T = [160,90];
plot([S(1),T(1)],[S(2),T(2)],'.');
 
% 图形标注
text(S(1)+2,S(2),'S');
text(T(1)+2,T(2),'T');
 
%% 描绘障碍物图形
fill(position(1:4,1),position(1:4,2),[0,0,0]);
fill(position(5:8,1),position(5:8,2),[0,0,0]);
fill(position(9:12,1),position(9:12,2),[0,0,0]);
fill(position(13:15,1),position(13:15,2),[0,0,0]);
 
% 下载链路端点数据
L = load('lines.txt');
 
%% 描绘线及中点
v = zeros(size(L));
for i=1:20
    plot([position(L(i,1),1),position(L(i,2),1)],[position(L(i,1),2)...
        ,position(L(i,2),2)],'color','black','LineStyle','--');
    v(i,:) = (position(L(i,1),:)+position(L(i,2),:))/2;
    plot(v(i,1),v(i,2),'*');
    text(v(i,1)+2,v(i,2),strcat('v',num2str(i)));
end
 
%% 描绘可行路径
sign = load('matrix.txt');
[n,m]=size(sign);
 
for i=1:n
    
    if i == 1
        for k=1:m-1
            if sign(i,k) == 1
                plot([S(1),v(k-1,1)],[S(2),v(k-1,2)],'color',...
                    'black','Linewidth',2,'LineStyle','-');
            end
        end
        continue;
    end
    
    for j=2:i
        if i == m
            if sign(i,j) == 1
                plot([T(1),v(j-1,1)],[T(2),v(j-1,2)],'color',...
                    'black','Linewidth',2,'LineStyle','-');
            end
        else
            if sign(i,j) == 1
                plot([v(i-1,1),v(j-1,1)],[v(i-1,2),v(j-1,2)],...
                    'color','black','Linewidth',2,'LineStyle','-');
            end
        end
    end
end
path = DijkstraPlan(position,sign);
j = path(22);
plot([T(1),v(j-1,1)],[T(2),v(j-1,2)],'color','yellow','LineWidth',3,'LineStyle','-.');
i = path(22);
j = path(i);
count = 0;
while true
    plot([v(i-1,1),v(j-1,1)],[v(i-1,2),v(j-1,2)],'color','yellow','LineWidth',3,'LineStyle','-.');
    count = count + 1;
    i = j;
    j = path(i);
    if i == 1 || j==1
        break;
    end
end
plot([S(1),v(i-1,1)],[S(2),v(i-1,2)],'color','yellow','LineWidth',3,'LineStyle','-.');
 
 
count = count+3;
pathtemp(count) = 22;
j = 22;
for i=2:count
    pathtemp(count-i+1) = path(j);
    j = path(j);
end
path = pathtemp;
path = [1     9     8     7    13    14    12    22];
 
%% 蚁群算法参数初始化
pathCount = length(path)-2;          %经过线段数量
pheCacuPara=2;                       %信息素计算参数
pheThres = 0.8;                      %信息素选择阈值
pheUpPara=[0.1 0.0003];              %信息素更新参数
qfz= zeros(pathCount,10);            %启发值
 
phePara = ones(pathCount,10)*pheUpPara(2);         %信息素
qfzPara1 = ones(10,1)*0.5;           %启发信息参数
qfzPara2 = 1.1;                      %启发信息参数
m=10;                                %种群数量
NC=500;                              %循环次数
pathk = zeros(pathCount,m);          %搜索结果记录
shortestpath = zeros(1,NC);          %进化过程记录
 
%% 初始最短路径
dijpathlen = 0;
vv = zeros(22,2);
vv(1,:) = S;
vv(22,:) = T;
vv(2:21,:) = v;
for i=1:pathCount-1
dijpathlen = dijpathlen + sqrt((vv(path(i),1)-vv(path(i+1),1))^2+(vv(path(i),2)-vv(path(i+1),2))^2);
end
LL = dijpathlen;
 
 
 
figure;
plot(1:NC,shortestpath,'color','blue');
hold on
% plot(1:NC,dijpathlen,'color','red');
ylabel('路径总长度');
xlabel('迭代次数');

Three, running results

Insert picture description here
Insert picture description here

Four, remarks

Add QQ912100926 for complete code or writing.
Review >>>>>>
[Path Planning] Particle Swarm Optimization Algorithm for 3D UAV Path Planning [Matlab 012]
[Path Planning] Genetic Algorithm for Open Vehicle Path Planning for Multiple Logistics Centers [Matlab 013]
[Path planning] Robot grid path planning based on particle swarm algorithm [Matlab 014]
[Path planning] Ant colony algorithm to solve the shortest path [Matlab 015]
[Path planning] Immune algorithm for logistics center location selection [Matlab 016]
[Path planning] Three-dimensional path planning for drones
based on artificial bee colony [Matlab 017] [Path planning] Genetic algorithm for robot path planning based on grid map [Matlab 018]
[Path planning] Ant colony algorithm for multiple drones Attack scheduling [Matlab 019]
[Path planning] Genetic algorithm based on grid map robot optimal path planning [Matlab 020]
[Path planning] Genetic algorithm for multi-UAV cooperative target allocation modeling considering the allocation order [ Matlab 021 issue]
[path planning] ant colony algorithm multi-center vrp problem [Matlab 022]
[path planning] ant colony algorithm to solve multi-center VRP with time window [Matlab 023 issue]
[path planning] many genetic algorithms Central VRP solution [Matlab 024]
[Path planning] Simulated annealing to solve the VRP problem [Matlab 025]
[Path planning] A star grid path planning [Matlab 026]
[Path planning] Based on a two-way cross factor Optimizing particle swarm grid map path planning [Matlab 027]
[Path Planning] [TSP] Ant Colony Algorithm for Solving TSP Problem with GUI [Matlab 028]
[Path Planning] Ant Colony Algorithm for Raster Map Path Planning [Matlab 029]
[Path Planning] Genetic Algorithm for Traveling Salesman TSP [ Matlab Issue 030]
[Path Planning] Traveling Salesman TSP Problem of Simulated Annealing Algorithm [Matlab 031]
[Path Planning] Smart Car Path Planning of Ant Colony Algorithm [Matlab 032]
[Path Planning] Huawei Cup: UAV based on matlab Optimized application in emergency rescue and disaster relief [Matlab 033]
[Path planning] MATLAB's minimum cost and maximum flow calculation problem [Matlab 034]
[Path planning] A* algorithm to solve the three-dimensional path planning problem [Matlab 035]
[Path planning] People Path planning of worker bee colony algorithm [Matlab036 period]
[Path planning] Path planning of artificial bee colony algorithm [Matlab 037]
[Path planning] Ant colony algorithm for multi-travel sales MTSP problem [Matlab 038]
[Path planning] Ant UAV path planning based on group algorithm [Matlab 039]

[[Path Planning] Genetic Algorithm for Solving Multiple VRP Problems [Matlab 040]](https://blog.csdn.net/m0_54742769/article/details/113091004
[VRP] Genetic Algorithm for Vehicle Routing Problem with Time Window [ Matlab 041]

Guess you like

Origin blog.csdn.net/m0_54742769/article/details/113104776