Next Article in Journal
Theoretical Derivation and Optimization Verification of BER for Indoor SWIPT Environments
Previous Article in Journal
Enantioselective Catalytic Synthesis of N-alkylated Indoles
 
 
Font Type:
Arial Georgia Verdana
Font Size:
Aa Aa Aa
Line Spacing:
Column Width:
Background:
Article

Exploiting Obstacle Geometry to Reduce Search Time in Grid-Based Pathfinding

1
Computer Engineering Department, The University of Jordan, Amman 11942, Jordan
2
Electrical Engineering Department, The University of Jordan, Amman 11942, Jordan
*
Author to whom correspondence should be addressed.
Symmetry 2020, 12(7), 1186; https://doi.org/10.3390/sym12071186
Submission received: 23 May 2020 / Revised: 11 July 2020 / Accepted: 15 July 2020 / Published: 17 July 2020

Abstract

:
Pathfinding is the problem of finding the shortest path between a pair of nodes in a graph. In the context of uniform-cost undirected grid maps, heuristic search algorithms, such as A and weighted A ( W A ), have been dominantly used for pathfinding. However, the lack of knowledge about obstacle shapes in a gird map often leads heuristic search algorithms to unnecessarily explore areas where a viable path is not available. We refer to such areas in a grid map as blocked areas (BAs). This paper introduces a preprocessing algorithm that analyzes the geometry of obstacles in a grid map and stores knowledge about blocked areas in a memory-efficient balanced binary search tree data structure. During actual pathfinding, a search algorithm accesses the binary search tree to identify blocked areas in a grid map and therefore avoid exploring them. As a result, the search time is significantly reduced. The scope of the paper covers maps in which obstacles are represented as horizontal and vertical line-segments. The impact of using the blocked area knowledge during pathfinding in A and W A is evaluated using publicly available benchmark set, consisting of sixty grid maps of mazes and rooms. In mazes, the search time for both A and W A is reduced by 28 % , on average. In rooms, the search time for both A and W A is reduced by 30 % , on average. This is achieved while preserving the search optimality of A and the search sub-optimality of W A .

1. Introduction

Grid-based pathfinding has been the subject of considerable interest in a number of fields such as video games and robotics navigation. A [1] is a simple, best-first search algorithm that relies on a heuristic function to guide the search towards finding the optimal path between a source node and a goal node in a grid map. To reduce the execution time of the A algorithm, researchers typically focus on finding new heuristic functions that reduce the number of visited nodes (i.e., search space) during pathfinding.
A is optimal if the used heuristic function is admissible, i.e., never overestimates when predicting the distance to reach the goal [2]. Weighted A ( W A ) [3] relaxes the admissibility rule and multiplies the heuristic function by a factor ϵ > 1 . While doing so might lead to finding sub-optimal paths, inflating the heuristic forces the search algorithm to prioritize exploring more promising paths rather than exploring every possible path to guarantee optimality. For example, Figure 1 compares the number of visited nodes in both A and W A (with ϵ = 3 ) when trying to find the same path in an 8-neighbor grid map of a 199 × 364 maze. Both algorithms use the octile-distance heuristic, which is a commonly-used admissible heuristic function that allows both straight and diagonal movements. As shown by Figure 1c, the greedy nature of W A led it to prioritizing the exploration of the closer nodes to the goal, which resulted in finding a different, sup-optimal path. By contrast, A slowly explores all similar nodes, i.e., nodes with the same cost, to guarantee optimality (as shown by Figure 1b).
W A is a simple yet effective extension of A and is still in wide use to this day [4,5]. However, W A , as well as A , has no knowledge about the geometry of obstacles in a grid map, which could mislead the search into exploring paths with blocked ends. For example, Figure 2a shows twenty two polygon-shaped areas with blocked ends in the maze of Figure 1a. We refer to such shapes as blocked areas (BAs) because they are bound by obstacles from all directions, except for the one direction where the search may enter this area. This paper aims to make knowledge about blocked areas in a grid map available during pathfinding. By doing so, a search algorithm can avoid exploring useless paths inside blocked areas, which in turn reduces search time. For example, Figure 1 shows that both A and W A have wastefully explored most of the blocked areas identified in Figure 2a. By comparison, Figure 2b,c show the potential of using the blocked areas’ knowledge into guiding both search algorithms to avoid exploring blocked areas and thus significantly reducing the number of visited nodes while performing pathfinding.
To make use of the blocked areas’ knowledge, we propose the following approach. First, a preprocessing algorithm investigates the geometry of obstacles in a grid map and identifies blocked areas. Next, information about blocked areas is stored in a memory-efficient balanced binary search tree, referred to as the BA-tree. During actual pathfinding, a search algorithm accesses the BA-tree to determine if a particular node is inside a blocked area. If so, then this node is not explored, i.e., eliminated from the search space.
An important property of our proposed method is that it does not depend on any specific heuristic function. Instead, it utilizes the geometry of obstacles to eliminate irrelevant parts to the search, i.e., in a sense, it reduces a map to a new (more concise) map that a heuristic search algorithm can investigate at a faster speed using its original heuristic function. Therefore, our method is orthogonal to the search algorithm itself, and hence can be combined with many heuristic search algorithms in the literature. As a proof of concept, in this paper, we present and evaluate our proposed method using A and W A search algorithms combined with the octile-distance heuristic. Another important property of our approach is that it preserves the optimality of a search algorithm. We present mathematical proofs of this claim in Section 4.
In addition, our approach has a small memory overhead because nodes in a grid map need not store any information about blocked areas, which would scale poorly for large maps. Instead, during pathfinding, a search algorithm retrieves this information from the BA-tree, where the memory requirements are bound by a small fraction of nodes in a grid map, as will be explained by Section 5.
While the concept of blocked areas can be generalized to any obstacle shape, in this paper, we consider maps where obstacles are represented as vertical and horizontal line-segments, which in turn form blocked areas that are polygons. Such cases are commonly found in maps of mazes, buildings and transportation maps.
We evaluate the impact of using the blocked areas’ knowledge for A and W A using a publicly available benchmark set that includes sixty maps of mazes and rooms [6]. Our evaluation shows that the search space (i.e., the number of visited nodes during pathfinding) of A is reduced by 34%, on average, for both mazes and rooms. This results in a significant reduction in search time for both A and W A . Specifically, in mazes, the execution times of both A and W A were reduced by 10–35% (the average is 28 % ). In rooms, the execution times of both A and W A were reduced by 5– 57 % (the average is 30 % ). Our evaluation also demonstrated that the memory overhead associated with storing blocked areas’ information in memory during preprocessing and the time associated with accessing this information during pathfinding are both small.
The remainder of this paper is organized as follows: Section 2 surveys related work. Section 3 provides background information about A and W A search algorithms. Section 4 presents the definition of blocked areas. Section 5 describes the proposed preprocessing algorithm for finding blocked areas in a grid map. Section 6 describes the proposed algorithms for constructing and accessing the BA-tree. Section 7 evaluates the impact of using the blocked areas’s knowledge in reducing execution time for both A and W A . Section 8 concludes the paper.

2. Related Work

Several heuristic search algorithms in the literature, such as A and W A , assume no prior knowledge about maps. However, in many grid-based pathfinding domains, maps have static nature, i.e., their territories remain mostly the same. Examples of such domains are video games and city maps. Therefore, preprocessing approaches where prior knowledge about grid maps are utilized for the purpose of speeding up pathfinding has attracted many researchers due to the amortized runtime overhead (preprocessing needs to be executed only once).
In general, the efficiency of preprocessing approaches for pathfinding depends on the following: (i) the type of knowledge collected; (ii) the runtime overhead of accessing this knowledge during actual pathfinding; and (iii) the memory overhead of storing this knowledge. Below, we survey previously proposed preprocessing methods and describe their difference to our work.
Some researchers proposed preprocessing approaches where optimal paths between all or some nodes are pre-calculated and stored in a database, which is looked up during actual pathfinding [7,8,9,10]. While pathfinding in these approaches is fast and optimal, in general (despite using compression techniques) memory requirements are huge because memory is proportional to the number of nodes in a map. By contrast, the memory requirement in our work is bounded by the number of blocked areas, which is, in practice, a small fraction compared to the total number of nodes in a grid map.
Other researchers suggested using preprocessing to create an abstraction layer (or multiple layers) for each group of nodes in the map with pre-calculated local paths. During actual pathfinding, a path is found first using the abstract map. This path is then refined in a subsequent step for the original map. The returned path is, however, not guaranteed to be optimal. Examples of such works are [11,12,13].
A related approach to the abstraction method is introduced by [14], where all shortest paths between all pairs of nodes are abstracted (instead of abstracting each group of nodes in a grid map). This is done using a preprocessing step that identifies all subgoals in a map. A subgoal is a sequence of nodes such that a path between any pair of nodes inside a subgoal is optimal only if it is a part of the optimal path to the next subgoal. During actual pathfinding, an optimal high-level path between subgoals is found first. This path is then refined to an optimal low-level path.
Compared to abstraction-based approaches, our approach does not require any additional refinement steps when performing pathfinding. In addition, it needs not store in memory any knowledge about pre-computed local distances between nodes.
A similar work to ours is the dead-end heuristic [15], which describes areas that are irrelevant to the current search. During the preprocessing phase, the map is decomposed into smaller areas and a high-level abstract graph with nodes representing those small areas is created. During actual pathfinding, the search is split into two phases. The first phase identifies all nodes in the high-level graph that are relevant to the shortest path (the other nodes are called the dead-end areas). The second phase performs actual pathfinding while avoiding dead areas. Due to using an abstract graph, dead-end heuristic requires an extra step during pathfinding; a step that is not needed in our work.
Another similar work to ours is [16], which uses preprocessing to identify swamps, a collection of nodes that can be skipped during optimal pathfinding. Conceptually, swamps and blocked areas have the same definition. In addition, similar to our work, swamps require no additional refinement steps during search time. However, unlike our work, each node in a map is required to store an identifier that tells which swamp this node belongs to so that, during pathfinding, search for nodes inside swamps is blocked. Our approach also blocks search inside the blocked areas, however, without requiring nodes to store blocked areas’ identifiers (which would be memory-inefficient in large maps). Instead, this information is retrieved from a memory-efficient binary search tree data structure during pathfinding.
Similar to A and W A , there are also other heuristic search algorithms in the literature that assume no prior knowledge about maps, such as the Explicit Estimation Search [17] and Jump Point Search [18] algorithms. Our work is complementary to those algorithms, i.e., pre-computed knowledge about blocked areas can be combined with those algorithms to reduce search time. As a proof of concept, this paper evaluates the impact of blocked areas’ knowledge on reducing search time for the A and W A algorithms.
The Grid-Based Path Planning Competition (GPPC) [19] was introduced in 2012 to facilitate comparing different search algorithms using a standard set of maps, some of which were created artificially and others were taken from commercial video games [6]. We use sixty available maps of mazes and rooms from the same set to evaluate the proposed approach in this work. Details of the competing algorithms in the GCCP are summarized by [20].
A noticeable related field to our work is route planning in transportation networks, in which preprocessing techniques have been proposed to find the shortest paths in road networks [21]. Some of these techniques have also been used in the context of grid-based pathfinding. For example, in the GCCP’15 contest, a route planning approach based on the contraction hierarchies (CH) algorithm [22] achieved competitive performance. During a preprocessing phase, the CH algorithm uses a node contraction method to augment the shortest paths between each pair of nodes in a graph with shortcuts. During actual pathfinding, the search makes use of these shortcuts to reduce the execution time.

