ERA*: Enhanced Relaxed A* algorithm for Solving the Shortest Path Problem in Regular Grid Maps

This paper introduces a novel algorithm for solving the point-to-point shortest path problem in a static regular 8-neighbor connectivity (G8) grid. This algorithm can be seen as a generalization of Hadlock algorithm to G8 grids, and is shown to be theoretically equivalent to the relaxed $A^*$ ($RA^*$) algorithm in terms of the provided solution's path length, but with substantial time and memory savings, due to a completely different computation strategy, based on defining a set of lookup matrices. Through an experimental study on grid maps of various types and sizes (1290 runs on 43 maps), it is proven to be 2.25 times faster than $RA^*$ and 17 times faster than the original $A^*$, in average. Moreover, it is more memory-efficient, since it does not need to store a G score matrix.


Introduction
The shortest path problem is a well-established and important problem that finds applications in various fields, including robotics (Zhang et al. (2018), Koubâa et al. (2018)), VLSI design (Udgirkar and Indumathi (2016)), wireless sensor networks (Radi et al. (2012)), and transportation (Bast et al. (2016), Zhu and Levinson (2015)).This problem can be represented either on a grid or a more general graph, with different techniques employed for each representation.Grid-based approaches are commonly favored in scenarios like extensive VLSI design, particularly when there are numerous obstacles to navigate around.
Traditionally, two types of methods have been used to address the global path planning problem.The first type is exhaustive search, which involves thorough exploration of the entire search space to find the optimal solution.Examples of exact search algorithms commonly used for this purpose include Dijkstra's algorithm ((Dijkstra (1959), Dijkstra (2022))) and A * algorithm (Hart et al. (1968)).
These algorithms guarantee finding the shortest path but may become impractical when dealing with large grids due to their computational complexity.
The second type is local search, which employs metaheuristic algorithms to explore only a portion of the search space.These algorithms, such as Tabu Search (Châari et al. (2014)), Ant Colony Optimization (Ajeil et al. (2020)), Genetic Algorithm (Alajlan et al. (2013)), Particle Swarm Optimization (Phung and Ha (2021); Huang et al. (2023)), and their multiple variants, provide approximate solutions and are often used when the exhaustive search is not feasible due to the large size of the grid.By exploring a limited subset of the search space, local search algorithms can find reasonably good solutions efficiently.
Recently, some relaxed alternatives of exhaustive search algorithms have emerged.These approaches aim to find a balance between the constraint of achieving optimality in path length and the need for faster search times.The work being discussed here falls into this category.It is demonstrated that the proposed Enhanced Relaxed A * (ERA * ) algorithm is theoretically equivalent to the relaxed A * (RA * , Ammar et al. (2016)) algorithm in terms of the path length of the solutions it provides.However, it achieves significant savings in terms of time and memory requirements by employing a completely different computation strategy.
By relaxing the constraint of path length optimality to some extent, this approach manages to expedite the search process while still delivering solutions that are comparable in terms of path length to those obtained through the RA * algorithm.The key advantage lies in the adoption of a novel computation strategy based on lookup matrices.These matrices store precomputed values that can be efficiently accessed during the search, eliminating the need for redundant calculations and resulting in substantial time and memory savings.
The remaining of this paper is organized as follows: Section 2 discussed the most relevant related works.Section 3 presents the proposed ERA * algorithm and proves its equivalence to RA * in terms of path cost.Section 4 presents the results of the evaluation of ERA * on a benchmark of representative grid maps, and compares it to A * and RA * in terms of path cost and execution time.Finally, section 5 concludes the paper and suggests some future works.

