[Path planning] Genetic algorithm based on grid map robot path planning [Matlab 018]

1. Introduction

Using grids to divide the robot's workspace and then using optimization algorithms to optimize the robot path is a classic problem of using intelligent algorithms to find the optimal path.
The difficulty of using genetic algorithm to process the robot path planning of the grid map mainly includes: 1 to ensure that the path is uninterrupted, and 2 to ensure that the path does not pass through obstacles. When using genetic algorithms to solve optimization problems, the steps are fixed, that is, population initialization, selection, crossover, mutation, and fitness calculation. Then I will talk about the problem of genetic algorithm for robot path planning in raster maps at each step. , Difficulties and solutions.
1.1 Population initialization
First of all, we must know the definition of genetic algorithm population initialization. The genetic algorithm population initialization is to generate a certain population of individuals, and each individual is a feasible solution. It should be noted here that it is a feasible solution. For this problem, it is a feasible path, that is to say, it should be a path from the beginning of the path to the end of the path without passing obstacles. How to initialize the population to obtain a feasible path is the first and most difficult point of the genetic algorithm to find the grid path.
Insert picture description here
1. Method
Path initialization can be divided into two steps: the first step is to generate a path that must pass through nodes. What is a path that must pass through nodes? For example, for a 10*10 grid, the path from number 1 in the lower left corner to number 100 in the upper right corner must pass through a point in row 2, a point in row 3... a point in row 9, this is Obviously, then we randomly select a node in the free grid in the second row, and a node in the free grid in the third row... Take a node in the free grid in the 9th row, then it will be a must The path through points, of course, this path is also intermittent. So the second step is needed. The second step is to connect these discontinuous nodes, and this problem is the most difficult problem in the algorithm, because in the connection path, it is too difficult to bypass obstacles, and if you bypass the obstacles, you will I found that I lost my direction and couldn't even return. Therefore, the midpoint connection method is used in the connection nodes, but the midpoint must be skillfully obtained. You can take 4 or 3 grids at the midpoint, and then find the free grids in these grids, and choose with equal probability. In the worst case, the grids at these midpoints are all obstacles, and one of these grids is selected as the path point with a moderate probability. Therefore, this method ensures the continuity of the path, but there may also be paths passing through obstacles. The path of this obstacle can be penalized in the fitness function. After the two steps of the above initialization path are completed, the simplified path operation is performed, that is, if there are two identical nodes in the path, the section between the same nodes is removed. This is easy to understand.
2. Selection
Selection is the same as the selection of genetic algorithm, no special changes are required, and selection is based on fitness.
3. Crossover
uses repeated point crossover. This is also easier to understand. For example, one path is [1 12 13 24 25 36 45 56] and the other path is [1 14 25 35 46 56]. The two paths have a common Node 25, crossover becomes [1 12 13 24 25 35 46 56] and [1 14 25 36 45 56].
4.
The method of mutation mutation uses random generation to select two nodes and remove the difference between these two nodes. Path, and then use the above-mentioned interpolation method to generate a continuous path.
5. Scoring calculation
The fitness calculates the length of the path and the number of obstacles that pass through, and the sum is enough. This is more intermittent, but I will show the effect of the program I wrote below.

Second, the source code

clc;
clear all;
clear all;
close all;
t=23;       %过程点个数=t-1
s=500;      %种群规模
pc=0.90;    %交叉概率
pm=0.20;    %变异概率
pop=zeros(s,t);
for i=1:s
    pop(i,1:t-1)=randperm(t-1);
end
for k=1:1:2000   %进化代次数k
    if mod(k,10)==1
        k
    end
    pop=qiujuli(pop);
    c=15;%选择淘汰个数
    pop=select(pop,c);
    p=rand;
    if p>=pc
        pop=cross(pop);
    end
    if p>=pm
        pop=mutate(pop);
    end
    
end
pop
​
min(pop(:,t))
J=pop(:,t);
fi=1./J;
[Oderfi,Indexfi]=sort(fi);   %安排fi从小到大
BestS=pop(Indexfi(s),:);    %使BestS=E(m),m即是属于max(fi)的Indexfi
I=BestS;
x=[2 3 6 10 14 17 22 20 23 25 30 28 25 21 29 16 18 15 9 11 6 5 ];
y=[5 26 14 29 27 24 28 22 26 30 30 17 13 15 4 13 3 1 6 2 2 7];
for i=1:1:t-1
    x1(i)=x(I(i));
    y1(i)=y(I(i));
end
x(t)=x(I(1));
y(t)=y(I(1));
a = [1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
    1 1 0 1 1 1 1 1 1 1 0 1 1 1 1 1 1 0 1 1 1 1 0 1 1 1 1 1 1 1
    1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 0 0 0 1
    1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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 1 1 1 1 1 1 0
    1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1
    1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1
    1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
    1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
    1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
    1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1
    1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1
    1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
    0 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1];%31*31栅格
b = a;
b(end+1,end+1) = 0;
colormap([0 0 0;1 1 1]),pcolor(b)
axis image xy;%绘制栅格图
hold on;
figure(1);
plot(x,y,'-or');

Three, running results

Insert picture description here

Four, remarks

Complete code or writing to add QQ912100926 past review
>>>>>>
[Path planning] Particle swarm optimization algorithm for three-dimensional UAV path planning [Matlab 012]
[Path planning] Genetic algorithm for open vehicles in multiple logistics centers Path planning [Matlab 013]
[Path planning] Particle swarm algorithm for robot grid path planning [Matlab 014]
[Path planning] Ant colony algorithm for solving the shortest path [Matlab 015]
[Path planning] Immune algorithm for logistics center Site selection [Matlab 016 period]
[Path planning] Three-dimensional path planning of artificial bee colony drones [Matlab 017 period]

Guess you like

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