3. Background

In this paper, a grid map is represented as a 2D array of points (or nodes), where each node is identified by x and y coordinates. In addition, each node has a flag to indicate if it is either an obstacle or a non-obstacle node. For a given node n, a d j a c e n t ( n ) is the set of non-obstacle nodes that are reachable from n via a single movement, which can be vertical, horizontal or diagonal. Consider node m a d j a c e n t ( n ) , the movement cost from n to m is represented by the function c(n,m):
c ( n , m ) = 1.0 , n to m movement is either vertical or horizontal 2.0 , n to m movement is diagonal
Algorithm 1 shows the pseudo code for the classical A algorithm, which finds the shortest path between a source node s and a goal node g in a grid map G. A is a best-first search algorithm that gradually expands nodes along the way from s to g while prioritizing exploring node with better heuristic scores. When expanding a node q, the algorithm defines the following four values: gscore(q), which is the distance from the source node s to q; hscore(q), which is the algorithm’s “guess" of the distance from q to the goal node g; fscore(q) = gscore(q) + hscore(q), which represents the priority of q in the search; and p a r e n t (q), which is a pointer to the parent of q in the path from s to g.
The algorithm maintains two lists: open and closed. When expanding a node, it is put in the open list. Nodes in the open list are then iteratively explored by their increasing order of fscore. A node that has been explored is removed from the open list and is put in the closed list so that it is not explored again. When the goal node is found, the search terminates and the path is constructed by recursively following the parent pointers from the goal node to the source node.
The optimality of A is only guaranteed if the heuristic function is admissible, i.e., estimated distance by hscore(q) is always less than or equal to the actual distance from q to the goal node g [2]. One simple way of never overestimating hscore(q) is always assuming a straight line movement from q to g. An example of such a heuristic function is the octile-distance function, which is popularly used in 8-connected grid maps where horizontal, vertical and diagonal movements are allowed. Specifically, the octile-distance from node q to a goal node g is equal to the minimum number of diagonal steps, plus the minimum number of either vertical or horizontal steps needed to go from q to g. The octile-distance is given by the equation
h score ( q ) = 2.0 × minimum ( Δ x , Δ y ) + 1.0 × ( Δ x + Δ y minimum ( Δ x , Δ y ) )
where Δ x is the number of horizontal steps and Δ y is the number of vertical steps from q to g. Note that minimum( Δ x , Δ y ) represents the number of diagonal steps from q to g.
Algorithm 1 A pathfinding
Input: 
Grid map G with a source node s and a goal node g
Output: 
The shortest path between s and g in G
  • o p e n e m p t y list
  • c l o s e d e m p t y list
  • add s into o p e n with gscore(s) = 0 , fscore(s) = hscore(s), p a r e n t (s) = n u l l
  • while o p e n is not empty do
  •     n get and remove node with minimum fscore from o p e n
  •    if n = g then
  •       return path from s to g
  •    end if
  •    add n into c l o s e d
  •    for each node q a d j a c e n t ( n ) and q c l o s e d do
  •        gscore gscore(n) + c(q,n)
  •        if q o p e n then
  •           add q into o p e n with gscore(q) = gscore , fscore(q) = gscore(q) + hscore(q), p a r e n t (q) = n
  •        else if gscore < gscore(q) then
  •           update q in o p e n with gscore(q) = gscore , fscore(q) = gscore(q) + hscore(q), p a r e n t (q) = n
  •       end if
  •    end for
  • end while
  • return f a i l u r e
W A has the same pseudo code in Algorithm 1 with only one modification: it calculates fscore(q) = gscore(q) + ϵ × hscore(q), ϵ > 1 . As previously explained, this simple yet elegant modification adds a stronger greedy nature of the search algorithm that leads it to finding a path more quickly, albeit being a sub-optimal path. It is proven that the cost of the sub-optimal path found by W A is bounded by ϵ × the cost of the optimal path [2].
The speed at which the A algorithm, as well as the W A algorithm, finds a path is affected by the quality of its heuristic function. For example, if the heuristic function computes an inaccurate estimate of the to-go-distance to the goal node, then the search algorithm will waste time exploring uninteresting nodes, i.e., nodes that are not pertaining to the shortest path. As previously mentioned, in many grid maps, a heuristic function may compute inaccurate distance estimates due to their unawareness of blocked ends created by the geometry of obstacles. To this end, this paper aims to identify areas in a grid map with blocked ends and make use of this knowledge to enable search algorithms to avoid wasting time exploring nodes in such areas.

4. Blocked Area Definition

For a given undirected 2D grid map, a blocked area (BA) is a connected subgraph of adjacent non-obstacle nodes that is bound by a continuous but non-enclosing chain of obstacle nodes. A blocked area’s entrance is the imaginary straight line that connects the two end points of the obstacles’ chain. Intuitively, any path that connects a node inside a blocked area with a node outside the blocked area passes by its entrance.
Given a blocked area A, we define e n t r a n c e (A) to be the set of all nodes that lie on the imaginary straight line of A’s entrance. As a result that nodes in a grid map are discrete, the imaginary line may not cross the nodes themselves, and instead, cross the squares that are formed by the nodes. Therefore, a more precise definition of e n t r a n c e (A) is the set of all nodes that lie on the corners of the intersecting squares with the entrance’s imaginary straight line. The remaining set of nodes inside the blocked area are defined as i n t e r n a l (A). Both of these sets are mutually exclusive, i.e., if node n i n t e r n a l (A), then  n e n t r a n c e (A), and vice versa. We also define e x t e r n a l (A) to be the set of all nodes n such that n i n t e r n a l (A) and n e n t r a n c e (A).
Given the aforementioned definition of a blocked area, all nodes in i n t e r n a l (A) and e n t r a n c e (A) must be non-obstacle nodes. Otherwise, A is not a blocked area. Furthermore, due to not having obstacles inside or along the entrance of a blocked area A, the following two properties hold:
Property 1 
There is always a path between a node n 1 e n t r a n c e (A) and a node n 2 i n t e r n a l (A).
Property 2 
There is always a shortest path between two nodes n 1 and n 2 e n t r a n c e (A) such that this path does not pass by any node n i n t e r n a l (A).
The main claim of this paper is that blocked areas can be ignored during pathfinding without affecting the correctness and the optimality of a heuristic search algorithm. In below, Lemma 1 proves the correctness claim by showing that there is always an alternative path to any path that passes by a blocked area in a grid map. Lemma 2 proves the optimality claim by showing that there is an alternative path that is also optimal.
Lemma 1.
Consider a blocked area A and a pair of nodes s and g that are outside A. If there is a path between s and g that passes by an internal node inside A, then there is also another path between s and g that does not pass by an internal node inside A.
Proof. 
Let p a t h (s,g) denote a path between s and g, where s, g e x t e r n a l (A). Additionally, let us assume this path passes by a node n i n t e r n a l (A). In order to prove Lemma 1, we need to show that there is another path, i.e., p a t h ^ (s,g), such that n p a t h ^ (s,g).
First, because n p a t h (s,g), we can rewrite p a t h (s,g) = p a t h (s,n) + p a t h (n,g). Next, because n i n t e r n a l (A), both p a t h (s,n) and p a t h (n,g) cross A’s entrance. Therefore, we can rewrite p a t h (s,g) = p a t h (s,x) + p a t h (x,n) + p a t h (n,y) + p a t h (y,g), where nodes x and y e n t r a n c e (A). Note that p a t h (x,n) and p a t h (n,y) exist (Property 1). Next, because x and y e n t r a n c e (A), p a t h (x,y) exists such that n p a t h (x,y) (Property 2). Therefore, we can construct a new path p a t h ^ (s,g) such that p a t h ^ (s,g) = p a t h (s,x) + p a t h (x,y) + p a t h (y,g), where all nodes in p a t h (s,x), p a t h (x,y) and p a t h (y,g) i n t e r n a l (A). □
Lemma 2.
Consider a blocked area A and a pair of nodes s and g that are outside A. If there is an optimal path between s and g that passes by an internal node inside A, then there is also another optimal path between s and g that does not pass by an internal node inside A.
Proof. 
Let p a t h (s,g) denote a path between s and g (s, g e x t e r n a l (A)) such that it passes by a node n i n t e r n a l (A). Additionally, let p a t h (s,g) be an optimal path with cost c. From Lemma 1, there is at least one path between s and g, denoted p a t h ^ (s,g), such that n p a t h ^ (s,g). Let c ^ be the cost of p a t h ^ (s,g). In order to prove Lemma 2, we need to show that c ^ = c.
As we showed earlier, we can write p a t h (s,g) = p a t h (s,x) + p a t h (x,n) + p a t h (n,y) + p a t h (y,g) and p a t h ^ (s,g) = p a t h (s,x) + p a t h (x,y) + p a t h (y,g), where nodes x and y e n t r a n c e (A). Let c 1 , c 2 and c 3 be the cost of p a t h (x,n), p a t h (n,y) and p a t h (x,y), respectively. Thus, c c ^ = c 1 + c 2 c 3 . To show that c ^ = c, we need to show c 1 + c 2 c 3 = 0 .
First, because c is optimal, c c ^ . Thus, c 1 + c 2 c 3 0 . Second, due to Property 2, p a t h (x,y) is optimal, i.e., it has a less or equal length to p a t h (x,n) + p a t h (n,y). Therefore, c 3 c 1 + c 2 , which leads to c 3 ( c 1 + c 2 ) 0 . Combining both inequalities, the only possible solution is c 1 + c 2 c 3 = 0 . □

5. Blocked Area Detection