Related Works
Shortest path algorithms are a crucial tool in the field of computer science and are used to solve a wide range of problems.In general, point-to-point shortest path algorithms work by starting at a source node and exploring the neighboring nodes until they reach the destination node.Along the way, the algorithm keeps track of the shortest distance from the source to each node, using this information to guide the search and ensure that the shortest path is found.There are a variety of shortest path algorithms that have been developed for finding the shortest path between two points in a regular grid (Panda and Mishra (2018)).These algorithms typically involve searching through the grid to identify the optimal path, taking into account factors such as the cost of moving from one cell to another and any obstacles that may be present in the grid.
One of the most popular and well-known shortest path algorithms for regular grids is Dijkstra's algorithm, which was first proposed by Dutch computer scientist Edsger Dijkstra (Dijkstra (1959), Dijkstra (2022)).Dijkstra's algorithm is a general-purpose algorithm that can be used to find the shortest path between any two points in a weighted, directed graph.It is based on the idea of building a "shortest path tree" from the source point to all other points in the grid, with the shortest path to each point being the minimum sum of the weights of the edges along the path.Although Dijkstra's algorithm is relatively simple and easy to implement, it has a time complexity of O(|E| + |V|log|V|) when using a suitable data structure (Fibonacci heaps), where |E| is the number of edges in the graph and |V| is the number of vertices.This makes it less efficient for larger grids.
Another popular shortest path algorithm for regular grids is A * Hart et al. (1968), which was proposed as an improvement of Dijkstra's algorithm.A * is a heuristic search algorithm that uses a combination of a best-first search and a cost-estimation function to guide the search towards the goal.Unlike Dijkstra's algorithm, which considers all paths from the source to the goal, A * only considers paths that are likely to lead to the goal, based on the cost-estimation function.This makes A * more efficient than Dijkstra's algorithm for many grid-based problems, although the performance of A * can be sensitive to the choice of cost-estimation function.Lee (1961) proposed the first Maze-solving algorithm that is based on targetdirected grid propagation and is memory-efficient.It was extensively employed in the field of printed circuit board design for finding wire paths.However, Rubin (1974) later revealed that the original claim of the algorithm's generality regarding the path cost function is incorrect.
More recent shortest path algorithms for regular grids include the Jump Point Search (JPS) algorithm, proposed by Harabor and Grastien (2011) as an improvement over A * in grid maps.It is based on a selective node expanding process that specifically identifies and expands certain nodes in the grid map, referred to as jump points.Thus, intermediate nodes along a path between two jump points are not expanded at all, which enhances the speed of A * search by an order of magnitude.Hadlock (1977) proposed the Minimum Detour (MD) algorithm in G4 regular grids.Its main idea is to calculate the detour number d(P), defined as the number of nodes on the path P that are directed away from the goal.Then, the path length is calculated as M(S,G) + 2d(P), where M(S,G) is the Manhattan distance between the start S and the goal G nodes.This is because any move opposed to the direction of the goal necessarily needs to be compensated to reach the goal.Since M(S,G) is constant for a given (S,G) pair, minimizing the path length is equivalent to minimizing the detour number.Nodes that have lower detour numbers are given higher priority in the grid expansion process, in a breath-first search style.Since then, no similar algorithm has been proposed in G8 grids, because the detour computation is not as simple as in G4 grids.This paper proposes to bridge this gap by introducing a Hadlock-inspired algorithm applicable to G8 grids.
Relaxed Dijkstra and Relaxed A * (RA * ) algorithms proposed by Ammar et al. ( 2016) exploit the grid-map structure to establish an accurate approximation of the optimal path, without visiting any cell more than once.The path length is approximated in terms of number of moves on the grid.This approach distinguishes itself from previous bounded relaxation algorithms of A * (Pohl (1970); Pearl (1984); Pohl (1973); Köll and Kaindl (1992)) primarily by performing relaxation on the exact cost, denoted as g, of the evaluation function f (where f = g + h).This sets it apart from existing relaxations of the A * algorithm, which typically focus on relaxing the heuristic h.The current work proposes aims to further accelerate the execution of the RA * algorithm by completely changing its computing paradigm, drawing inspiration from the Hadlock algorithm.
It is worth noting that path planning in a grid map can be substantially accelerated in a completely different way by building connection graphs before applying a search algorithm (Zheng et al. (1996)).Nevertheless, the fact that the proposed ERA * algorithm does not construct connection graphs is a significant advantage in many cases.For instance, in large VLSI design problems with a high number of obstacles, the construction of the entire connection graph could be extremely costly.

