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 and weighted (), 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 and is evaluated using publicly available benchmark set, consisting of sixty grid maps of mazes and rooms. In mazes, the search time for both and is reduced by , on average. In rooms, the search time for both and is reduced by , on average. This is achieved while preserving the search optimality of and the search sub-optimality of .
1. Introduction
Grid-based pathfinding has been the subject of considerable interest in a number of fields such as video games and robotics navigation. [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 algorithm, researchers typically focus on finding new heuristic functions that reduce the number of visited nodes (i.e., search space) during pathfinding.
is optimal if the used heuristic function is admissible, i.e., never overestimates when predicting the distance to reach the goal [2]. Weighted () [3] relaxes the admissibility rule and multiplies the heuristic function by a factor . 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 and (with ) when trying to find the same path in an 8-neighbor grid map of a 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 led it to prioritizing the exploration of the closer nodes to the goal, which resulted in finding a different, sup-optimal path. By contrast, slowly explores all similar nodes, i.e., nodes with the same cost, to guarantee optimality (as shown by Figure 1b).
Figure 1.
Visited nodes (shown in dark grey) during optimal pathfinding using and sub-optimal pathfinding using weighted () (with ) 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.
is a simple yet effective extension of and is still in wide use to this day [4,5]. However, , as well as , 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 and 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.
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.
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 and 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 and 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 is reduced by 34%, on average, for both mazes and rooms. This results in a significant reduction in search time for both and . Specifically, in mazes, the execution times of both and were reduced by 10–35% (the average is ). In rooms, the execution times of both and were reduced by 5– (the average is ). 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 and 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 and . Section 8 concludes the paper.
2. Related Work
Several heuristic search algorithms in the literature, such as and , 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 and , 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 and 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, 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 , the movement cost from n to m is represented by the function c(n,m):
Algorithm 1 shows the pseudo code for the classical algorithm, which finds the shortest path between a source node s and a goal node g in a grid map G. 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 (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 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
where is the number of horizontal steps and is the number of vertical steps from q to g. Note that minimum(,) represents the number of diagonal steps from q to g.
| Algorithm 1 pathfinding |
|
has the same pseudo code in Algorithm 1 with only one modification: it calculates fscore(q) = gscore(q) + × hscore(q), . 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 is bounded by × the cost of the optimal path [2].
The speed at which the algorithm, as well as the 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 (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 (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 (A). Both of these sets are mutually exclusive, i.e., if node (A), then (A), and vice versa. We also define (A) to be the set of all nodes n such that (A) and (A).
Given the aforementioned definition of a blocked area, all nodes in (A) and (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 (A) and a node (A).
- Property 2
- There is always a shortest path between two nodes and (A) such that this path does not pass by any node (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 (s,g) denote a path between s and g, where s, g∈(A). Additionally, let us assume this path passes by a node (A). In order to prove Lemma 1, we need to show that there is another path, i.e., (s,g), such that n ∉ (s,g).
First, because n ∈ (s,g), we can rewrite (s,g) = (s,n) + (n,g). Next, because (A), both (s,n) and (n,g) cross A’s entrance. Therefore, we can rewrite (s,g) = (s,x) + (x,n) + (n,y) + (y,g), where nodes x and (A). Note that (x,n) and (n,y) exist (Property 1). Next, because x and (A), (x,y) exists such that (x,y) (Property 2). Therefore, we can construct a new path (s,g) such that (s,g) = (s,x) + (x,y) + (y,g), where all nodes in (s,x), (x,y) and (y,g) (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 (s,g) denote a path between s and g (s, g∈(A)) such that it passes by a node (A). Additionally, let (s,g) be an optimal path with cost c. From Lemma 1, there is at least one path between s and g, denoted (s,g), such that (s,g). Let be the cost of (s,g). In order to prove Lemma 2, we need to show that = c.
As we showed earlier, we can write (s,g) = (s,x) + (x,n) + (n,y) + (y,g) and (s,g) = (s,x) + (x,y) + (y,g), where nodes x and (A). Let , and be the cost of (x,n), (n,y) and (x,y), respectively. Thus, . To show that = c, we need to show .
First, because c is optimal, . Thus, . Second, due to Property 2, (x,y) is optimal, i.e., it has a less or equal length to (x,n) + (n,y). Therefore, , which leads to . Combining both inequalities, the only possible solution is . □
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., = (,) and = (,), 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 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 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 , , and are generated, where is represented by (67,67)→(100,67)→(100,34), is represented by (67,67)→(100,67)→(100,100), is represented by (133,67)→(100,67)→(100,34) and is represented by (133,67)→(100,67)→(100,100).
Figure 3.
A 2D grid map of a 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 , , …, and 17 blocked areas marked as , , …, . The blocked areas in the map (excluding their entrances) are shown as shaded grey areas.
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 is bound by the continuously connected corners (written in counterclockwise order): , , and . Similarly, blocked area is bound by the continuously connected corners: , , , and . An interesting case is , which is a triangular-shaped blocked area that was formed by the single corner .
A polygon-shaped blocked area is represented by its perimeter joint points, which can be extracted from its corners. For example, consider blocked area in Figure 3, which is formed by the corners , and (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 , and , respectively. The first and the last points are the free points in and . 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): , , …, can be represented by joint points: , , , …, , , where is the intersection point of corner and and are the free points of the two corners and , respectively. The entrance is represented by the straight line between and .
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 , , , , , and 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 , and . Downward corners are the corners with their vertical side located downward from the horizontal line-segment obstacle, which include , , and . 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 , and . The first adjacent pair (, ) are not connected because they have the same intersection point, while the second adjacent pair (, ) are connected due to having distinct intersection points. Similarly, sorting the downward corners will give , , and , where only two adjacent pairs are connected: (, ) and (, ). 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 |
|
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 |
|
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, and 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 , , and , 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 or 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 or 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 is the number of vertical line-segment obstacles, 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:
- The maximum number of possible intersections occurs when every vertical line-segment obstacle intersects with every horizontal line-segment obstacle.
- Each intersection generates anywhere between one to four corners.
- 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 . 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 is , the Partition and Sort needs linear time (i.e., ) to partition the corners and linearithmic time (i.e., ) to sort the corners. Due to having a loop, the overall execution of the Partition and Sort method is bound by . 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 .
Table 1.
Complexity analysis of Algorithm 2’s execution time.
By taking into account the above three inequalities, the entire execution of Algorithm 2 is bound by () +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 is the number of joints in blocked area , the total number of extra pointers needed to store all blocked areas is . 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(, , …, ) to be the smallest rectangle that bounds a group of m blocked areas: , , …, . An MBR is represented by four coordinates: , the coordinate of the upper-most row; , the coordinate of the lower-most row; , the coordinate of the left-most column; , the coordinate of the right-most column. For example, in Figure 3, MBR(, , , ) is represented by , , and .
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 blocked areas are put in the same MBR. Each MBR is then partitioned horizontally into two MBRs such that each nearby 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 nodes, which are generated from partitioning the 2 nodes at level 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.
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 , , and coordinates. Each leaf node may have only one or two blocked areas.
Lemma 4.
Assuming m is the number of blocked areas in a grid map, the height of the BA-tree is .
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 .
Without loss of generality, let us first assume the simple case when m is a power of 2, i.e., , where d is some integer. In this case, the levels of the BA-tree are: 0, 1, …, , where 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 = .
In the general case, let h be the height of the BA-tree. Furthermore, let d be an integer such that . First, because and is the height of a tree with nodes (as shown by the simple case). Second, because and is the height of a tree with nodes. Combining both inequalities, we can write . As a result that h is an integer, the only possible solution is . As a result that (generated from applying the logarithm function to the inequality ), then . □
| Algorithm 4 BA-tree Construction Functions |
|
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 or level h.
Without loss of generality, let us first assume the simple case when m is a power of 2, i.e., , 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 (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 . As a result of , there are no leaf nodes that can be located at a level that is smaller than (as shown by the simple case). Furthermore, because , the maximum level in the BA-tree is (Lemma 4). Thus, all leaf nodes can only be located at levels and . As a result of (Lemma 4), we can also infer that all leaf nodes are located at levels 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 .
Proof.
As a result that the number of nodes in level i is at most , the maximum number of nodes in the BA-tree is bound by . This is a geometric series that is equal to . , . Thus, . □
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 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 . 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 , where n is the number of integers). At each level j in the BA-tree, there are nodes, i.e., subproblems. Each subproblem’s execution time is bound by sorting blocked areas. Therefore, the amount of work done by all nodes in level j is . As a result that the height of the tree is (Lemma 4), the amount of work done to construct all levels in the BA-tree is bound by . In general, the execution time is bound by .
We now present a memory consumption analysis for the BA-tree. As shown by Corollary 1, the number of internal nodes is bound by , where m is the number of blocked areas. Each internal node stores four integers (the coordinates of its MBR) and two pointers ( and ). Assuming pointers and integers require the same amount of memory, all internal nodes need to store no more than 6 × () 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: , , …, . 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 MBR(e), then the search for the descendent nodes of e is terminated (lines 9–11). This is because, if MBR(e), it is predetermined that any of the descendent blocked areas of e. In the case 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 MBR(e) or not is straightforward: MBR(e) if and only if and . 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 |
|
Figure 5.
Two search examples using the BA-tree in Figure 4. Searched nodes are shown in grey.
The worst-case scenario in Algorithm 5 occurs when a search function visits all the nodes in the BA-tree, which is bound by (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 (Lemma 4), the average-case execution time of Algorithm 5 is , 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 and 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 and . All four search algorithms: , , and 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 algorithm. Compared to the standard implementation of (shown in Algorithm 1), Algorithm 6 has two modifications. First, before adding node q into the , 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 (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 list and therefore discarded from the search space. and have the same implementations as and , respectively, except that they calculate fscore(q) = gscore(q) + × hscore(q), where is a real number that controls the inflation of the heuristic function hscore(q). In this paper, we set .
| Algorithm 6 pathfinding |
|
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 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.
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.
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 (); (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 (); and (v) the worst-case number of searched nodes when accessing the BA-tree ().
Table 3.
Preprocessing evaluation for all sixty benchmarks in Table 2. is the number of blocked areas. is the percentage of nodes covered by blocked areas. is the percentage of all nodes stored in blocked areas. is the total number of nodes in the BA-tree. is the worst-case number of searched nodes when accessing the BA-tree using Algorithm 5.
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 , and , respectively. On average, the percentages of covered nodes in room-8, room-16 and room-32 are , and , 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 of the total number of nodes in mazes and is less than 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 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) versus ; and (ii) versus . 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 when performing pathfinding for a particular map is 500 milliseconds, while the execution time for when performing the same pathfinding is 300 milliseconds. In this case, the relative execution time is , which demonstrates that the execution time of was reduced by 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:
where is the number of scenarios in map instance i; is the execution time when performing pathfinding using for scenario j in map instance i; and is the execution time when performing pathfinding using 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 over 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 and were reduced by , which translated into a reduction in execution time by , on average. In room maps, the search spaces of were reduced by , and , on average, for room-8, room-16 and room-32, respectively. As a result, the execution times were reduced by , and , respectively. In the case of , on average, the search spaces for room-8, room-16 and room-32 were reduced by , and , respectively. This caused the execution time to be reduced by , and , respectively.
Table 4.
Average relative execution time and search space of with respect to and with respect to .
The performance results in Table 4 can be explained by 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 , on average). Thus, they have a similar performance in Table 4. On the other hand, room maps have different values, which explains their varying performance. For example, room-32, where the coverage percentage is the highest (, on average), the execution time was reduced by , on average. However, in the case of room-8, where the coverage is the lowest (, on average), the execution time was reduced by , 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 and . 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.
Relative execution times across different path costs in mazes.
Figure 7.
Relative execution times across different path costs in rooms.
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 , the execution time is reduced by for low path costs, and then this reduction steadily improves as the path cost increases, to reach around 35%, for high path costs. In , the reduction in execution time varies from in low path costs to 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 , in the case of room-32, the reduction in execution time starts from a moderate , and then sharply improves as the path cost increases to reach for paths with high costs. In room-16, the reduction in execution time starts from in low path costs and quickly increases to reach in high path costs. In room-8, the reduction in execution time gradually increases from in low path costs to in high path costs. In , 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 for low path costs and then sharply improves to reach in high path costs (with the exception of one case). In room-16, the reduction in execution time varies between and while having less consistent behavior. In room-8, the reduction in execution time varies between and 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 and were reduced by 10– (the average reduction is ). In all three types of rooms, in general, the execution times of both and were reduced by 5– (the average reduction is ). 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 to find a different path from the one found by . 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 and , 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 found paths with lower costs than . This is because the exploration of blocked areas led in some cases to find a longer path. On average, reduces the path cost of by .
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 and 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 and have been substantially decreased while preserving the optimality of and the sub-optimality of . 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 and 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:
| BA | Blocked Area |
| MBR | Minimum Bounding Rectangle |
| BA-tree | Blocked Area Binary Search Tree |
Appendix A
Table A1.
Absolute execution times (in seconds) of , , and algorithms. Each map has hundreds of scenarios. Execution time is calculated for all scenarios combined.
Table A1.
Absolute execution times (in seconds) of , , and algorithms. Each map has hundreds of scenarios. Execution time is calculated for all scenarios combined.
| Map | A | A + BA | WA | WA + BA | Map | A | A + BA | WA | WA + BA |
|---|---|---|---|---|---|---|---|---|---|
| maze-8-0 | 606.13 | 435.43 | 395.50 | 281.77 | room-8-0 | 88.88 | 72.48 | 4.14 | 3.39 |
| maze-8-1 | 1177.48 | 839.20 | 1022.24 | 713.94 | room-8-1 | 89.64 | 72.06 | 3.99 | 3.32 |
| maze-8-2 | 1253.47 | 911.12 | 1175.24 | 828.57 | room-8-2 | 85.88 | 70.93 | 4.04 | 3.39 |
| maze-8-3 | 1242.60 | 892.60 | 1086.52 | 777.95 | room-8-3 | 90.31 | 71.48 | 4.16 | 3.38 |
| maze-8-4 | 1486.42 | 1061.93 | 1340.09 | 952.22 | room-8-4 | 92.72 | 75.09 | 4.16 | 3.37 |
| maze-8-5 | 1244.26 | 918.89 | 1078.94 | 815.13 | room-8-5 | 91.68 | 72.42 | 4.19 | 3.39 |
| maze-8-6 | 952.46 | 691.29 | 758.50 | 552.37 | room-8-6 | 89.03 | 72.56 | 4.19 | 3.41 |
| maze-8-7 | 1233.75 | 860.23 | 1121.58 | 776.59 | room-8-7 | 94.31 | 75.26 | 4.20 | 3.46 |
| maze-8-8 | 860.89 | 619.11 | 699.58 | 492.72 | room-8-8 | 91.16 | 74.90 | 4.16 | 3.46 |
| maze-8-9 | 989.16 | 715.01 | 773.00 | 557.57 | room-8-9 | 85.47 | 69.33 | 4.08 | 3.33 |
| maze-16-0 | 1329.34 | 889.86 | 1288.10 | 848.99 | room-16-0 | 112.66 | 66.34 | 6.39 | 4.41 |
| maze-16-1 | 1050.80 | 703.85 | 923.91 | 605.18 | room-16-1 | 115.88 | 66.19 | 7.86 | 5.02 |
| maze-16-2 | 915.98 | 557.95 | 745.92 | 464.16 | room-16-2 | 125.75 | 75.78 | 7.54 | 4.89 |
| maze-16-3 | 1436.52 | 921.47 | 1363.56 | 885.25 | room-16-3 | 126.38 | 76.14 | 7.36 | 5.00 |
| maze-16-4 | 1279.73 | 882.36 | 1153.61 | 805.72 | room-16-4 | 113.90 | 66.99 | 7.09 | 4.68 |
| maze-16-5 | 856.22 | 644.30 | 624.59 | 456.29 | room-16-5 | 122.85 | 70.29 | 7.20 | 4.89 |
| maze-16-6 | 1498.60 | 919.84 | 1318.68 | 881.00 | room-16-6 | 123.06 | 70.12 | 7.29 | 4.74 |
| maze-16-7 | 1252.22 | 847.61 | 1082.52 | 724.38 | room-16-7 | 122.21 | 73.10 | 7.49 | 5.01 |
| maze-16-8 | 1678.08 | 1138.18 | 1667.93 | 1130.87 | room-16-8 | 132.22 | 79.57 | 8.31 | 5.46 |
| maze-16-9 | 1013.88 | 666.51 | 873.78 | 579.84 | room-16-9 | 113.59 | 67.47 | 7.07 | 4.44 |
| maze-32-0 | 866.32 | 603.74 | 747.96 | 527.58 | room-32-0 | 133.71 | 62.46 | 11.64 | 5.67 |
| maze-32-1 | 702.57 | 429.94 | 563.21 | 337.46 | room-32-1 | 136.56 | 59.24 | 15.04 | 7.09 |
| maze-32-2 | 1156.95 | 831.74 | 1054.09 | 780.24 | room-32-2 | 177.67 | 80.87 | 19.35 | 9.54 |
| maze-32-3 | 1363.69 | 920.05 | 1303.14 | 861.31 | room-32-3 | 156.62 | 74.05 | 16.29 | 7.98 |
| maze-32-4 | 810.20 | 552.03 | 665.51 | 458.38 | room-32-4 | 102.25 | 50.50 | 10.83 | 5.58 |
| maze-32-5 | 900.76 | 602.67 | 777.57 | 568.65 | room-32-5 | 136.18 | 59.62 | 13.38 | 6.50 |
| maze-32-6 | 893.30 | 571.00 | 755.84 | 485.97 | room-32-6 | 146.73 | 67.39 | 14.61 | 6.95 |
| maze-32-7 | 651.99 | 443.38 | 484.97 | 321.80 | room-32-7 | 145.30 | 68.19 | 15.31 | 7.29 |
| maze-32-8 | 1109.12 | 639.24 | 929.74 | 606.87 | room-32-8 | 159.24 | 71.05 | 19.55 | 9.27 |
| maze-32-9 | 1265.99 | 834.11 | 1143.14 | 734.76 | room-32-9 | 179.26 | 79.54 | 19.58 | 8.60 |
References
- 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]
- 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]
- Pohl, I. Heuristic Search Viewed as Path Finding in a Graph. Artif. Intell. 1970, 1, 193–204. [Google Scholar] [CrossRef]
- Hawa, M. Light-Assisted A★ Path Planning. Eng. Appl. Artif. Intell. 2013, 26, 888–898. [Google Scholar] [CrossRef]
- 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]
- Sturtevant, N. Benchmarks for Grid-Based Pathfinding. Trans. Comput. Intell. AI Games 2012, 4, 144–148. [Google Scholar] [CrossRef]
- 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]
- 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]
- Strasser, B.; Botea, A.; Harabor, D. Compressing Optimal Paths with Run Length Encoding. J. Artif. Intell. Res. 2015, 54, 593–629. [Google Scholar] [CrossRef]
- 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]
- Botea, A.; Müller, M.; Schaeffer, J. Near Optimal Hierarchical Path-Finding. J. Game Dev. 2004, 1, 7–28. [Google Scholar]
- 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]
- 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]
- 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]
- 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]
- 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]
- 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]
- 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]
- Sturtevant, N. The Grid-Based Path Planning Competition. AI Mag. 2014, 35, 66–69. [Google Scholar] [CrossRef][Green Version]
- 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]
- 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]
- 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]
- Bentley, J.; Ottmann, T. Algorithms for Reporting and Counting Geometric Intersections. IEEE Trans. Comput. 1979, c–28, 643–647. [Google Scholar] [CrossRef]
- Chazelle, B.; Edelsbrunner, H. An Optimal Algorithm for Intersecting Line Segments in the Plane. J. ACM 1992, 39, 1–54. [Google Scholar] [CrossRef]
- 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]
- Manolopoulos, Y.; Nanopoulos, A.; Papadopoulos, A.N.; Theodoridis, Y. R-Trees: Theory and Applications; Springer: Berlin/Heidelberg, Germany, 2006. [Google Scholar]
- Hormann, K.; Agathos, A. The point in polygon problem for arbitrary polygons. Comput. Geom. 2001, 20, 131–144. [Google Scholar] [CrossRef]
- De Berg, M.; Cheong, O.; van Kreveld, M.; Overmars, M. Computational Geometry: Algorithms and Applications, 3rd ed.; Springer: Berlin/Heidelberg, Germany, 2008. [Google Scholar]
- 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]
- 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]
© 2020 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (http://creativecommons.org/licenses/by/4.0/).