1. Introduction
The shortest path problem is a fundamental issue in graph theory, with various types. Depending on whether there are constraints, it can be categorized into unconstrained and constrained shortest path problems. For instance, the Vehicle Routing Problem (VPR) is a typical example of a constrained shortest path problem [
1]. Based on the number of objectives, it can be divided into single-objective and multi-objective shortest path problems. The Traveling Salesman Problem is a classic example of a multi-objective shortest path problem [
2]. Additionally, based on whether the constraints change, it can be classified as static or dynamic shortest path problems, among others. The concept of the shortest path is not limited to physical distance; it can also apply to any quantifiable weight, such as time or cost. In practical applications, many problems can be transformed into shortest path problems for solution.
In path planning, the length of a path is typically the most critical metric, as it directly impacts the cost associated with the path. In general, a shorter path also has fewer waypoints and turns, because the line segments directly connecting the waypoints are the shortest, which means the path is smoother. In robot or vehicle path planning, paths with fewer turns generally consume less energy [
3]. Therefore, finding a shorter, collision-free path is a significant challenge.
Currently, algorithms for solving the shortest path problem can be broadly categorized into classical path algorithms and heuristic path algorithms. Classical path algorithms are primarily used to address small-scale deterministic problems, such as Breadth-First Search (BFS), Dijkstra [
4], and Depth-First Search (DFS). These algorithms excel in solving problems with a unique optimal solution. Heuristic path algorithms, on the other hand, are more commonly used to tackle large-scale complex problems, including Genetic Algorithms (GA) [
5], Ant Colony Optimization (ACO) [
6], and Particle Swarm Optimization (PSO) [
7]. These algorithms are particularly effective in solving problems with multiple constraints and multi-objective issues [
8]. Heuristic algorithms can also be classified into several types based on their principles: population-based algorithms, physics-based algorithms, and evolutionary algorithms [
9,
10,
11].
In recent years, research on the shortest path problem has been prolific. For example, Ref. [
12] models real-world problems as weighted time path graphs and proposes a graph transformation technique based on BFS and Dijkstra’s algorithm to study the shortest time paths in these graphs. Ref. [
13] utilizes the strategy of Dijkstra’s algorithm to propose a baseline algorithm, which combines the lower bound of the shortest path and the lower bound of the multi-path to develop a framework for solving the K shortest path problem, capable of identifying the first k distinct shortest paths in a directed weighted graph. Ref. [
14] introduces a novel genetic algorithm to address the clustering shortest path tree problem (CluSPTP) and tests it on both Euclidean and non-Euclidean instance sets. Ref. [
15] proposes an improved distance-based ant colony optimization path (IDBACOR), incorporating direction information into the pheromone update process and adding a speed factor to the probability calculation, guiding ants to move towards the target point as much as possible, thereby solving the shortest path problem in transportation networks.
However, in the context of two-dimensional obstacle grid maps, some existing algorithms struggle to find optimal solutions. Classic pathfinding algorithms, such as BFS and Dijkstra, are limited to searching in four or eight directions, which means they do not always find the true shortest path (TSP) but rather the shortest grid path (SGP) [
16,
17]. The second chapter of this paper explains the differences between these two types of paths. Heuristic pathfinding algorithms, such as GA, ACO, and PSO, can break through the search direction limitations in close-range scenarios, finding shorter paths than classic pathfinding algorithms. However, when the distance between the start and end points is too large, the efficiency of heuristic pathfinding algorithms significantly decreases, and their solution quality may even fall short of that of classic pathfinding algorithms. Although [
16] has shown that the ratio of SGPs to TSPs is limited within a certain range, as the map expands and the distance between the start and end points increases, there can still be a significant gap between SGPs and TSPs. Previous research has also attempted to overcome the search angle limitations to shorten path lengths. For example, Ref. [
18] proposed a variant of A* algorithm, aimed at finding paths shorter than the SGP. Ref. [
19] introduced an Any-angle pathfinding (Anya) algorithm that focuses on the shortest path between two points in the grid, but it is limited to solving problems involving grid vertices and cannot search for points within the grid. Ref. [
20] applied the Block A* algorithm to game maps to find paths at any angle.
This paper proposes an SGP vertex extraction and filtering algorithm (SGPVEFA), which is an accurate algorithm specially used to solve the true shortest path in two-dimensional obstacle environment. The innovation points of this paper are as follows.
A method is proposed to optimize SGPs into TSPs.
An obstacle grid vertex extraction algorithm based on an equivalent path is proposed.
An obstacle vertex set screening method based on an improved dynamic optimization algorithm is proposed.
Subsequent experiments have confirmed that SGPVEFA can efficiently optimize SGPs to TSPs, regardless of the map size or the distance between the starting and ending points. Compared to other algorithms, the paths found by SGPVEFA are shorter and contain fewer nodes. In long-distance scenarios, the optimization effect of SGPVEFA is particularly significant.
The rest of this paper is organized as follows:
Section 2 details the definition and association of SGPs and TSPs in the obstacle grid map;
Section 3 introduces the obstacle vertex extraction algorithm for SGPs;
Section 4 introduces the TSP points screening method for the obstacle vertex set;
Section 5 conducts simulation experiments on the proposed algorithm; and
Section 6 is a summary.
2. Obstacle Grid Map and True Shortest Path
In robot path planning, constructing a grid map is a common method that helps identify the surrounding environment and make movement decisions. The grid map can be pre-built before path planning and remains unchanged during subsequent planning, known as static environment construction. Alternatively, it can be updated in real-time as the path planning progresses, known as dynamic environment construction. The grid map method is widely used due to its simplicity, intuitiveness, and ease of implementation.
While the grid method can help construct environmental maps, real-life obstacles are not always regular shapes. To prevent collisions, we can directly overlay the grid map onto the obstacles and set the grids that fully or partially occupy the obstacles as obstacle grids, as shown in
Figure 1. However, this rough approach may lack precision, leading to longer planned paths. To address this, we can enhance accuracy by increasing resolution [
21], thus better simulating real obstacle environments, as illustrated in
Figure 2. We can increase the resolution until it falls within an acceptable error range. Therefore, the obstacle grid maps mentioned in the following sections refer to regular obstacle environments.
Additionally, it is important to note that in some studies, the behavior of a path passing through the common point of two obstacle grids that share only one common point is considered a valid path. However, this practice is unsafe in real life. Therefore, this paper considers such behavior as illegal. In the subsequent sections of this paper, neither SGPs nor TSPs involve such behavior.
The shortest path problem in obstacle grid maps can typically be solved using various algorithms, such as backtracking, Dijkstra’s algorithm, and dynamic programming. However, these algorithms usually explore only four or eight directions. Due to the limited search directions, the shortest paths found are not TSPs but SGPs. A TSP is the shortest (Euclidean) polyline path from the starting grid to the endpoint grid, which does not intersect with the set of obstacles except at vertices or edges and avoids crossing the common edge of two obstacle grids that share a complete edge. In contrast, an SGP is the shortest path from the starting point to the endpoint through continuous movements in eight directions within the obstacle grid map. As shown in
Figure 3, path
a represents an SGP, while path
b represents a TSP.
In the obstacle grid map, due to the obstacles, it is necessary to take a longer route to reach the destination. Most path search algorithms can only explore in eight directions, which correspond to four grids sharing a common edge and four grids sharing a common point. When the starting point and the endpoint cannot be directly connected by obstacles, the TSP requires moving along the boundaries or vertices of the obstacles. The limitation on search directions results in the difference between SGPs and TSPs. However, searching in all possible directions would require a significant amount of time.
In an obstacle-free map, if the starting point and the endpoint are on the same row or column, SGPs and TSPs are identical. However, when the destination is offset so that it is not on the same row, column, or diagonal as the starting point, a difference between SGPs and TSPs emerges. This is because SGPs can only turn at 45-degree angles, whereas TSPs can turn at any angle. By placing some obstacle grids in the path of TSPs, the movement angles of TSPs are also restricted. TSPs can no longer move directly from the starting point to the endpoint, but must navigate around obstacles by using their vertices or edges.
Although searching in any direction is too costly, searching for SGPs is very easy, and there is a connection between SGPs and TSPs. Since SGPs are the shortest paths limited to eight directions of movement, TSPs are the shortest paths allowed to move in any direction. The routes and grids traversed by SGPs and TSPs are largely the same when navigating obstacles. We also observed that SGPs navigate obstacles by making multiple diagonal movements, which, after translation, intersect with the obstacle at a series of vertices. The lines connecting these vertices form the TSP, as shown in
Figure 4. Therefore, we propose the following conjecture: TSPs consists of a subset of obstacle vertices that intersect the equivalent path (described in
Section 3.2) of SGPs with obstacles.
Therefore, this paper proposes an SGP vertex extraction and filtering algorithm (SGPVEFA) based on this hypothesis. This algorithm extracts the obstacle vertices that the SGP passes through by constructing equivalent paths and models them into a chain structure. Then, it is filtered by an improved dynamic programming algorithm. It has been verified that the path searched by SGPVEFA is consistent with the TSP. The overall flow chart of SGPVEFA is shown in
Figure 5.
3. Obstacle Vertex Extraction Algorithm Based on Equivalent Path
3.1. Problem Modeling
Let
be an
grid graph containing a set of obstacles
and a set of passable grids
.
is one grid in
, that is,
, and
,
. In
, there is an SGP
that passes through n nodes from the starting point
to the endpoint
. Here,
represents the grid center at the x-th row and y-th column in
, and
can be obtained by moving one step in any of the eight directions from
. The objective function is the total path length
of S, which can be calculated by Formula (1).
The following constraints must be satisfied for Formula (1):
That is, all nodes must not cross the boundary.
That is, every move is an eight-direction move.
That is, there can be no loops in the path.
The requirement is to extract the set of obstacle vertices from .
3.2. Equivalent Path
Assuming that in the grid graph , under the condition that only eight directions are allowed to move, the shortest path from the starting point B to the end point E requires axial movements and oblique movements, then the relative order of these movements can be adjusted arbitrarily without affecting the arrival at the destination. In this paper, these paths are called equivalent paths.
The continuous eight-directional movement path in an obstacle grid can be decomposed into several combinations of equivalent paths. As shown in
Figure 6, the continuous eight-directional movement path from grid B to grid E can be divided into three segments. Segments
a and
c each have two combinations of paths that are equivalent to each other, while segment
b can be considered a special equivalent path with one combination of paths.
3.3. Obstacle Vertex Extraction Algorithm (OVEA)
The trajectory of the SGP varies depending on the distribution of obstacles. Directly searching for all obstacle vertices traversed by the SGP is extremely challenging, so it is necessary to break down the SGP. The eight-directional movement can be categorized into two types: movement along the coordinate axes (referred to as axial movement) and movement along the diagonal (referred to as oblique movement). Axial movement does not involve passing through obstacle vertices, whereas diagonal movement might. Therefore, when extracting obstacle vertices, the focus should be on the diagonal movements in the SGP.
We also observed that in the SGP, there are three possible continuous movements: axial–oblique movement, oblique–axial movement, and oblique–oblique movement (axial–axial movement can be optimized at turns, which contradicts the definition of SGP). This implies that in SGPs, at least one of any two consecutive movements is an oblique movement. Based on this observation, we sequentially decompose a complete SGP into these three types of movement combinations and perform obstacle vertex extraction for each pair of consecutive movements.
3.3.1. Axial–Oblique Movement
It is assumed that in an SGP, from grid B to grid M, there are k consecutive axial moves
and l consecutive oblique moves
, where the starting point of
is
, and the endpoint is
. For each oblique move, we attempt to translate in the opposite direction of the axial move to construct an equivalent path. We continue until we encounter an obstacle vertex or reach the extension of the previous equivalent path, as illustrated in
Figure 7.
Assuming the starting point of after translation is at the grid and the endpoint is at the grid , we will sequentially check the four grids: , , , and . If only one of these four grids is an obstacle, we conclude that has stopped due to touching an obstacle vertex. If equals , we conclude that has stopped because it has moved to the extension of the previous equivalent path.
After the equivalent path is constructed, for the equivalent path that stops due to touching the obstacle vertex, we add the obstacle vertices it passes in the order of sequence into the TSP candidate point set.
3.3.2. Oblique–Axial Movement
For oblique–axial movement, we can consider it as the reverse of axial–oblique movement. Due to the reversibility of the path, the obstacle vertices encountered during a forward and backward movement along an SGP are the same. Suppose in an SGP, from grid B to grid M, there are k consecutive oblique movements
and l consecutive axis movements
. By reversing this sequence, the path is transformed into one from grid M to grid B:
, as shown in
Figure 8. The method for axial–oblique movement described in 3.3.1 can then be applied to extract the obstacle vertices encountered and add them to the candidate point set in reverse order.
3.3.3. Oblique–Oblique Movement
For the oblique–oblique movement, we can consider it as a sequence of oblique–axial–oblique movement. The first part of the oblique–axial movement should be reversed according to the strategy outlined in
Section 3.3.2 to construct the equivalent path. Since there are no axial movements, the equivalent path for the entire segment is the original path itself. Similarly, the equivalent path for the second part of the axial–oblique movement is also the original path itself, as shown in
Figure 9.
Therefore, for oblique–oblique movement, we only need to record the obstacle vertices that pass through it and add them to the candidate points set.
The pseudocode of the obstacle vertex extraction algorithm is shown in Algorithm 1.
Algorithm 1. Obstacle Vertex Extraction Algorithm |
Initialize map, ; For Every two continuous movement of S in different directions Determine the type of two movements; IF they are Axial—oblique For i = 1 to n While did not touch any obstacles AND Move in the opposite direction along the straight movement; END While IF There is only one obstacle grid in (), (), (), () IF candidate point set contains (,); Update the position of (,); ELSE Add (,) to the candidate point set; END END IF END For ELSE IF they’re oblique—Axial Flip the path; Extract obstacle vertices using the Axial—Oblique method; Add obstacle vertices in reverse order to the candidate point set; ELSE Add obstacle vertices to the candidate points set; END IF END For |
4. Path-Smoothing Method Based on an Improved Dynamic Programming Algorithm
After extracting all the obstacle vertices that the SGP has passed, not all of these points are included in the TSP. Some points may be non-adjacent but directly connectable, as illustrated in
Figure 10c. Therefore, the original problem is transformed into a process of screening the candidate point set, removing points outside the TSP to achieve a smoother path.
Since obstacle vertices are added to the candidate points set by translating and touching obstacles, and these points are added in the order of the SGP, adjacent candidate points can be directly connected. Thus, the points in the candidate point set form a data structure similar to that shown in
Figure 11, where all points form a one-way linked list according to their insertion order. Since some path points may be directly connectable, there might be shorter direct connections between some path points.
4.1. Problem Transformation Modeling
It is known that the set of candidate points with length
is
. A subsequence
was found in
with a length
such that Formula (5) holds.
P and Q should satisfy the following constraints:
That is,
is a subset of
.
where
represents the straight-line distance between
and
,
and
can be directly connected.
That is, the path length of the branch is not greater than that of the main chain.
4.2. Improved Dynamic Programming Algorithm
Lemma 1. If is the shortest path from to , then for any two nodes and in this path, the sub-path is also the shortest path from to .
The following proves the feasibility of using dynamic programming algorithm for this problem.
Proof. Since is a TSP from to , Lemma 1 indicates that has the property of optimal substructure. If there is a common point in , , and , then the subsequence of forms a TSP from to , and the subsequence of forms a TSP from to . According to the definitions of and , is a subsequence of , and is a subsequence of . This means that the optimal solution to this problem can be broken down into the optimal solutions of these subproblems. Therefore, this problem also possesses the property of optimal substructure, and it can be solved using dynamic programming algorithms. □
Since this problem not only requires obtaining the path length but also storing the shortest path, an additional array is needed during the dynamic programming process to record the historical optimal paths. However, as the algorithm runs, the number of nodes in the historical optimal paths increases, causing the array’s length to vary, which is not conducive to pre-allocating space. Moreover, when the problem scale is large, a significant amount of storage space is required for these paths. To address this issue, we leverage the characteristic of the optimal substructure of candidate point sets by setting up an auxiliary array that stores the indices of predecessor nodes instead of the paths themselves, as shown in
Figure 12.
It is also noted that the set of candidate points has the following properties:
Property 1. The subsequent adjacent points of a point in the candidate set extracted by SGPs are continuous in the candidate set.
Proof of Property 1. Suppose that in the candidate set of a certain SGP, the subsequent adjacent points of a point are discontinuous in the set. That is, there exists a continuous subsequence , where are adjacent points, A and C are not adjacent, D is a subsequent candidate point of C, and A and D are adjacent.
Since
and
are not adjacent points, the line connecting
and
must pass through an obstacle or a common vertex of two obstacle grids. Connect point A to the boundary point of the obstacle to form two lines
a and
b, as shown in
Figure 13. Since
and
are adjacent,
must be located outside lines
a and
b. If
is on the outside of line
a, because
and
are adjacent, line
will not pass through the obstacle or the wall gap (which is considered illegal in this context). This means there is a shorter SGP between
that does not need to bypass the obstacle between
, which contradicts the definition that the SGP should be the shortest eight-directional movement path. Similarly, if
is on the outside of line
b, there is also a shorter SGP, leading to another contradiction. Therefore,
and
are not adjacent points, and
Property 1 holds. □
From Property 1, we can deduce the following.
Inference 1. For any two nodes and in the candidate point set , where the set of pre-adjacent points of is and the set of pre-adjacent points of is , if , then .
Proof of Inference 1. Assume and According to Property 1, the set of adjacent points after is , and the set of adjacent points after is {}(l ≥ j). Since and , it follows that , so and are adjacent points. Furthermore, since , , which contradicts . Therefore, Inference 1 holds. □
Inference 1 indicates that the boundary of the set of preceding adjacent points for a path point will shift backward as the point moves through the candidate point set. Therefore, a sliding window can be used to optimize dynamic programming algorithms, thereby enhancing their efficiency. The sliding window defines the range of the preceding adjacent points and gradually advances toward the endpoint during the loop.
The flow chart of the optimized dynamic programming algorithm is shown in
Figure 14.
6. Conclusions
This paper introduces an SGP vertex extraction filtering algorithm designed to optimize the SGP in obstacle grid maps into the TSP. This algorithm can find a shorter and smoother route than intelligent path planning algorithms within a short time frame. In scenarios involving large-scale maps and high obstacle densities, the performance of SGPVEFA is particularly outstanding.
From the ablation experiments in
Section 5.2 of the paper, it is evident that SGPVEFA spends very little time optimizing an SGP into a TSP, with most of its time dedicated to solving the SGP problem. The algorithm’s complexity is determined by the number of points in the given SGP and the distribution of obstacles, rather than the map’s dimensions. Therefore, increasing the map size does not degrade the algorithm’s efficiency, but it does slow down the search for SGPs. However, due to the low coupling degree of SGPVEFA, when dealing with larger problem scales, we can integrate it with heuristic algorithms. First, we used heuristic algorithms to solve SGPs, and then applied this algorithm to solve TSPs.
However, due to the complexity of two-dimensional obstacle grid maps, this paper has not yet provided rigorous proof that this method can solve the TSP. Additionally, SGPVEFA has certain limitations. For example, SGPVEFA requires pre-acquiring the SGP of the obstacle grid map, whereas some heuristic algorithms do not require this step, which may limit its applicability. Moreover, it can only solve problems with obstacle grid maps, and in real-world scenarios, the problem needs to be modeled into a similar situation, which is not an easy task. Furthermore, SGPVEFA is a static algorithm, and obstacles and feasible paths can change over time, necessitating the integration of dynamic response mechanisms. Additionally, the problems we encounter are not limited to two-dimensional planes; for instance, in drone path planning, future research could explore extending SGPVEFA to three-dimensional space. In recent years, many new heuristic techniques have been developed to optimize complex nonlinear problems, such as the Beetle Antennae Olfactory Recurrent Neural Network [
27] and BAS-ADAM [
28]. We will attempt to compare or integrate these new technologies in our future research.