Methodology
The proposed algorithm is based on calculating detour penalties that are propagated from the source node S to the the goal node G.For a given current node C, we define: • α: the angle between the x-axis and the − − → CG vector.
, where x G and x C are the abscissas of the goal node and the current node, respectively.
• ∆ y = y G − y C , where y G and y C are the ordinates of the goal node and the current node, respectively.Figure 1 clarifies the definition of the variables α, ∆ x , and ∆ y on an example.Figure 2 presents the five first matrices of incremental detour penalty for α ∈ [0 • , 90 • ].These 3x3 matrices store the incremental detour (penalty) from the goal expressed as: Where h is the shortcut distance to goal (shortest path assuming there are no obstacles, see figure 1).
Figure 2: Incremental detour penalty lookup matrices for angles between the current node and the goal node from 0°to 90°.The remaining cases can be obtained from the above cases, using simple 90°rotations of the 3x3 matrix.NE, SE, and NW stand for Northeast, Southeast, and Northwest, respectively.These incremental penalties are added when propagating the total penalty the source node to the goal node.
The value of some penalties, which are denoted as NE (North-East), SE (South-East), and NW (North-West), depend on the value of ∆ x and ∆ y .For instance, in case (a), corresponding to α = 0 (C and G on the same row, with G on the right, so that the optimal path between them is equal to ∆ x ), if ∆ x = 1, it means that the goal is adjacent to the current node on its right.Consequently, if we move towards NE or SE, we will reach the goal with a minimum cost of √ 2 + 1 instead of just 1 for the optimal path between C and G.That is why the penalty is √ 2. Whereas, for all other values of ∆ x > 1, if we move towards NE, we can return back to the row containing G with a total cost of 2 √ 2 instead of 2 for the optimal path.That is why the penalty is 2 √ 2 − 2. Obviously, the case ∆ x < 1 cannot correspond to angle α = 0.The reasoning is similar for the other cases.
Notice that the matrix (e) can be obtained from the matrix (a) by applying a 90°anti-clockwise rotation and substituting ∆ x for ∆ y in the formulas of NE/SE that becomes NW/NE.Likewise: • (g) α = 135 • : is obtained from (c) by applying a 90°anti-clockwise rotation.
In total, we have 28 fixed 3 × 3 matrices (counting the cases of different ∆ x and ∆ y values), that we store before running the search algorithm.
As in Hadlock (1977), nodes that have lower detour numbers are given higher priority in the grid expansion process.This process proceeds until the goal position is reached.Then the path is reconstructed backwards from the goal cell, by moving from each cell to its parent cell that expanded it, until the starting cell is reached.
Instead of two matrices (actual cost g and combined score f ) as in A * and RA * , only one matrix of detour penalties (D) is stored in memory.At a give node n i , the detour value can be calculated recursively, using the euclidean distance dist and the heuristic function h (shortcut distance), as: With: Therefore: Consequently, since h(n 0 ) is constant, optimizing D is equivalent to optimizing f .
Algorithm 1 presents the main steps for path exploration in ERA * .The algorithm takes as input a grid represented by a 2D matrix (map) where obstacles are marked with a predefined value, and the coordinates of the start (S) and goal (G) nodes.It calculates the penalty matrix D with a finite value for all explored nodes.The algorithm stops when the node exploration reaches G, or when a predefined maximum number of iterations is reached.We first store the 28 3 × 3 incremental penalty matrices (see Figure 2), and initialize the priority queue I of expanded nodes to the start node S with associated penalty 0 (line 4).The penalty matrix D and the Predecessor matrix P (used for path reconstruction) are both initialized with default infinity values (lines 6-8), except for the penalty associated with S which is initialized to 0 (line 10).Then, we iterate over the priority queue I by dequeuing each time the node that has the minimum penalty value D(i, j).Based on the value of ∆x and ∆y between this current node C and the goal node, Choose the correct (3 × 3) D i penalty matrix matP according to the relative value of ∆x and ∆y J = {(i, j, D(i, j)) | (i, j) = N ∈ map, N neighbor of C, N is not an obstacle, and D(i, j) = +∞} foreach (i P , j P , D(i P , j P )) in J do end we choose the corresponding incremental penalty matrix D i .This choice is accomplished through a series of if statements where the most likely cases (e.g., inequalities such as ∆y ≥ 1) are placed before less likely cases (e.g., equalities such as ∆x = 0), in order to optimize execution time.We define J (line 16) as the set of all free (i.e., non-obstacle) neighbor nodes of C for which the penalty value D(i, j) is infinite (i.e., has not been calculated yet).For each node in J, we save its predecessor C in the P matrix (line 17) for later path reconstruction, and we calculate its penalty value D(i P , j P ) as the sum of the current node's penalty plus the corresponding incremental penalty in the 3 × 3 D i matrix (line 18).Then, we enqueue J in I (line 21), where the priorities correspond to the D values.If there is a path between S and G, G will be reached and its penalty value calculated, unless the predefined maximum number of iteration is attained.
Once Algorithm 1 reaches the goal G, Algorithm 2 is used to reconstruct the path backward.It takes as input the penalty matrix D and predecessors matrix P that were both generated in Algorithm 1, and the start and goal coordinates on the grid.If D(i G , j G ) +∞ (line 1), it means that Algorithm 1 has reached the goal and a path from S to G has been found.The path reconstruction algorithm starts from the goal (i G , j G ) (line 3), and prepends the current node's predecessor to the path at each iteration (line 14), while adding 1 (for horizontal and vertical moves) or √ 2 (for diagonal moves) until it reaches the start node S. Alternatively, we can count the number of diagonal moves, and multiply it by √ 2 only at the end to avoid accumulating numerical inaccuracies.