In this paper, we consider grid maps where obstacle nodes are adjacent to each other such that they form vertical or horizontal line-segments. In such grid maps, blocked areas have polygon shapes with internal non-obstacle nodes and a non-enclosing perimeter of obstacle nodes. The open side of the blocked area’s perimeter represents its entrance.
In a grid map, each line-segment obstacle is represented by two distinct nodes, i.e., e 1 = ( x 1 , y 1 ) and e 2 = ( x 2 , y 2 ), which are its end points. A horizontal line-segment obstacle has the same x-coordinate in both of its end points. A vertical line-segment obstacle has the same y-coordinate in both of its end points. We use the notation e 1 e 2 to refer to a line-segment obstacle.
A vertical and a horizontal line-segment obstacles may intersect in a grid map. To identify such a scenario, we introduce a data structure called corner, which is represented by three distinct nodes v, t and h, where t is the intersection point, v is the end point of the vertical side and h is the end point of the horizontal side. We use the notation v t h to refer to a corner. Note that when a horizontal and a vertical line-segment obstacle intersect, up to four corners with different geometrical shapes can be generated. For example, the intersection + has a single intersection point and four corners with the following shapes: ┌, └, ┐ and ┘.
Figure 3 shows an example of a maze with 11 and 13 horizontal and vertical line-segment obstacles, respectively. Those obstacles intersect in 24 different intersection points such that 43 corners are generated. For example, the vertical line-segment (67,67)→(133,67) intersects with the horizontal line-segment (100,34)→(100,100). As a result, the four corners C 9 , C 10 , C 11 and C 12 are generated, where  C 9 is represented by (67,67)→(100,67)→(100,34), C 10 is represented by (67,67)→(100,67)→(100,100), C 11 is represented by (133,67)→(100,67)→(100,34) and C 12 is represented by (133,67)→(100,67)→(100,100).
In a grid map, a polygon-shaped blocked area is formed when one or more corners are connected together such that a subset of non-obstacle nodes are bound within a continuous (but non-enclosing) chain of vertical and horizontal line-segment obstacles. For example, in Figure 3, blocked area A 7 is bound by the continuously connected corners (written in counterclockwise order): C 5 , C 6 , C 19 and C 18 . Similarly, blocked area A 15 is bound by the continuously connected corners: C 29 , C 31 , C 39 , C 38 and C 35 . An interesting case is A 1 , which is a triangular-shaped blocked area that was formed by the single corner C 7 .
A polygon-shaped blocked area is represented by its perimeter joint points, which can be extracted from its corners. For example, consider blocked area A 17 in Figure 3, which is formed by the corners C 25 , C 43 and C 42 (sorted in counterclockwise order). This blocked area is represented by the five points (166,133)→(199,133)→(199,232)→(166,232)→(166,166). The middle three points are the intersection points of C 25 , C 43 and C 42 , respectively. The first and the last points are the free points in C 25 and C 42 . The entrance is represented by the straight line (166,166)→(166,133).
In general, a polygon-shaped blocked area with s corners (sorted in counterclockwise order): C 1 , C 2 , …, C s can be represented by s + 2 joint points: e 1 , t 1 , t 2 , …, t s , e s , where t i is the intersection point of corner C i and e 1 and e s are the free points of the two corners C 1 and C s , respectively. The entrance is represented by the straight line between e 1 and e s .
A simple and key observation is the following: a corner can only be in one unique blocked area. In other words, different blocked areas in a grid map have disjoin sets of connected corners. Therefore, to identify blocked areas in a grid map, we propose the following approach. First, identify all corners that result from the intersections between vertical and horizontal line-segment obstacles in a grid map. Then, identify each disjoint subset of corners that belong to the same blocked area. Finally, extract joint points from these disjoint sets to represent each blocked area.
Algorithm 2 presents the pseudo code for a preprocessing algorithm that performs the aforementioned approach. Firstly, in lines 1–2, Algorithm 2 uses the sweep line algorithm [23] to identify all intersection points between vertical and horizontal line-segments obstacles. The sweep line algorithm is a widely-used method for finding line-line intersections in Euclidean spaces due to its linearithmic performance [24]. Subsequently, Algorithm 2 extracts all corners from all intersections. Extracting corners from an intersection is straightforward (For brevity, pseudo codes of straightforward functions are not shown.).
Secondly, in lines 3–10, Algorithm 2 identifies which corners are connected. To do so, we propose the Partition and Sort method, which identifies all pairs of connected corners for every horizontal and vertical line-segment obstacle in a grid map. To explain, consider the horizontal line-segment obstacle (100,133)→(100,232), where the intersection points of the corners C 23 , C 30 , C 31 , C 32 , C 33 , C 39 and C 40 are located. Our method first partitions the corners into two sublists: upward corners and downward corners. Upward corners are the corners with their vertical side located upward from the horizontal line-segment obstacle, which include corners C 30 , C 31 and C 39 . Downward corners are the corners with their vertical side located downward from the horizontal line-segment obstacle, which include C 23 , C 32 , C 33 and C 40 . Next, our method sorts the corners in each sublist according to the y-coordinates of their vertical sides so that adjacent corners are next to each other. In the sorted order, each adjacent pair of corners with distinct intersection points are connected. For example, sorting the upward corners will give C 30 , C 31 and C 39 . The first adjacent pair ( C 30 , C 31 ) are not connected because they have the same intersection point, while the second adjacent pair ( C 31 , C 39 ) are connected due to having distinct intersection points. Similarly, sorting the downward corners will give C 23 , C 32 , C 33 and C 40 , where only two adjacent pairs are connected: ( C 23 , C 32 ) and ( C 33 , C 40 ). Algorithm 3 presents the pseudo code for our proposed Partition and Sort method. Similar to horizontal line-segment obstacles, the Partition and Sort method is applied to vertical line-segment obstacles but while partitioning to left and right (instead of up and down) and sorting by x-coordinates (instead of sorting by y-coordinates).
Algorithm 2 Blocked Area Detection Algorithm
Input: 
Grid map G with a set of vertical line-segment obstacles V and a set of horizontal line-segment obstacles H. The number of intersections is R and the number of corners is N.
Output: 
List of all blocked areas in G
1:
t 1 , t 2 , …, t R ⇐ SweepLineAlgorithm(V, H)
2:
C 1 , C 2 , …, C N ⇐ extractCorners( t 1 , t 2 , …, t R )
3:
U F a union-find data structure with initially N disjoint corners: C 1 , C 2 , …, C N
4:
for each line L in V H do
5:
    c o r n e r s u b l i s t ⇐ subset of corners with intersection points in L
6:
    c o n n e c t e d P a i r s ⇐ PartitionAndSort( c o r n e r s u b l i s t ,L)
7:
   for each pair of corners C i and C j in c o n n e c t e d P a i r s do
8:
       U F .union( C i , C j )
9:
    end for
10:
end for
11:
B A l i s t an initially empty list of blocked areas
12:
for each disjoint set S in U F do
13:
    C 1 , C 2 , …, C s ⇐ get corners in S
14:
   sort C 1 , C 2 , …, C s counterclockwise
15:
    e 1 , t 1 , t 2 , …, t s , e s ⇐ extractJoints( C 1 , C 2 , …, C s )
16:
    A createBlockedArea( e 1 , t 1 , t 2 , …, t s , e s )
17:
   add A to B A l i s t
18:
end for
19:
for each blocked area A in B A l i s t do
20:
   if e n t r a n c e (A) has obstacle nodes or i n t e r n a l (A) has obstacle nodes then
21:
       remove A from B A l i s t
22:
   end if
23:
end for
24:
return B A l i s t
The Partition and Sort method identifies connected corners in pairs. However, a blocked area can have multiple connected corners. To find all connected corners, we propose using a union-find data structure, which is a commonly-used data structure for keeping track of connected components in graphs (Sedgewick and Wayne, 2011). A union-find data structure starts by initially assuming all corners are disjoint and put into separate sets. Then, every time a pair of corners are found to be connected by the Partition and Sort method, union-find data structure unions their sets. By doing so for all pairs of connected corners in a grid map, the union-find data structure will have all connected corners put in the same set. Furthermore, all sets in the union-find data structure are disjoint.
Algorithm 3 Partition and Sort method
Input: 
Set of l corners: C 1 , C 2 , …, C l with intersection points located on line-segment obstacle L.
Output: 
All pairs of connected corners on L
1:
c o n n e c t e d P a i r s ⇐ an initially empty list
2:
ifL is horizontal then
3:
    u p w a r d ⇐ an initially empty list
4:
    d o w n w a r d ⇐ an initially empty list
5:
    x L x-coordinate of L
6:
   for each corner C i in C 1 , C 2 , …, C l do
7:
       x i x-coordinate of the vertical end point of C i
8:
      if x i < x L then
9:
         add C i to u p w a r d
10:
    else
11:
        add C i to d o w n w a r d
12:
      end if
13:
   end for
14:
   sort corners in u p w a r d and d o w n w a r d by the y-coordinate of their intersection points
15:
   for each adjacent pairs of corners C i and C j in u p w a r d and d o w w a r d do
16:
       if C i and C j have distinct intersection points then
17:
           add ( C i , C j ) to c o n n e c t e d P a i r s
18:
       end if
19:
   end for
20:
else ifL is vertical then
21:
    l e f t ⇐ an initially empty list
22:
    r i g h t ⇐ an initially empty list
23:
    y L y-coordinate of L
24:
   for each corner C i in C 1 , C 2 , …, C l do
25:
       y i y-coordinate of the horizontal end point of C i
26:
      if y i < y L then
27:
         add C i to l e f t
28:
      else
29:
         add C i to r i g h t
30:
      end if
31:
   end for
32:
   sort corners in l e f t and r i g h t by the x-coordinate of their intersection points
33:
   for each adjacent pairs of corners C i and C j in l e f t and r i g h t do
34:
      if C i and C j have distinct intersection points then
35:
          add ( C i , C j ) to c o n n e c t e d P a i r s
36:
      end if
37:
   end for
38:
end if
39:
return c o n n e c t e d P a i r s
Thirdly, in lines 11–18, Algorithm 2 creates polygon-shaped blocked areas by extracting their perimeter’s joint points from every disjoint set of corners in the union-find data structure.
Finally, in lines 19–23, Algorithm 2 removes all blocked areas that do not satisfy our definition in Section 4, which stated that all internal and entrance nodes must be non-obstacle nodes. For example, in Figure 3, C 22 and C 34 form a blocked area. However, this blocked area is discarded because its entrance intersects with the vertical line-segment obstacle (34,166)→(133,166)), i.e., it has obstacle nodes in its entrance. Another example are corners C 16 , C 14 , C 1 and C 2 , which form a blocked area that was discarded because it has internal obstacle nodes.
The detailed description of how Algorithm 2 determines which blocked areas have obstacles in their e n t r a n c e or i n t e r n a l sets is not shown but can be explained as follows. As a result that a blocked area’s entrance is a straight line, the sweep line algorithm is used to determine if there is any horizontal or vertical line-segment obstacle that intersects with the entrance of a blocked area A. If so, A is discarded. Additionally, we modify the sweep line algorithm so that it can be used to identify all blocked areas with internal vertical or horizontal line-segment obstacles. Those blocked areas are also discarded.
Lemma 3.
The generated set of polygon-shaped blocked areas by Algorithm 2 satisfy the definition given in Section 4, i.e., each polygon-shaped blocked area is a connected subgraph of adjacent non-obstacle nodes that is bound by a continuous but non-enclosing chain of obstacle nodes.
Proof. 
As previously explained, in lines 1–18, Algorithm 2 identifies all non-enclosing polygon shapes of obstacles that represent blocked areas in a map. Then, in lines 19–23, Algorithm 2 determines which non-enclosing polygon shapes have obstacles in their e n t r a n c e or i n t e r n a l sets and ensures that they are removed, i.e., not recognized as blocked area. Thus, Algorithm 2 guarantees that each polygon-shaped blocked area in the final output is a connected subgraph of adjacent non-obstacle nodes that are bound by a continuous but non-enclosing chain of vertical and horizontal line-segment obstacles (i.e., obstacle nodes). □
We now present a complexity analysis of Algorithm 2’s execution time. For convenience, let us assume, in a grid map, that T V is the number of vertical line-segment obstacles, T H is the number of horizontal line-segment obstacles, R is the number of intersections, N is the number of corners and P is the number of blocked areas. The following inequalities hold:
  • R T V × T H
    The maximum number of possible intersections occurs when every vertical line-segment obstacle intersects with every horizontal line-segment obstacle.
  • R N 4 × R
    Each intersection generates anywhere between one to four corners.
  • P N
    The maximum number of blocked areas occurs when each corner, alone, forms a triangular-shaped blocked area.
