Pathfinding 2D Illustration
   HOME

TheInfoList



OR:

Pathfinding or pathing is the search, by a computer application, for the shortest route between two points. It is a more practical variant on solving mazes. This field of research is based heavily on
Dijkstra's algorithm Dijkstra's algorithm ( ) is an algorithm for finding the shortest paths between nodes in a weighted graph, which may represent, for example, a road network. It was conceived by computer scientist Edsger W. Dijkstra in 1956 and published three ...
for finding the shortest path on a
weighted graph This is a glossary of graph theory. Graph theory is the study of graphs, systems of nodes or vertices connected in pairs by lines or edges. Symbols A B ...
. Pathfinding is closely related to the
shortest path problem In graph theory, the shortest path problem is the problem of finding a path between two vertices (or nodes) in a graph such that the sum of the weights of its constituent edges is minimized. The problem of finding the shortest path between t ...
, within
graph theory In mathematics and computer science, graph theory is the study of ''graph (discrete mathematics), graphs'', which are mathematical structures used to model pairwise relations between objects. A graph in this context is made up of ''Vertex (graph ...
, which examines how to identify the path that best meets some criteria (shortest, cheapest, fastest, etc) between two points in a large network.


Algorithms

At its core, a pathfinding method searches a
graph Graph may refer to: Mathematics *Graph (discrete mathematics), a structure made of vertices and edges **Graph theory, the study of such graphs and their properties *Graph (topology), a topological space resembling a graph in the sense of discret ...
by starting at one vertex and exploring adjacent
node In general, a node is a localized swelling (a "knot") or a point of intersection (a vertex). Node may refer to: In mathematics * Vertex (graph theory), a vertex in a mathematical graph *Vertex (geometry), a point where two or more curves, lines ...
s until the destination node is reached, generally with the intent of finding the cheapest route. Although graph searching methods such as a
breadth-first search Breadth-first search (BFS) is an algorithm for searching a tree data structure for a node that satisfies a given property. It starts at the tree root and explores all nodes at the present depth prior to moving on to the nodes at the next dept ...
would find a route if given enough time, other methods, which "explore" the graph, would tend to reach the destination sooner. An analogy would be a person walking across a room; rather than examining every possible route in advance, the person would generally walk in the direction of the destination and only deviate from the path to avoid an obstruction, and make deviations as minor as possible. Two primary problems of pathfinding are (1) to find a path between two nodes in a
graph Graph may refer to: Mathematics *Graph (discrete mathematics), a structure made of vertices and edges **Graph theory, the study of such graphs and their properties *Graph (topology), a topological space resembling a graph in the sense of discret ...
; and (2) the
shortest path problem In graph theory, the shortest path problem is the problem of finding a path between two vertices (or nodes) in a graph such that the sum of the weights of its constituent edges is minimized. The problem of finding the shortest path between t ...
—to find the optimal shortest path. Basic algorithms such as
breadth-first Breadth-first search (BFS) is an algorithm for searching a tree data structure for a node that satisfies a given property. It starts at the tree root and explores all nodes at the present depth prior to moving on to the nodes at the next dept ...
and
depth-first Depth-first search (DFS) is an algorithm for traversing or searching tree or graph data structures. The algorithm starts at the root node (selecting some arbitrary node as the root node in the case of a graph) and explores as far as possible al ...
search address the first problem by exhausting all possibilities; starting from the given node, they iterate over all potential paths until they reach the destination node. These algorithms run in O(, V, +, E, ), or linear time, where V is the number of vertices, and E is the number of edges between vertices. The more complicated problem is finding the optimal path. The exhaustive approach in this case is known as the
Bellman–Ford algorithm The Bellman–Ford algorithm is an algorithm that computes shortest paths from a single source vertex (graph theory), vertex to all of the other vertices in a weighted digraph. It is slower than Dijkstra's algorithm for the same problem, but more ...
, which yields a time complexity of O(, V, , E, ), or quadratic time. However, it is not necessary to examine all possible paths to find the optimal one. Algorithms such as A* and
Dijkstra's algorithm Dijkstra's algorithm ( ) is an algorithm for finding the shortest paths between nodes in a weighted graph, which may represent, for example, a road network. It was conceived by computer scientist Edsger W. Dijkstra in 1956 and published three ...
strategically eliminate paths, either through
heuristics A heuristic or heuristic technique (''problem solving'', '' mental shortcut'', ''rule of thumb'') is any approach to problem solving that employs a pragmatic method that is not fully optimized, perfected, or rationalized, but is nevertheless ...
or through dynamic programming. By eliminating impossible paths, these algorithms can achieve time complexities as low as O(, E, \log(, V, )). The above algorithms are among the best general algorithms which operate on a graph without preprocessing. However, in practical travel-routing systems, even better time complexities can be attained by algorithms which can pre-process the graph to attain better performance. One such algorithm is
contraction hierarchies In computer science, the method of contraction hierarchies is a speed-up technique for finding the shortest path in a graph. The most intuitive applications are car-navigation systems: a user wants to drive from A to B using the quickest possible ...
.


Dijkstra's algorithm

A common example of a graph-based pathfinding algorithm is
Dijkstra's algorithm Dijkstra's algorithm ( ) is an algorithm for finding the shortest paths between nodes in a weighted graph, which may represent, for example, a road network. It was conceived by computer scientist Edsger W. Dijkstra in 1956 and published three ...
. This algorithm begins with a start node and an "open set" of candidate nodes. At each step, the node in the open set with the lowest distance from the start is examined. The node is marked "closed", and all nodes adjacent to it are added to the open set if they have not already been examined. This process repeats until a path to the destination has been found. Since the lowest distance nodes are examined first, the first time the destination is found, the path to it will be the shortest path. Dijkstra's algorithm fails if there is a negative
edge Edge or EDGE may refer to: Technology Computing * Edge computing, a network load-balancing system * Edge device, an entry point to a computer network * Adobe Edge, a graphical development application * Microsoft Edge, a web browser developed by ...
weight. In the hypothetical situation where Nodes A, B, and C form a connected undirected graph with edges AB = 3, AC = 4, and BC = −2, the optimal path from A to C costs 1, and the optimal path from A to B costs 2. Dijkstra's Algorithm starting from A will first examine B, as that is the closest. It will assign a cost of 3 to it, and mark it closed, meaning that its cost will never be reevaluated. Therefore, Dijkstra's cannot evaluate negative edge weights. However, since for many practical purposes there will never be a negative edgeweight, Dijkstra's algorithm is largely suitable for the purpose of pathfinding.


A* algorithm

A* is a variant of Dijkstra's algorithm with a wide variety of use cases. A* assigns a weight to each open node equal to the weight of the edge to that node plus the approximate distance between that node and the finish. This approximate distance is found by the
heuristic A heuristic or heuristic technique (''problem solving'', '' mental shortcut'', ''rule of thumb'') is any approach to problem solving that employs a pragmatic method that is not fully optimized, perfected, or rationalized, but is nevertheless ...
, and represents a minimum possible distance between that node and the end. This allows it to eliminate longer paths once an initial path is found. If there is a path of length x between the start and finish, and the minimum distance between a node and the finish is greater than x, that node need not be examined. A* uses this heuristic to improve on the behavior relative to Dijkstra's algorithm. When the heuristic evaluates to zero, A* is equivalent to Dijkstra's algorithm. As the heuristic estimate increases and gets closer to the true distance, A* continues to find optimal paths, but runs faster (by virtue of examining fewer nodes). When the value of the heuristic is exactly the true distance, A* examines the fewest nodes. (However, it is generally impractical to write a heuristic function that always computes the true distance, as the same comparison result can often be reached using simpler calculations – for example, using
Chebyshev distance In mathematics, Chebyshev distance (or Tchebychev distance), maximum metric, or L∞ metric is a metric defined on a real coordinate space where the distance between two points is the greatest of their differences along any coordinate dimensio ...
over
Euclidean distance In mathematics, the Euclidean distance between two points in Euclidean space is the length of the line segment between them. It can be calculated from the Cartesian coordinates of the points using the Pythagorean theorem, and therefore is o ...
in
two-dimensional space A two-dimensional space is a mathematical space with two dimensions, meaning points have two degrees of freedom: their locations can be locally described with two coordinates or they can move in two independent directions. Common two-dimensiona ...
.) As the value of the heuristic increases, A* examines fewer nodes but no longer guarantees an optimal path. In many applications (such as video games) this is acceptable and even desirable, in order to keep the algorithm running quickly.


In video games

Pathfinding has a history of being included in video games with moving objects or NPCs. Chris Crawford in 1982 described how he "expended a great deal of time" trying to solve a problem with pathfinding in ''
Tanktics ''Tanktics: Computer Game of Armored Combat on the Eastern Front'' is a 1976 two-player tank battle computer wargame by Chris Crawford. It was Crawford's first video game. He initially self-published it as ''Wargy I''. It was published by Avalo ...
'', in which computer tanks became trapped on land within U-shaped lakes. "After much wasted effort I discovered a better solution: delete U-shaped lakes from the map", he said.


Hierarchical path finding

The concept of hierarchical pathfinding predates its adoption by the
video game industry The video game industry is the tertiary industry, tertiary and quaternary industry, quaternary sectors of the entertainment industry that specialize in the video game development, development, marketing, distribution (marketing), distribution, ...
and has its roots in classical artificial intelligence research. One of the earliest formal descriptions appears in Sacerdoti's work on ABSTRIPS (Abstraction-Based STRIPS) in 1974, which explored hierarchical search strategies in logic-based planning. Later research, such as Hierarchical A* by Holte et al., further developed the theory of abstraction hierarchies in search problems. In the context of video games, the need for efficient planning on large maps with limited
CPU time CPU time (or process time) is the amount of time that a central processing unit (CPU) was used for processing instructions of a computer program or operating system. CPU time is measured in clock ticks or seconds. Sometimes it is useful to con ...
led to the practical implementation of hierarchical pathfinding algorithms. A notable advancement was the introduction of
Hierarchical Path-Finding A* A hierarchy (from Greek: , from , 'president of sacred rites') is an arrangement of items (objects, names, values, categories, etc.) that are represented as being "above", "below", or "at the same level as" one another. Hierarchy is an important ...
(HPA*) by Botea et al. in 2004. HPA* partitions the map into clusters and precomputes optimal local paths between entrance points of adjacent clusters. At runtime, it plans an abstract path through the cluster graph, then refines that path within each cluster. This significantly reduces the search space and allows for near-optimal planning with much faster performance. Partial-Refinement A* (PRA*), developed by Sturtevant and Buro, takes a similar approach but emphasizes interleaved planning and acting. Instead of refining the entire path immediately, PRA* refines only the first few steps and continues refining the rest as needed during execution. This is especially useful in dynamic environments. Similar techniques include
navigation mesh A navigation mesh, or navmesh, is an abstract data structure used in artificial intelligence applications to aid agents in pathfinding through complicated spaces. This approach has been known since at least the mid-1980s in robotics, where it has ...
es (navmesh), used for geometric planning in games, and multimodal
transportation planning Transportation planning is the process of defining future policies, goals, investments, and spatial planning designs to prepare for future needs to move people and goods to destinations. As practiced today, it is a collaborative process that i ...
, such as in variations of the
travelling salesman problem In the Computational complexity theory, theory of computational complexity, the travelling salesman problem (TSP) asks the following question: "Given a list of cities and the distances between each pair of cities, what is the shortest possible ...
that involve multiple transport types. A hierarchical planner performs pathfinding in two phases: first, between clusters at a high level; then, within individual clusters at a low level. This structure enables guided local search with fewer nodes, resulting in high performance. The main drawback is the implementation complexity of maintaining abstraction layers and refinements.


Example

A
map A map is a symbolic depiction of interrelationships, commonly spatial, between things within a space. A map may be annotated with text and graphics. Like any graphic, a map may be fixed to paper or other durable media, or may be displayed on ...
with a size of 3000×2000 nodes contains 6 million tiles. Planning a path directly on this scale, even with an optimized
algorithm In mathematics and computer science, an algorithm () is a finite sequence of Rigour#Mathematics, mathematically rigorous instructions, typically used to solve a class of specific Computational problem, problems or to perform a computation. Algo ...
, is computationally intensive due to the vast number of graph nodes and possible paths. A hierarchical approach divides the map into 300×200 node clusters, forming a 10×10 grid (100 clusters total). The high-level abstract graph now contains only 100 nodes. A path is planned between these clusters, which is computationally cheap. Once the abstract path is found, each cluster on the path is processed using a regular A* planner to find the exact low-level route within. This two-stage process significantly improves efficiency while maintaining near-optimal path quality.


Algorithms used in pathfinding

*
Dijkstra's algorithm Dijkstra's algorithm ( ) is an algorithm for finding the shortest paths between nodes in a weighted graph, which may represent, for example, a road network. It was conceived by computer scientist Edsger W. Dijkstra in 1956 and published three ...
*
A* search algorithm A* (pronounced "A-star") is a graph traversal and pathfinding algorithm that is used in many fields of computer science due to its completeness, optimality, and optimal efficiency. Given a weighted graph, a source node and a goal node, the algo ...
, a special case of the Dijkstra's algorithm * * D* a family of
incremental heuristic search Incremental heuristic search algorithms combine both incremental and heuristic search to speed up searches of sequences of similar search problems, which is important in domains that are only incompletely known or change dynamically. Incremental s ...
algorithms for problems in which constraints vary over time or are not completely known when the
agent Agent may refer to: Espionage, investigation, and law *, spies or intelligence officers * Law of agency, laws involving a person authorized to act on behalf of another ** Agent of record, a person with a contractual agreement with an insuran ...
first plans its path *
Any-angle path planning Any-angle path planning algorithms are pathfinding algorithms that search for a Euclidean shortest path between two points on a grid map while allowing the turns in the path to have any angle. The result is a path that cuts directly through ope ...
algorithms, a family of algorithms for planning paths that are not restricted to move along the edges in the search graph, designed to be able to take on any angle and thus find shorter and straighter paths


Multi-agent pathfinding

Multi-agent pathfinding is to find the paths for multiple agents from their current locations to their target locations without colliding with each other, while at the same time optimizing a cost function, such as the sum of the path lengths of all agents. It is a generalization of pathfinding. Many multi-agent pathfinding algorithms are generalized from A*, or based on reduction to other well studied problems such as integer linear programming. However, such algorithms are typically incomplete; in other words, not proven to produce a solution within polynomial time. Some parallel approaches, such as
Collaborative Diffusion Collaborative Diffusion is a type of pathfinding algorithm which uses the concept of ''antiobjects'', objects within a computer program that function opposite to what would be conventionally expected. Collaborative Diffusion is typically used in ...
, are based on
embarrassingly parallel In parallel computing, an embarrassingly parallel workload or problem (also called embarrassingly parallelizable, perfectly parallel, delightfully parallel or pleasingly parallel) is one where little or no effort is needed to split the problem into ...
algorithms spreading multi-agent pathfinding into computational grid structures, e.g., cells similar to
cellular automata A cellular automaton (pl. cellular automata, abbrev. CA) is a discrete model of computation studied in automata theory. Cellular automata are also called cellular spaces, tessellation automata, homogeneous structures, cellular structures, tessel ...
. A different category of algorithms sacrifice optimality for performance by either making use of known navigation patterns (such as traffic flow) or the topology of the problem space.


See also

*
Motion planning Motion planning, also path planning (also known as the navigation problem or the piano mover's problem) is a computational problem to find a sequence of valid configurations that moves the object from the source to destination. The term is used ...
*
Any-angle path planning Any-angle path planning algorithms are pathfinding algorithms that search for a Euclidean shortest path between two points on a grid map while allowing the turns in the path to have any angle. The result is a path that cuts directly through ope ...


References


External links

*https://melikpehlivanov.github.io/AlgorithmVisualizer *http://sourceforge.net/projects/argorha
StraightEdge
Open Source Java 2D path finding (using A*) and lighting project. Includes applet demos.
python-pathfinding
Open Source Python 2D path finding (using Dijkstra's Algorithm) and lighting project.
Daedalus Lib
Open Source. Daedalus Lib manages fully dynamic triangulated 2D environment modeling and pathfinding through A* and funnel algorithms. {{authority control Game artificial intelligence Routing algorithms Edsger W. Dijkstra Scoutcraft