Dataset
The simulation study was performed using Matlab R2012a on a laptop with an Intel Core i7 processor (2.4 GHz) and 16 GB of RAM.The evaluation of the algorithms was based on the same benchmark used in Ammar et al. (2016), which is composed of four categories of maps: • 26 maps with randomly placed rectangular obstacles of various obstacle sizes and ratios, ranging from 100 x 100 to 2000 x 2000 in size.
• 6 mazes with passages of different sizes, all 512 x 512 in size, with variable corridor size.
• 4 room maps (512 x 512) filled with random square rooms of variable size.
• 6 maps from video games and 1 real-world map (Willow Garage), ranging from 512 x 512 to 1024 x 1024 in size and selected for their varying levels of difficulty.
Algorithm 2: path reconstruction algorithm input : D: penalty matrix // Output from Algorithm 1 P: Predecessors matrix // Output from Algorithm 1 (i S , j S ): coordinates of the Start node S on the grid (i G , j G ): coordinates of the Goal node G on the grid output: path: near-optimal path between S and G length: length of the near-optimal path between S and G f ail : True if no path has been found We designed and generated the first category of random maps, while the other three categories (mazes, rooms, and video games) were selected from a large set of benchmarking maps provided by Sturtevant (2012).For each map, we conducted 30 runs with randomly selected start and goal nodes each time.Thus, the total number of runs is 1290 (43 maps × 30) for each algorithm.
We compared the proposed ERA * algorithm to the original A * t (A * using path tie-breaks) and to RA * wot (Relaxed A * without using path tie-breaks) which was proven in Ammar et al. (2016) to provide the best tradeoff between path cost and execution time among the tested relaxed variants in G8 grids.

Results
Two main performance metrics are considered to evaluate the three global planners: • The path length: it represents the length of the shortest global path found by the planner.
• The execution time: time spent by an algorithm to find its best (or optimal) solution.Table 1: Percentage of exact optimal paths (when a path exists) per environment, for the three tested algorithms.
Table 1 shows the percentage of optimal paths (when a path exists) for the three tested algorithms, per environment.The original A * provides the optimal in all cases, since no relaxation is applied to it.We observe that ERA * yields a slightly higher rate of optimal paths than RA * wot for random environments of different sizes, a slightly lower rate for rooms and video games, and a markedly lower rate for mazes, in which path lengths are the longest in average, as shown in table 2. This is due to the numerical issues entailed by the incremental computation.Nevertheless, table 3 shows that the percentage of extra length compared to the optimal path remains low at 2.3% in average, and a maximum of 10.4%, which is slightly lower than the maximum extra length produced by RA * wot .When compared to A * , ERA * is 17.13 times faster in average, with a range from 7.27× to 24.3×.Table 5 shows that ERA * has consistently the fastest execution time among the three algorithms in nearly 90% of cases.This superiority applies in all tested grid environments as can be seen in the scatter plots in Figure 4 (randomly generated environments of various sizes) and Figure 5 (structured environments) which compare ERA * and RA * wot in the Cost/Time space.These two figures also show that the range of path length for the two algorithms is similar.Figure 6 depicts the box plot of the ratio between the execution time and the optimal path for the three algorithms.It shows a markedly reduced range for ERA * and RA * compared to A * .On a closer scale, Figure 7 shows that ERA * further reduces this range by almost one half compared to RA * .Figure 8 provides a comprehensive evaluation of the performance of the three algorithms by representing them in cost/time space, in terms of average and standard deviation.The aim of this comparison is to evaluate the performance of different algorithms for both the path cost and the execution time.The cost/time space, therefore, shows the trade-off between the cost and time incurred by each algorithm.The evaluation is done based on two metrics: average and standard deviation.The width of each rectangle is proportional to the path cost standard deviation, while the height is proportional to the execution time standard deviation.The average is represented by a star at the center of each rectangle.The figure shows that ERA * provides the best tradeoff between cost and time, a reduced range of execution time, and a range of path cost that is close to RA * 's.
Furthermore, we conducted an analysis on the cost and time performance of the three algorithms on the described set of experiments, using a T-test.The first comparison was between the ERA * and RA * wot algorithms, where the null hypothesis of equal means for time was rejected with a very low p-value of 1.1216e −20 .Whereas, the null hypothesis for cost was accepted with a p-value of 0.91, indicating that the difference in cost between the two algorithms is not statistically significant.The second comparison was between the ERA * and A * t algorithms.Again, the null hypothesis for equal means in time was rejected with a very low pvalue of 1.1002e −35 , indicating that there is a statistically significant difference in time performance between the two algorithms.While the null hypothesis for cost was accepted with a p-value of 0.7607, indicating that the cost difference between the two algorithms is not statistically significant.