Table 1 describes an execution time complexity analysis for Algorithm 2. Authors in [24] have shown that, for a given Cartesian space with n line-segments and k intersections, the sweep line algorithm is bound by n log 2 n + k . This explains the upper bounds shown for lines 1 and 19–23 in Table 1. In addition, note that we use the weighted union-find data structure (Sedgewick and Wayne, 2011), which guarantees that union operations are executed in logarithmic-time. Therefore, in lines 4–10, the most expensive operation inside the loop is the Partition and Sort method. Specifically, let us assume that the number of corners in c o r n e r s u b l i s t is N l , the Partition and Sort needs linear time (i.e., N l ) to partition the corners and linearithmic time (i.e., N l log 2 N l ) to sort the corners. Due to having a loop, the overall execution of the Partition and Sort method is bound by N + N log 2 N . Finally, in lines 11-18, the most expensive operation in the loop is the sort operation in line 14. Hence, the overall loop’s execution is bound by N log 2 N .
By taking into account the above three inequalities, the entire execution of Algorithm 2 is bound by ( T V + T H + P ) log 2 ( T V + T H + P ) +N log 2 N . This shows that the preprocessing time of Algorithm 2 has an efficient linearithmic growth.
By the end of its execution, Algorithm 2 will identify all polygon-shaped blocked areas in a grid map. Each polygon-shaped blocked area is represented by its perimeter joint points, i.e., each blocked area is stored in memory using pointers that point to the nodes located at these joints. Assuming J i is the number of joints in blocked area A i , the total number of extra pointers needed to store all blocked areas is J = i = 1 P J i . In practice, even for large maps, J represents a small fraction compared to the total number of nodes in a map. For example, in all of our benchmark set in Section 7, J is less than 5.4% of the total number of nodes in the map.

6. BA-Tree

As previously mentioned, our approach uses pre-computed knowledge about blocked areas in a map to prohibit a search algorithm from unnecessarily exploring nodes inside blocked areas. This is achieved using the BA-tree, a binary tree data structure that stores blocked areas’ information. During actual pathfinding, a search algorithm accesses the BA-tree to determine whether a particular node is inside a blocked area. If so, this node is discarded. In below, we first describe a preprocessing algorithm that constructs the BA-tree. Then, we describe an algorithm for accessing the BA-tree.

6.1. BA-Tree Construction

In computer science, spatial searching refers to the problem of locating objects in multi-dimensional spaces. R-tree data structures [25] have been extensively used for handling spatial searching in many contexts such as database applications and geographic information system applications [26]. The basic idea of R-tree data structures is to recursively subdivide a multi-dimensional space into subspaces such that nearby objects are grouped together into the same subspace. Those subspaces are then organized into a tree data structure, which in turn is used for servicing search queries. In this paper, we present the BA-tree, a variant of R-tree that is applied in the context of 2D grid-based pathfinding. Specifically, the BA-tree is a balanced binary search tree that is used for identifying which blocked area a given node belongs to in a 2D grid map.
For convenience, we first present the definition of the minimum bounding rectangle (or MBR) (The same terminology was used in the literature of R-tree data structures), which is the smallest rectangle that encapsulates a group of nearby blocked areas. Formally, we define MBR( A 1 , A 2 , …, A m ) to be the smallest rectangle that bounds a group of m blocked areas: A 1 , A 2 , …, A m . An MBR is represented by four coordinates: x u p p e r , the coordinate of the upper-most row; x l o w e r , the coordinate of the lower-most row; y l e f t , the coordinate of the left-most column; y r i g h t , the coordinate of the right-most column. For example, in Figure 3, MBR( A 10 , A 11 , A 13 , A 15 ) is represented by x u p p e r = 1 , x l o w e r = 100 , y l e f t = 133 and y r i g h t = 232 .
Given a grid map with m blocked areas, the BA-tree is constructed as follows. Initially, an MBR that spans all m blocked areas is created. This MBR is then partitioned vertically into two MBRs such that each nearby m 2 blocked areas are put in the same MBR. Each MBR is then partitioned horizontally into two MBRs such that each nearby m 4 blocked areas are put in the same MBR. This is done recursively while alternating between vertical partitioning and horizontal partitioning. The recursive partitioning terminates when one or two blocked areas are reached. The resulting MBRs from the recursive partitioning are organized to form the following binary tree data structure:
  • Internal nodes represent MBRs while leaf nodes represent blocked areas.
  • At level 0 of the tree, there is only one node, the root node, which represents the MBR that encapsulates all m blocked areas.
  • At level 1 of the tree, there are two nodes, which represent the two MBRs generated from applying vertical partitioning to the MBR of the node at level 0.
  • At level 2 of the tree, there are four nodes, which represent the four MBRs generated from applying horizontal partitioning to the MBRs of the two nodes at level 1.
  • In general, at level l of the tree, there are 2 l nodes, which are generated from partitioning the 2 l 1 nodes at level l 1 of the tree. This partitioning is vertical if l is odd, while it is horizontal if l is even.
Algorithm 4 presents pseudo code for the vertical and horizontal partitioning functions that construct the BA-tree for a grid map. To simplify partitioning, both functions use sorting (line 11) to ensure that nearby blocked areas are adjacent to each other. Both functions recursively call each other (lines 12–13) to alternate the partitioning process. As an example, Figure 4 shows the BA-tree constructed by Algorithm 4 for the maze in Figure 3. Note that MBRs in different internal nodes may overlap. In below, we show few key properties of the BA-tree.
Lemma 4.
Assuming m is the number of blocked areas in a grid map, the height of the BA-tree is log 2 m 1 .
Proof. 
In a binary tree, the height is equal to the maximum level of a node in the BA-tree. Therefore, our goal is to show that all nodes in the BA-tree are located at levels log 2 m 1 .
Without loss of generality, let us first assume the simple case when m is a power of 2, i.e., m = 2 d , where d is some integer. In this case, the levels of the BA-tree are: 0, 1, …, d 1 , where d 1 is the last level because the recursive partitioning terminates when number of blocked areas is 2 (line 1 in Algorithm 4). Thus, the height of the tree is d 1 = log 2 m 1 .
In the general case, let h be the height of the BA-tree. Furthermore, let d be an integer such that 2 d 1 < m 2 d . First, h d 1 because m 2 d and d 1 is the height of a tree with 2 d nodes (as shown by the simple case). Second, h > d 2 because m > 2 d 1 and d 2 is the height of a tree with 2 d 2 nodes. Combining both inequalities, we can write d 2 < h d 1 . As a result that h is an integer, the only possible solution is h = d 1 . As a result that d = log 2 m (generated from applying the logarithm function to the inequality 2 d 1 < m 2 d ), then h = log 2 m 1 . □
Algorithm 4 BA-tree Construction Functions
Input 
Set of m blocked areas: A 1 , A 2 , …, A m
Output 
Set of tree nodes representing the BA-tree
Function 
divideVertically ( A 1 , A 2 , …, A m )
1:
if m 2 then
2:
    e ⇐ new leaf node
3:
    if m = 1 then
4:
        e.put( A 1 )
5:
    else
6:
        e.put( A 1 , A 2 )
7:
    end if
8:
else
9:
    e⇐ new internal node
10:
  e.put( M B R ( A 1 , A 2 , …, A m ))
11:
  sort A 1 , A 2 , …, A m by their y r i g h t coordinate
12:
  e.left ⇐ divideHorizontally ( A 1 , A 2 , …, A m 2 )
13:
  e.right ⇐ divideHorizontally ( A m 2 + 1 , A m 2 + 2 , …, A m )
14:
end if
15:
returne
Function 
divideHorizontally ( A 1 , A 2 , …, A m )
1:
if m 2 then
2:
     e ⇐ new leaf node
3:
     if m = 1 then
4:
         e.put( A 1 )
5:
     else
6:
        e.put( A 1 , A 2 )
7:
     end if
8:
else
9:
     e ⇐ new internal node
10:
   e.put( M B R ( A 1 , A 2 , …, A m ))
11:
   sort A 1 , A 2 , …, A m by their x l o w e r coordinate
12:
   e.left ⇐ divideVertically ( A 1 , A 2 , …, A m 2 )
13:
   e.right ⇐ divideVertically ( A m 2 + 1 , A m 2 + 2 , …, A m )
14:
end if
15:
returne
Lemma 5.
The BA-tree is a balanced binary tree.
Proof. 
Let m be the number of blocked areas in a grid map and h be the height of the BA-tree. To show that the BA-tree is balanced, we need to show that each leaf node in the BA-tree is located at either level h 1 or level h.
Without loss of generality, let us first assume the simple case when m is a power of 2, i.e., m = 2 d , where d is some integer. In this case, it is easy to prove that the BA-tree is balanced because Algorithm 4 always partitions an MBR of an internal node e such that the number of blocked areas in the left subtree of e is equal to the number of blocked areas in the right subtree of e (lines 12–13). Furthermore, in this case, all leaf nodes are located exactly at level d 1 (because m is a power of 2 and the recursive partitioning terminates when the number of blocked areas is 2).
In the general case, let d be an integer such that 2 d 1 < m 2 d . As a result of m > 2 d 1 , there are no leaf nodes that can be located at a level that is smaller than d 2 (as shown by the simple case). Furthermore, because m 2 d , the maximum level in the BA-tree is d 1 (Lemma 4). Thus, all leaf nodes can only be located at levels d 2 and d 1 . As a result of h = d 1 (Lemma 4), we can also infer that all leaf nodes are located at levels h 1 and h. □
Lemma 6.
Assuming m is the number of blocked areas in a grid map, the number of nodes in the BA-tree is bound by 2 × m 1 .
Proof. 
As a result that the number of nodes in level i is at most 2 i , the maximum number of nodes in the BA-tree is bound by i = 0 log 2 m 1 2 i . This is a geometric series that is equal to 2 log 2 m 1 . log 2 m < log 2 m + 1 , 2 log 2 m < 2 log 2 m + 1 = 2 × m . Thus, 2 log 2 m 1 < 2 × m 1 . □
Corollary 1.
Assuming m is the number of blocked areas in a grid map, the number of internal nodes in the BA-tree is bound by m 1 and the number of leaf nodes is bound by m.

6.2. BA-Tree Analysis

We now present a complexity analysis of the execution time of Algorithm 4. Without loss of generality, let us assume the number of blocked areas m is a power of 2 and the height of the BA-tree is log 2 m . In Algorithm 4, it is quite straightforward to observe that the sort operation in line 11 is the longest operation, i.e., execution time is bound by sorting time (which has the upper bound complexity of n log 2 n , where n is the number of integers). At each level j in the BA-tree, there are 2 j nodes, i.e., subproblems. Each subproblem’s execution time is bound by sorting m 2 j blocked areas. Therefore, the amount of work done by all nodes in level j is 2 j × m 2 j log 2 m 2 j = m log 2 m 2 j m log 2 m . As a result that the height of the tree is log 2 m 1 (Lemma 4), the amount of work done to construct all levels in the BA-tree is bound by m log 2 2 m . In general, the execution time is bound by m log 2 m 2 .
We now present a memory consumption analysis for the BA-tree. As shown by Corollary 1, the number of internal nodes is bound by m 1 , where m is the number of blocked areas. Each internal node stores four integers (the coordinates of its MBR) and two pointers ( l e f t and r i g h t ). Assuming pointers and integers require the same amount of memory, all internal nodes need to store no more than 6 × ( m 1 ) integers. In other words, the needed memory for internal nodes in the BA-tree is bound by the number of blocked areas in a grid map. On the other hand, leaf nodes store the blocked areas: A 1 , A 2 , …, A m . As previously mentioned in Section 5, the amount of memory needed to store blocked area’s information, denoted by J, is bound by the total number of joint points in blocked areas, which is, in practice, equal to a small fraction of the number of nodes in a grid map.

6.3. BA-Tree Access

Algorithm 5 presents pseudo code for a recursive search function that identifies which blocked area A in the BA-tree contains a particular node q in a grid map. Starting from the root node, the search function searches all the nodes in the BA-tree in a depth-first fashion, however, with a key optimization: when visiting an internal node e, if q MBR(e), then the search for the descendent nodes of e is terminated (lines 9–11). This is because, if q MBR(e), it is predetermined that e any of the descendent blocked areas of e. In the case q MBR(e), the function continues the search in the left path of e (line 12). If a blocked area was not found in the left path (line 13), the function then searches the right path of e (line 14). Determining whether q MBR(e) or not is straightforward: q MBR(e) if and only if x u p p e r q . x x l o w e r and y l e f t q . y y r i g h t . In the case e is a leaf node (lines 1–8), the search function simply checks if q is contained by any of the blocked areas in e and terminates the search if such blocked area is found. Note that the maximum number of blocked areas in a leaf node is two. To determine if a polygon-shaped blocked area A contains a node q, we use the winding number algorithm [27], a widely-used method in computational geometry for determining if a point is inside a polygon. Figure 5 shows examples on two search queries for the BA-tree in Figure 4.
Algorithm 5 BA-tree Access Function
Input 
Query node q in a grid map and node e in the BA-tree
Output 
Blocked area A to which q belongs to, or null if no such blocked area exists.
Function 
searchBAtree (q, e)
1:
ife is a leaf then
2:
    for each blocked area A in e do
3:
      if e internal(A) then
4:
         return A
5:
      end if
6:
   end for
7:
   return n u l l
8:
end if
9:
if q M B R (e) then
10:
   return null
11:
end if
12:
A ⇐ searchBAtree (q, e.left)
13:
ifA = null then
14:
    A⇐ searchBAtree (q, e.right)
15:
end if
16:
returnA
The worst-case scenario in Algorithm 5 occurs when a search function visits all the nodes in the BA-tree, which is bound by 2 × m 1 (Lemma 6), where m is the number of blocked areas. However, this is rarely needed because, in real maps, blocked areas are often scattered such that they are isolated from each other. Thus, in the common case, the search function only needs to check a subset of paths in the BA-tree. As a result that the height of the BA-tree is log 2 m 1 (Lemma 4), the average-case execution time of Algorithm 5 is τ × log 2 m , where τ is some constant.

6.4. BA-Tree Alternatives

We now describe two alternative schemes to store blocked areas’ knowledge and discuss their differences to the BA-tree. The first alternative scheme is to assign a unique numeric ID to each blocked area, and then use an extra grid, in which each node stores the ID of the corresponding blocked area, or an invalid ID if it is outside all blocked areas. Such a scheme would require O(1) access time and O(n) space, where n is the total number of nodes in a grid map. By contrast, the BA-tree is more memory-efficient because it stores information about only joint points, which represents a small fraction of the total number of nodes in a gird map. Furthermore, the BA-tree has a low access time overhead, as discussed earlier.
Another scheme is to use trapezoidal decomposition [28], i.e., divide blocked areas into a set of trapezoids such that each trapezoid is the portion of the sweep line between two adjacent corners. Trapezoids are neighbors if they are neighbors along the sweep line or if one appears when the other disappears at a sweep event. The number of trapezoids is bound by 3 × n, where n is the total number of line-segment obstacles in a grid map [28]. Identifying which trapezoid contains a particular node is a grid map is O(1). More specifically, the first node requires O(n) due to performing linear search. Afterward, identifying adjacent nodes requires constant time because they are found in adjacent trapezoids. The trapezoidal decomposition scheme provides better access time guarantees than the BA-tree. However, it requires more memory to store the trapezoids’ information.

7. Experimental Results

We evaluate the performance by showing the reduction in execution time for both A and W A algorithms after combining the knowledge of blocked areas in their search. We perform pathfinding for sixty maps of mazes and rooms taken from the public pathfinding benchmarks library [6]. The modified algorithms are denoted by A + B A and W A + B A . All four search algorithms: A , W A , A + B A and W A + B A are implemented and compiled using Java SE 8 and all experiments were executed on a Red Hat Enterprise Linux 6 machine with a 2.2 GHz Intel Xeon-E5 processor and a 64 GB DDR3 memory with a speed of 1333 MHz.
Below, we describe, in detail, the implementation of the modified search algorithms and the tested benchmark set. Then, we present the evaluation results.

7.1. Search Implementation

Algorithm 6 shows the pseudo code for the implementation of A + B A algorithm. Compared to the standard implementation of A (shown in Algorithm 1), Algorithm 6 has two modifications. First, before adding node q into the o p e n l i s t , the algorithm accesses the BA-tree (in line 14) using the search function presented in Algorithm 5 to determine the blocked area A where q is located. Second, in line 15–17, the algorithm inserts q into the o p e n l i s t (i.e., included in the search) only if one of the following three conditions are satisfied:
  • q is not inside a blocked area.
  • q is inside a blocked area; however, this blocked area also contains the goal node g. This condition ensures that the search never ignores a blocked area where the goal node is located.
  • q is inside a blocked area; however, this blocked area also contains the parent node of q. This condition is needed in the case that the source node s happens to be inside a blocked area. If so, this blocked area is included in the search.
The aforementioned conditions are checked in the order shown, i.e., condition 2 is only checked if condition 1 is not satisfied and condition 3 is only checked if both conditions 1 and 2 are not satisfied. If none of the three conditions is satisfied, then q is not inserted into the o p e n list and therefore discarded from the search space. W A and W A + B A have the same implementations as A and A + B A , respectively, except that they calculate fscore(q) = gscore(q) + ϵ × hscore(q), where ϵ > 1 is a real number that controls the inflation of the heuristic function hscore(q). In this paper, we set ϵ = 3.0 .
Algorithm 6 A + B A pathfinding
Input: 
Grid map G with a source node s and a goal node g
Output: 
The shortest path between s and g in G
1:
o p e n e m p t y list
2:
c l o s e d e m p t y list
3:
B A r o o t ⇐ the root node of the B A -tree
4:
add s into o p e n with gscore(s) = 0 , fscore(s) = hscore(s), p a r e n t (s) = n u l l
5:
while o p e n is not empty do
6:
    n get and remove node with minimum fscore from o p e n
7:
   if n = g then
8:
       return path from s to g
9:
   end if
10:
 add n into c l o s e d
11:
 for each node q a d j a c e n t ( n ) and q c l o s e d do
12:
     gscore gscore(n) + c(q,n)
13:
     if q o p e n then
14:
       A ⇐ searchBAtree (q, B A r o o t )
15:
       if A = n u l l or g A or A = searchBAtree ( p a r e n t (q), B A r o o t ) then
16:
         add q into o p e n with gscore(q) = gscore , fscore(q) = gscore(q) + hscore(q), p a r e n t (q) = n
17:
       end if
18:
    else if gscore < gscore(q) then
19:
        update q in o p e n with gscore(q) = gscore , fscore(q) = gscore(q) + hscore(q), p a r e n t (q) = n
20:
     end if
21:
   end for
22:
end while
23:
return f a i l u r e
An important note is that a tie may occur when extracting the node with the minimum f-score in the open list, i.e., there might be multiple nodes that have the same minimum f-score (line 6). In such a case, ties are broken in favor of the node with the largest g-score. Such tie-breaking strategy is common in the literature [29,30]. We use this strategy in the implementation of all four tested algorithms.
In all four algorithms, the o p e n list is implemented using a binary min heap data structure, while the closed list is implemented using a hash table data structure that uses chaining to resolve collisions.

7.2. Benchmark Set

Thirty grid maps of mazes and thirty grid maps of rooms were selected form the public pathfinding benchmarks library to evaluate performance in this paper. A maze’s map consists of corridors with fixed sizes that are randomly scattered. A room’s map consists of squares with fixed sizes that are uniformly distributed with randomly generated doors between every two adjacent rooms (squares). All sixty maps of mazes and rooms have 512 × 512 resolution, i.e., the number of nodes in each row and in each column is 512.
The thirty mazes are divided into three types, each of which has ten maps, which are: maze-8, maze-16 and maze-32, where 8, 16 and 32 are the sizes of the corridors in each type, respectively. Similarly, the thirty rooms are divided into three types, each of which has ten maps, which are: room-8, room-16 and room-32, where 8, 16 and 32 are the sizes of the squares in each type, respectively. The pathfinding benchmarks library also provides, for each grid map, hundreds of test cases with randomly generated source and goal points (called scenarios) for performing pathfinding. We use all of these scenarios in our evaluation (however, we discard invalid scenarios where either the source or the goal node is an obstacle).
Table 2 summarizes the evaluated benchmarks set. In all sixty maps, obstacles are represented as vertical and horizontal line-segments. Therefore, in Table 2, we also include information about the number of horizontal and vertical line-segment obstacles, as well as the number of intersections and corners in every map. All of these measurements are relevant to the blocked area detection algorithm presented in Section 5.