Conclusion
In conclusion, this paper introduced a novel algorithm for solving the pointto-point shortest path problem on a static regular 8-neighbor connectivity (G8) grid.The algorithm is a generalized version of the Hadlock algorithm specifically designed for G8 grids.This work falls within the category of relaxed alternative algorithms that balance the trade-off between path length optimality and search time.By relaxing the constraint of path length optimality to some extent, the   while still providing solutions with similar path lengths to those obtained using RA*.The key advantage lies in the novel computation strategy utilizing lookup matrices, which significantly reduces redundant calculations, resulting in substantial time and memory savings.
Experimental results obtained through extensive testing on various grid maps validate the algorithm's effectiveness.On average, it is 2.25 times faster than RA* and 17 times faster than the original A* algorithm.Additionally, it exhibits improved memory efficiency since it eliminates the need for storing a G score matrix.
Future research can focus on exploring further optimizations and extensions of the ERA* algorithm.This could involve investigating its performance in dynamic or uncertain environments, incorporating additional constraints or cost factors, and exploring possibilities for parallelization or distributed computation.Additionally, the algorithm's applicability to other grid types or graph structures can be explored.The insights gained from this work lay the foundation for potential advancements in efficient path planning algorithms for various domains and applications.

Figure 1 :
Figure 1: Example showing the angle α between the current node (C) and the goal node (G), ∆ x = x G − x C , ∆ y = y G − y C , and the shortcut distance between C and G, which corresponds to the minimum distance in a G8 grid when there are no obstacles between the two nodes.

Algorithm 1 :
ERA * search algorithm input : map: The whole grid with obstacle information max nb iter: maximum number of iterations (i S , j S ): coordinates of the Start node S on the grid (i G , j G ): coordinates of the Goal node G on the grid output: D: penalty matrix nb iter: number of iterations to find the near-optimal path nb iter = 0 f ail = False Store the 28 (3 × 3) D i penalty matrices // See Fig.2 and eq.1 I = [(i S , j S , 0)] // Priority queue of expanded nodes // Initialization of the distance matrix D and the predecessors matrix P on the map: foreach node in map do D(node) = +∞ P(node) = +∞ end D(i S , j S ) = 0 while (D(i G , j G ) = +∞ and nb iter < max nb iter and size(I) > 0) do (i C , j C ) = dequeueMin(I) // C will be the current node , j C ) = (i P , j P ) 14 path.prepend((iC , j C ))

Figure 3 :
Figure 3: Histogram of the execution time ratio between RA * wot and ERA * algorithms.

Figure 4 :
Figure 4: Comparison of execution time between the proposed ERA * (in blue) and RA * wot (in red) algorithms, for different environment sizes (from 100x100 to 2000x2000 nodes), randomly generated.

Figure 5 :
Figure 5: Comparison of execution time between the proposed ERA * (in blue) and RA * wot

Figure 6 :
Figure 6: Box plot of the execution time divided by the optimal path length, for A * , RA * wot

Figure 7 :
Figure 7: Box plot of the execution time divided by the optimal path length, for RA * wot and ERA * algorithms.

Figure 8 :
Figure 8: Comparison between the tested algorithms in cost/time space, in terms of average and standard deviation.The width of each rectangle is proportional to the path cost standard deviation, and its height is proportional to the execution time standard deviation.The average is represented by a star at the center of each rectangle.

Table 2 :
Average path cost per environment size, in cell units.On the other hand, Table4shows the average execution time of each algorithm in each grid environment.ERA * is 2.25 times faster in average than RA * wot .

Table 3 :
Percentage of extra length compared to optimal path, calculated for non-optimal paths over all environments.This ratio varies from 1.74× to 2.47× depending on the type of grid environment.Figure3displays the histogram of this ratio.It shows that RA * wot is faster than ERA * in only very few cases.

Table 4 :
Average execution time (in seconds).

Table 5 :
Percentage of runs for which each algorithm appears in rank 1 to 3, with regards to the execution time.