7.3. Preprocessing Evaluation

Prior to performing pathfinding, in all sixty maps, a preprocessing step is executed to identify all blocked areas (using Algorithm 2), and then construct the BA-tree (using Algorithm 4). In some maps, some of the identified triangular-shaped blocked areas are small, i.e., they have one side with short length. As an optimization, such blocked areas were discarded because they are not useful during actual pathfinding. In all maps, preprocessing time was less than 300 milliseconds.
Table 3 presents an evaluation of the preprocessing step by showing the following measurements: (i) the number of blocked areas ( B A ); (ii) the percentage of nodes covered by those blocked areas (insideBA%); (iii) the percentage of nodes stored in memory due to blocked areas (joints%); (iv) the size of the BA-tree, i.e., the total number of tree nodes used to construct the BA-tree ( B A S i z e ); and (v) the worst-case number of searched nodes when accessing the BA-tree ( S e a r c h ).
In a grid map, the percentage of nodes covered by blocked areas represents an upper bound on the number of nodes that can be eliminated during pathfinding. On average, the percentages of covered nodes in maze-8, maze-16 and maze-32 are 35 % , 37 % and 38 % , respectively. On average, the percentages of covered nodes in room-8, room-16 and room-32 are 25 % , 41 % and 52 % , respectively.
As was previously mentioned in Section 5, blocked areas are stored in memory using pointers that point to nodes located at the joints of blocked areas. Table 3 shows that, in the worst-case, the total number of joints in blocked areas is less than 1.3 % of the total number of nodes in mazes and is less than 5.4 % in rooms. This demonstrates the memory efficiency of our approach.
While accessing the BA-tree is not part of preprocessing, in Table 3, we also measure the worst-case scenario of accessing the BA-tree. Specifically, we use the search function in Algorithm 5 to access the BA-tree using every node in a grid map as a search query, and then we report in Table 3 the worst-case number of how many nodes in the BA-tree were searched. In all sixty grid maps, the worst-case search needed was no more than 6 × log 2 n nodes in the BA-tree, where n is the total number of nodes in the BA-tree. This shows that, in practice, the access time of the BA-tree is logarithmic.

7.4. Pathfinding Evaluation

We demonstrate the impact of the blocked areas’ knowledge in pathfinding using two comparisons: (i) A + B A versus A ; and (ii) W A + B A versus W A . We do so by computing the relative execution time, which is a intuitive measurement of the reduction in execution time. For example, let us assume that the execution time of A when performing pathfinding for a particular map is 500 milliseconds, while the execution time for A + B A when performing the same pathfinding is 300 milliseconds. In this case, the relative execution time is 300 / 500 = 0.6 , which demonstrates that the execution time of A was reduced by 40 % when using the blocked areas’ knowledge in its pathfinding. We also evaluate the reduction in search space, i.e., the reduction in the number of visited nodes during pathfinding, by computing the relative search space.
As shown by Table 2, our benchmarks set consists of six types of maps, each of which has ten instances. Furthermore, each map instance has hundreds of scenarios. Therefore, we measure performance for each one of the six map types by computing the average relative execution time and the average relative search space for all ten instances combined. Specifically, we use the following formula:
average relative execution time = i = 0 9 j = 1 S i ( A + B A ) i , j ( A ) i , j i = 0 9 S i
where S i is the number of scenarios in map instance i; ( A + B A ) i , j is the execution time when performing pathfinding using A + B A for scenario j in map instance i; and ( A ) i , j is the execution time when performing pathfinding using A for scenario j in map instance i. A similar formula is used for computing the relative search space. Furthermore, the average relative execution time and search space of W A + B A over W A are computed in the same manner.
Table 4 shows the average relative execution time and search space for the two aforementioned comparisons. In all three types of mazes, on average, the search spaces of both A and W A were reduced by 33 % , which translated into a reduction in execution time by 28 % , on average. In room maps, the search spaces of A were reduced by 22 % , 36 % and 45 % , on average, for room-8, room-16 and room-32, respectively. As a result, the execution times were reduced by 15 % , 33 % and 44 % , respectively. In the case of W A , on average, the search spaces for room-8, room-16 and room-32 were reduced by 18 % , 34 % and 47 % , respectively. This caused the execution time to be reduced by 16 % , 30 % and 43 % , respectively.
The performance results in Table 4 can be explained by i n s i d e B A % in Table 3, which is the percentage of how many nodes are covered by blocked areas in a map. For example, all three types of mazes have approximately the same coverage percentage (around 37 % , on average). Thus, they have a similar performance in Table 4. On the other hand, room maps have different i n s i d e B A % values, which explains their varying performance. For example, room-32, where the coverage percentage is the highest ( 52 % , on average), the execution time was reduced by 43 % , on average. However, in the case of room-8, where the coverage is the lowest ( 25 % , on average), the execution time was reduced by 16 % , on average. Appendix A shows absolute execution times for all maps.
The performance results in Table 4 demonstrates that using blocked areas’ knowledge during pathfinding has significant impact on reducing search time in both A and W A . However, Table 4 hides some of the interesting details about how the benefit of blocked areas’ knowledge compares between short-distance pathfinding versus long-distance pathfinding. For example, in mazes, there are thousands of pathfinding scenarios available from the pathfinding benchmarks library, in which some scenarios have short paths (i.e., path cost is less than 100), whereas some scenarios have long paths with cost up to 2000. Figure 6 demonstrates the impact of blocked areas’ knowledge on different path costs in mazes. Specifically, in Figure 6, we divide all scenarios into ten groups, where scenarios in the first group have path costs from 0 to 200, scenarios in the second group have path costs from 200 to 400, scenarios in the third group have path costs from 400 to 600 and so on. Similarly, Figure 7 depicts the impact of blocked areas’ knowledge on different path costs in rooms. Note that, unlike mazes, scenarios in room maps have path costs that are between 0 and 800. Therefore, these scenarios are divided into ten groups, where scenarios in the first group have path costs between 0 and 80, scenarios in the second group have path costs between 80 and 160, scenarios in the third group have path costs between 160 and 240 and so on.
Figure 6 shows that, in all three types of mazes, blocked area’s knowledge has significant but different performance impacts on both short-distance and long-distance pathfinding. Specifically, in A , the execution time is reduced by 10 % for low path costs, and then this reduction steadily improves as the path cost increases, to reach around 35%, for high path costs. In W A , the reduction in execution time varies from 18 % in low path costs to 34 % in high path costs.
Figure 7 shows that, in all three types of rooms, the impact of blocked area’s knowledge on performance is mostly significant in both short-distance and long-distance pathfinding. However, this impact differs across different room types. In A , in the case of room-32, the reduction in execution time starts from a moderate 3 % , and then sharply improves as the path cost increases to reach 57 % for paths with high costs. In room-16, the reduction in execution time starts from 3 % in low path costs and quickly increases to reach 43 % in high path costs. In room-8, the reduction in execution time gradually increases from 5 % in low path costs to 19 % in high path costs. In W A , the performance behavior is less deterministic, i.e., in some cases the reduction in execution time decreases as the path cost increases. However, this nondeterminism varies in degree between different types of rooms. In room-32, the reduction in execution time starts form 10 % for low path costs and then sharply improves to reach 58 % in high path costs (with the exception of one case). In room-16, the reduction in execution time varies between 23 % and 36 % while having less consistent behavior. In room-8, the reduction in execution time varies between 6 % and 30 % while also having no consistent trend in performance.
We summarize the results of our evaluation of pathfinding in mazes and rooms as follows. In all three types of mazes, in general, the execution times of both A and W A were reduced by 10– 35 % (the average reduction is 28 % ). In all three types of rooms, in general, the execution times of both A and W A were reduced by 5– 57 % (the average reduction is 30 % ). Unlike mazes, different room map types have significantly different degrees of how many nodes are covered by blocked areas, which led to having different performance behaviors.
Finally, it is worthwhile to mention that eliminating nodes inside blocked areas during pathfinding often led A + B A to find a different path from the one found by A . However, in all maps and in all scenarios, both paths had the same optimal cost (as was also proven in Section 4). In the case of W A + B A and W A , both algorithms found sub-optimal paths. In most cases, the two paths obtained by both algorithms have the same cost. However, interestingly, in some cases, we observed that W A + B A found paths with lower costs than W A . This is because the exploration of blocked areas led W A in some cases to find a longer path. On average, W A + B A reduces the path cost of W A by 2 % .

8. Conclusions

This paper introduced the concept of blocked areas, which are sub-regions in grid maps where there is no viable path due to obstacles. In the context of grid-based optimal or sub-optimal pathfinding, the presence of blocked areas causes heuristic search algorithms to frequently explore irrelevant paths, significantly increasing search time in the process. To decrease search time, this paper presented a preprocessing approach that uses computational geometry techniques to identify blocked areas with polygon shapes in a grid map and store information about them into a memory-efficient balanced binary search tree. During actual pathfinding, the stored knowledge about blocked areas is used to avoid exploring paths inside blocked areas, which in turn reduces search time.
We evaluated the performance by comparing the execution times of A and W A before and after using blocked areas’ knowledge in pathfinding for a publicly available benchmark set that includes sixty maps of mazes and rooms. Our experimental results have shown that the execution times for both A and W A have been substantially decreased while preserving the optimality of A and the sub-optimality of W A . This is achieved for both short-distance and long-distance pathfinding. Furthermore, we calculated the worst-case bounds for the memory needed to store blocked areas’ information during preprocessing and the access time needed to retrieve this information during pathfinding and showed that those bounds are efficient.
Utilizing blocked areas’ knowledge during pathfinding is applicable beyond the A and W A algorithms. In future work, we will study the impact of combining blocked areas’ knowledge with other search algorithms in the literature.

Author Contributions

Conceptualization, F.J. and M.H.; methodology, F.J. and M.H.; software, F.J.; validation, F.J.; formal analysis, F.J.; investigation, F.J.; writing—original draft preparation, F.J.; writing—review and editing, M.H.; visualization, F.J.; All authors have read and agreed to the published version of the manuscript.

Funding

This research received no external funding.

Conflicts of Interest

The authors declare no conflict of interest.

Abbreviations

The following abbreviations are used in this manuscript:
BABlocked Area
MBRMinimum Bounding Rectangle
BA-treeBlocked Area Binary Search Tree

Appendix A

Table A1. Absolute execution times (in seconds) of A , A + B A , W A and W A + B A algorithms. Each map has hundreds of scenarios. Execution time is calculated for all scenarios combined.
Table A1. Absolute execution times (in seconds) of A , A + B A , W A and W A + B A algorithms. Each map has hundreds of scenarios. Execution time is calculated for all scenarios combined.
MapA A + BAWA WA + BAMapA A + BAWA WA + BA
maze-8-0606.13435.43395.50281.77room-8-088.8872.484.143.39
maze-8-11177.48839.201022.24713.94room-8-189.6472.063.993.32
maze-8-21253.47911.121175.24828.57room-8-285.8870.934.043.39
maze-8-31242.60892.601086.52777.95room-8-390.3171.484.163.38
maze-8-41486.421061.931340.09952.22room-8-492.7275.094.163.37
maze-8-51244.26918.891078.94815.13room-8-591.6872.424.193.39
maze-8-6952.46691.29758.50552.37room-8-689.0372.564.193.41
maze-8-71233.75860.231121.58776.59room-8-794.3175.264.203.46
maze-8-8860.89619.11699.58492.72room-8-891.1674.904.163.46
maze-8-9989.16715.01773.00557.57room-8-985.4769.334.083.33
maze-16-01329.34889.861288.10848.99room-16-0112.6666.346.394.41
maze-16-11050.80703.85923.91605.18room-16-1115.8866.197.865.02
maze-16-2915.98557.95745.92464.16room-16-2125.7575.787.544.89
maze-16-31436.52921.471363.56885.25room-16-3126.3876.147.365.00
maze-16-41279.73882.361153.61805.72room-16-4113.9066.997.094.68
maze-16-5856.22644.30624.59456.29room-16-5122.8570.297.204.89
maze-16-61498.60919.841318.68881.00room-16-6123.0670.127.294.74
maze-16-71252.22847.611082.52724.38room-16-7122.2173.107.495.01
maze-16-81678.081138.181667.931130.87room-16-8132.2279.578.315.46
maze-16-91013.88666.51873.78579.84room-16-9113.5967.477.074.44
maze-32-0866.32603.74747.96527.58room-32-0133.7162.4611.645.67
maze-32-1702.57429.94563.21337.46room-32-1136.5659.2415.047.09
maze-32-21156.95831.741054.09780.24room-32-2177.6780.8719.359.54
maze-32-31363.69920.051303.14861.31room-32-3156.6274.0516.297.98
maze-32-4810.20552.03665.51458.38room-32-4102.2550.5010.835.58
maze-32-5900.76602.67777.57568.65room-32-5136.1859.6213.386.50
maze-32-6893.30571.00755.84485.97room-32-6146.7367.3914.616.95
maze-32-7651.99443.38484.97321.80room-32-7145.3068.1915.317.29
maze-32-81109.12639.24929.74606.87room-32-8159.2471.0519.559.27
maze-32-91265.99834.111143.14734.76room-32-9179.2679.5419.588.60

References

  1. Hart, P.E.; Nilsson, N.J.; Raphael, B. A Formal Basis for The Heuristic Determination of Minimum Cost Paths. IEEE Trans. Syst. Sci. Cybern. 1968, 4, 100–107. [Google Scholar] [CrossRef]
  2. Dechter, R.; Pearl, J.; Raphael, B. Generalized Best-First Search Strategies and The Optimality of A. J. ACM 1985, 32, 505–536. [Google Scholar] [CrossRef]
  3. Pohl, I. Heuristic Search Viewed as Path Finding in a Graph. Artif. Intell. 1970, 1, 193–204. [Google Scholar] [CrossRef]
  4. Hawa, M. Light-Assisted A Path Planning. Eng. Appl. Artif. Intell. 2013, 26, 888–898. [Google Scholar] [CrossRef]
  5. Thayer, J.; Ruml, W. Faster than Weighted A: An Optimistic Approach to Bounded Suboptimal Search. In Proceedings of the 18th International Conference on Automated Planning and Scheduling, Delft, The Netherlands, 24–29 June 2008; pp. 355–362. [Google Scholar]
  6. Sturtevant, N. Benchmarks for Grid-Based Pathfinding. Trans. Comput. Intell. AI Games 2012, 4, 144–148. [Google Scholar] [CrossRef]
  7. Sturtevant, N.; Felner, A.; Barrer, M.; Schaeffer, J.; Burch, N. Memory-Based Heuristics for Explicit State Spaces. In Proceedings of the 21st International Joint Conference on Artificial Intelligence, Pasadena, CA, USA, 11–17 July 2009; Volume 9, pp. 609–614. [Google Scholar]
  8. Botea, A. Ultra-Fast Optimal Pathfinding Without Runtime Search. In Proceedings of the 6th Conference on Artificial Intelligence and Interactive Digital Entertainment, Stanford, CA, USA, 11–13 October 2010; pp. 144–148. [Google Scholar]
  9. Strasser, B.; Botea, A.; Harabor, D. Compressing Optimal Paths with Run Length Encoding. J. Artif. Intell. Res. 2015, 54, 593–629. [Google Scholar] [CrossRef]
  10. Xie, F.; Botea, A.; Kishimoto, A. Heuristic-Aided Compressed Distance Databases. In Proceedings of the Workshops at the 29th AAAI Conference on Artificial Intelligence, Austin Texas, TX, USA, 25–30 January 2015; pp. 85–91. [Google Scholar]
  11. Botea, A.; Müller, M.; Schaeffer, J. Near Optimal Hierarchical Path-Finding. J. Game Dev. 2004, 1, 7–28. [Google Scholar]
  12. Demyen, D.; Buro, M. Efficient Triangulation-Based Pathfinding. In Proceedings of the 21st Conference on Artificial Intelligence, Boston, MA, USA, 16–20 July 2006; Volume 1, pp. 942–947. [Google Scholar]
  13. Sturtevant, N. Memory-efficient Abstractions for Pathfinding. In Proceedings of the 3rd Conference on Artificial Intelligence and Interactive Digital Entertainment, Stanford, CA, USA, 6–8 June 2007; pp. 31–36. [Google Scholar]
  14. Uras, T.; Koenig, S.; Hernández, C. Subgoal Graphs for Optimal Pathfinding in Eight-Neighbor Grids. In Proceedings of the 23rd International Conference on Automated Planning and Scheduling, Rome, Italy, 10–14 June 2013; pp. 224–232. [Google Scholar]
  15. Björnsson, Y.; Halldórsson, K. Improved heuristics for optimal pathfinding on game maps. In Proceedings of the 2nd Conference on Artificial Intelligence and Interactive Digital Entertainment, Marina del Rey, CA, USA, 20–23 June 2006; pp. 9–14. [Google Scholar]
  16. Pochter, N.; Zohar, A.; Rosenschein, J. Using Swamps to Improve Optimal Pathfinding. In Proceedings of the 8th International Conference on Autonomous Agents and Multiagent Systems, Budapest, Hungary, 10–15 May 2009; Volume 2, pp. 1163–1164. [Google Scholar]
  17. Thayer, J.; Ruml, W. Bounded Suboptimal Search: A Direct Approach Using Inadmissible Estimates. In Proceedings of the 22nd International Joint Conference on Artificial Intelligence, Barcelona, Spain, 16–22 July 2011; pp. 674–679. [Google Scholar]
  18. Harabor, D.; Grastien, A. Online Graph Pruning for Pathfinding on Grid Maps. In Proceedings of the 25th Conference on Artificial Intelligence, San Francisco, CA, USA, 7–11 August 2011; pp. 1114–1119. [Google Scholar]
  19. Sturtevant, N. The Grid-Based Path Planning Competition. AI Mag. 2014, 35, 66–69. [Google Scholar] [CrossRef] [Green Version]
  20. Sturtevant, N.; Traish, J.; Tulip, J.; Uras, T.; Koenig, S.; Strasser, B.; Botea, A.; Harabor, D.; Rabin, S. The grid-based path planning competition: 2014 entries and results. In Proceedings of the Annual Symposium on Combinatorial Search, Ein Gedi, Israel, 11–13 June 2015. [Google Scholar]
  21. Bast, H.; Delling, D.; Goldberg, A.; Müller-Hannemann, M.; Pajor, T.; Sanders, P.; Wagner, D.; Werneck, R.F. Route Planning in Transportation Networks. In Algorithm Engineering, Lecture Notes in Computer Science Book Series; Kliemann, L., Sanders, P., Eds.; Springer: Cham, Switzerland, 2016; Volume 9220, pp. 19–80. [Google Scholar]
  22. Geisberger, R.; Sanders, P.; Schultes, D.; Delling, D. Contraction Hierarchies: Faster and Simpler Hierarchical Routing in Road Networks. In Experimental Algorithms. WEA 2008 30 May-1 June, Provincetown, MA, USA. Lecture Notes in Computer Science Book Series; McGeoch, C.C., Ed.; Springer: Cham, Switzerland, 2012; Volume 5038, pp. 319–333. [Google Scholar]
  23. Bentley, J.; Ottmann, T. Algorithms for Reporting and Counting Geometric Intersections. IEEE Trans. Comput. 1979, c–28, 643–647. [Google Scholar] [CrossRef]
  24. Chazelle, B.; Edelsbrunner, H. An Optimal Algorithm for Intersecting Line Segments in the Plane. J. ACM 1992, 39, 1–54. [Google Scholar] [CrossRef]
  25. Guttman, A. R-Trees: A Dynamic Index Structure for Spatial Searching. In Proceedings of the ACM SIGMOD International Conference on Management of Data, Boston, MA, USA, 8–21 June 1984; pp. 47–57. [Google Scholar]
  26. Manolopoulos, Y.; Nanopoulos, A.; Papadopoulos, A.N.; Theodoridis, Y. R-Trees: Theory and Applications; Springer: Berlin/Heidelberg, Germany, 2006. [Google Scholar]
  27. Hormann, K.; Agathos, A. The point in polygon problem for arbitrary polygons. Comput. Geom. 2001, 20, 131–144. [Google Scholar] [CrossRef] [Green Version]
  28. De Berg, M.; Cheong, O.; van Kreveld, M.; Overmars, M. Computational Geometry: Algorithms and Applications, 3rd ed.; Springer: Berlin/Heidelberg, Germany, 2008. [Google Scholar]
  29. Burns, E.; Hatem, M.; Leighton, M.J.; Ruml, W. Implementing Fast Heuristic Search Code. In Proceedings of the Annual Symposium on Combinatorial Search, Niagara Falls, ON, Canada, 19–21 July 2012. [Google Scholar]
  30. Holte, R.C. Common Misconceptions Concerning Heuristic Search. In Proceedings of the Annual Symposium on Combinatorial Search, Niagara Falls, ON, Canada, 19–21 July 2012. [Google Scholar]
Figure 1. Visited nodes (shown in dark grey) during optimal pathfinding using A and sub-optimal pathfinding using weighted A ( W A ) (with ϵ = 3.0 ) for the path shown in red. Note that the source node is at the right-bottom and the goal node is the left-bottom of the map.
Figure 1. Visited nodes (shown in dark grey) during optimal pathfinding using A and sub-optimal pathfinding using weighted A ( W A ) (with ϵ = 3.0 ) for the path shown in red. Note that the source node is at the right-bottom and the goal node is the left-bottom of the map.
Symmetry 12 01186 g001
Figure 2. The impact of using the blocked areas’ knowledge on reducing the number of visited nodes in optimal and sub-optimal pathfinding for the same path in Figure 1.
Figure 2. The impact of using the blocked areas’ knowledge on reducing the number of visited nodes in optimal and sub-optimal pathfinding for the same path in Figure 1.
Symmetry 12 01186 g002
Figure 3. A 2D grid map of a 199 × 232 maze with 11 horizontal and 13 vertical line-segment obstacles. The x-coordinates of the horizontal obstacles and the y-coordinates of the vertical obstacles are shown on the left and the upper sides of the map, respectively. In the map, there are 43 corners marked as C 1 , C 2 , …, C 43 and 17 blocked areas marked as A 1 , A 2 , …, A 17 . The blocked areas in the map (excluding their entrances) are shown as shaded grey areas.
Figure 3. A 2D grid map of a 199 × 232 maze with 11 horizontal and 13 vertical line-segment obstacles. The x-coordinates of the horizontal obstacles and the y-coordinates of the vertical obstacles are shown on the left and the upper sides of the map, respectively. In the map, there are 43 corners marked as C 1 , C 2 , …, C 43 and 17 blocked areas marked as A 1 , A 2 , …, A 17 . The blocked areas in the map (excluding their entrances) are shown as shaded grey areas.
Symmetry 12 01186 g003
Figure 4. The BA-tree constructed by Algorithm 4 for the maze in Figure 3: (a) All generated minimum bounding rectangles (MBRs) are shown (different colors are used to help the reader distinguish each MBR). MBRs are numbered by the order of their creation by Algorithm 4; (b) The BA-tree is shown. Rectangle shapes are used for internal nodes to highlight the fact that they represent MBRs. In addition, each rectangle have four numbers shown on each one of its sides to show its x u p p e r , x l o w e r , y l e f t and y r i g h t coordinates. Each leaf node may have only one or two blocked areas.
Figure 4. The BA-tree constructed by Algorithm 4 for the maze in Figure 3: (a) All generated minimum bounding rectangles (MBRs) are shown (different colors are used to help the reader distinguish each MBR). MBRs are numbered by the order of their creation by Algorithm 4; (b) The BA-tree is shown. Rectangle shapes are used for internal nodes to highlight the fact that they represent MBRs. In addition, each rectangle have four numbers shown on each one of its sides to show its x u p p e r , x l o w e r , y l e f t and y r i g h t coordinates. Each leaf node may have only one or two blocked areas.
Symmetry 12 01186 g004
Figure 5. Two search examples using the BA-tree in Figure 4. Searched nodes are shown in grey.
Figure 5. Two search examples using the BA-tree in Figure 4. Searched nodes are shown in grey.
Symmetry 12 01186 g005
Figure 6. Relative execution times across different path costs in mazes.
Figure 6. Relative execution times across different path costs in mazes.
Symmetry 12 01186 g006
Figure 7. Relative execution times across different path costs in rooms.
Figure 7. Relative execution times across different path costs in rooms.
Symmetry 12 01186 g007
Table 1. Complexity analysis of Algorithm 2’s execution time.
Table 1. Complexity analysis of Algorithm 2’s execution time.
LinesUpper Bound ComplexityExplanation
1( T V + T H ) log 2 ( T V + T H ) + R Sweep Line Algorithm
2NExtracting N corners from R intersections
3NInitializing union-find with N corners
4 – 10 N + N log 2 N The Partition and Sort method applied for a sub-list of corners inside a loop
11 – 18 N log 2 N Sorting a sub-list of corners inside a loop
19 – 23( T V + T H + P ) log 2 ( T V + T H + P ) + P Sweep Line Algorithm
Table 2. The benchmark set used for performance evaluation in this paper. S is the number of scenarios available from the pathfinding benchmarks library. B% is the percentage of obstacle nodes in the map. H is the number of horizontal line-segment obstacles. V is the number of vertical line-segment obstacles. R is the number of intersections between horizontal and vertical line-segment obstacles. N is the number of corners generated from these intersections.
Table 2. The benchmark set used for performance evaluation in this paper. S is the number of scenarios available from the pathfinding benchmarks library. B% is the percentage of obstacle nodes in the map. H is the number of horizontal line-segment obstacles. V is the number of vertical line-segment obstacles. R is the number of intersections between horizontal and vertical line-segment obstacles. N is the number of corners generated from these intersections.
MapSB%HVRNMapSB%HVRN
maze-8-0543311%81780415862315room-8-0183021%33183332396712,560
maze-8-1851611%83777915872334room-8-1180521%33463340396012,516
maze-8-2914811%81880315912370room-8-2178521%33013314396312,532
maze-8-3928211%84778916072369room-8-3178621%32803329396212,539
maze-8-410,79611%80878015532323room-8-4184021%33443269395612,555
maze-8-5930411%79379515522286room-8-5180021%33413306396312,564
maze-8-6708711%83881416192408room-8-6181121%33093345395112,562
maze-8-7936011%81778815752368room-8-7185721%33123385397212,528
maze-8-8666711%82482916212368room-8-8183821%33293300396112,519
maze-8-9748611%82979615922341room-8-9178721%33123293396412,588
maze-16-084126%245232463678room-16-0183312%87288110153510
maze-16-173946%248237468689room-16-1185412%86787610143527
maze-16-262316%240224442664room-16-2189812%90089810123499
maze-16-388276%252229465680room-16-3189612%89189710143507
maze-16-481956%243228458688room-16-4185212%87986610163518
maze-16-563736%242228456677room-16-5186112%90590110133500
maze-16-687236%260237482697room-16-6186612%87888410173509
maze-16-779656%241229453678room-16-7187512%89488710123508
maze-16-810,4946%241235461672room-16-8189612%90687010103503
maze-16-967236%231246463682room-16-9182112%100595410113489
maze-32-056033%7062122173room-32-018448%391341256915
maze-32-147873%6553110165room-32-118936%248252256929
maze-32-269383%6661118177room-32-220156%220214255931
maze-32-372823%6557113176room-32-319287%313313256922
maze-32-452273%6560117167room-32-4166510%365418248897
maze-32-557443%6765121177room-32-518447%285277254929
maze-32-655193%7166129181room-32-618966%257244256927
maze-32-745333%6359114164room-32-718887%311311255923
maze-32-860983%6561117174room-32-819596%225222256933
maze-32-972433%5754104154room-32-920056%247255256929
Table 3. Preprocessing evaluation for all sixty benchmarks in Table 2. B A is the number of blocked areas. i n s i d e B A % is the percentage of nodes covered by blocked areas. j o i n t s % is the percentage of all nodes stored in blocked areas. B A S i z e is the total number of nodes in the BA-tree. S e a r c h is the worst-case number of searched nodes when accessing the BA-tree using Algorithm 5.
Table 3. Preprocessing evaluation for all sixty benchmarks in Table 2. B A is the number of blocked areas. i n s i d e B A % is the percentage of nodes covered by blocked areas. j o i n t s % is the percentage of all nodes stored in blocked areas. B A S i z e is the total number of nodes in the BA-tree. S e a r c h is the worst-case number of searched nodes when accessing the BA-tree using Algorithm 5.
MapBAinsideBA%joints%BASizeSearchMapBAinsideBA%joints%BASizeSearch
maze-8-087235.2%1.3%102345room-8-0393225.2%5.4%409563
maze-8-189635.4%1.3%102351room-8-1388924.6%5.3%409561
maze-8-292335.6%1.3%102351room-8-2388124.3%5.3%409561
maze-8-388934.3%1.3%102349room-8-3390625.0%5.3%409559
maze-8-490235.8%1.3%102347room-8-4383324.6%5.2%409557
maze-8-582833.2%1.2%102355room-8-5393125.5%5.4%409559
maze-8-696035.7%1.3%102353room-8-6386225.0%5.3%409555
maze-8-789736.8%1.3%102349room-8-7384724.9%5.3%409557
maze-8-893335.6%1.3%102353room-8-8387024.0%5.3%409559
maze-8-990335.3%1.3%102351room-8-9384625.3%5.3%409571
maze-16-025637.5%0.4%25541room-16-0200740.4%2.5%204759
maze-16-126137.0%0.4%26541room-16-1195442.8%2.5%204761
maze-16-226239.3%0.4%26741room-16-2196740.2%2.5%204755
maze-16-325438.9%0.4%25537room-16-3195240.5%2.5%204753
maze-16-424933.9%0.4%25539room-16-4196842.2%2.5%204751
maze-16-523034.6%0.3%25537room-16-5196140.8%2.5%204761
maze-16-628038.1%0.4%30337room-16-6195541.7%2.5%204753
maze-16-725337.3%0.4%25537room-16-7199140.3%2.5%204753
maze-16-825235.8%0.4%25545room-16-8191341.5%2.5%204751
maze-16-924838.3%0.4%25537room-16-9197540.4%2.5%204757
maze-32-07237.5%0.1%7933room-32-064249.0%0.8%77147
maze-32-16540.7%0.1%6529room-32-162551.2%0.8%73745
maze-32-27039.0%0.1%7525room-32-262452.2%0.8%73543
maze-32-36832.3%0.1%7131room-32-363751.1%0.8%76147
maze-32-46334.3%0.1%6325room-32-461852.4%0.8%72351
maze-32-57434.0%0.1%8327room-32-563851.5%0.8%76343
maze-32-68544.7%0.1%10533room-32-663151.9%0.8%74945
maze-32-76838.4%0.1%7123room-32-762952.8%0.8%74547
maze-32-86945.0%0.1%7325room-32-863250.7%0.8%75145
maze-32-95636.1%0.1%6331room-32-962852.0%0.8%74347
Table 4. Average relative execution time and search space of A + B A with respect to A and W A + B A with respect to W A .
Table 4. Average relative execution time and search space of A + B A with respect to A and W A + B A with respect to W A .
MazeA + BA w.r.t A WA w.r.t WA + BA
Execution TimeSearch SpaceExecution TimeSearch Space
maze-80.740.660.750.67
maze-160.700.660.710.67
maze-320.710.680.700.67
room-80.850.780.840.82
room-160.670.640.700.66
room-320.560.550.570.53

Share and Cite

MDPI and ACS Style

Jubair, F.; Hawa, M. Exploiting Obstacle Geometry to Reduce Search Time in Grid-Based Pathfinding. Symmetry 2020, 12, 1186. https://doi.org/10.3390/sym12071186

AMA Style

Jubair F, Hawa M. Exploiting Obstacle Geometry to Reduce Search Time in Grid-Based Pathfinding. Symmetry. 2020; 12(7):1186. https://doi.org/10.3390/sym12071186

Chicago/Turabian Style

Jubair, Fahed, and Mohammed Hawa. 2020. "Exploiting Obstacle Geometry to Reduce Search Time in Grid-Based Pathfinding" Symmetry 12, no. 7: 1186. https://doi.org/10.3390/sym12071186

Note that from the first issue of 2016, this journal uses article numbers instead of page numbers. See further details here.

Article Metrics

Back to TopTop