N - Type of nodepublic class IndexedAStarPathFinder<N> extends java.lang.Object implements PathFinder<N>
PathFinder that can perform both interruptible and non-interruptible pathfinding.
This implementation is a common variation of the A* algorithm that is faster than the general A*.
In the general A* implementation, data are held for each node in the open or closed lists, and these data are held as a NodeRecord instance. Records are created when a node is first considered and then moved between the open and closed lists, as required. There is a key step in the algorithm where the lists are searched for a node record corresponding to a particular node. This operation is something time-consuming.
The indexed A* algorithm improves execution speed by using an array of all the node records for every node in the graph. Nodes
must be numbered using sequential integers (see IndexedGraph.getIndex(Object)), so we don't need to search for a node in the
two lists at all. We can simply use the node index to look up its record in the array (creating it if it is missing). This
means that the close list is no longer needed. To know whether a node is open or closed, we use the category of the node record. This makes the search step very fast indeed (in fact, there is no search, and we can go straight
to the information we need). Unfortunately, we can't get rid of the open list because we still need to be able to retrieve the
element with the lowest cost. However, we use a BinaryHeap for the open list in order to keep performance as high as
possible.
| Modifier and Type | Class and Description |
|---|---|
static class |
IndexedAStarPathFinder.Metrics
A class used by
IndexedAStarPathFinder to collect search metrics. |
| Modifier and Type | Field and Description |
|---|---|
IndexedAStarPathFinder.Metrics |
metrics |
| Constructor and Description |
|---|
IndexedAStarPathFinder(IndexedGraph<N> graph) |
IndexedAStarPathFinder(IndexedGraph<N> graph,
boolean calculateMetrics) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
addToOpenList(com.badlogic.gdx.ai.pfa.indexed.IndexedAStarPathFinder.NodeRecord<N> nodeRecord,
float estimatedTotalCost) |
protected void |
generateConnectionPath(N startNode,
GraphPath<Connection<N>> outPath) |
protected void |
generateNodePath(N startNode,
GraphPath<N> outPath) |
protected com.badlogic.gdx.ai.pfa.indexed.IndexedAStarPathFinder.NodeRecord<N> |
getNodeRecord(N node) |
protected void |
initSearch(N startNode,
N endNode,
Heuristic<N> heuristic) |
protected boolean |
search(N startNode,
N endNode,
Heuristic<N> heuristic) |
boolean |
search(PathFinderRequest<N> request,
long timeToRun)
Performs an interruptible search, trying to find a path made up of nodes from the start node to the goal node attempting to
honor costs provided by the graph.
|
boolean |
searchConnectionPath(N startNode,
N endNode,
Heuristic<N> heuristic,
GraphPath<Connection<N>> outPath)
Performs a non-interruptible search, trying to find a path made up of connections from the start node to the goal node
attempting to honor costs provided by the graph.
|
boolean |
searchNodePath(N startNode,
N endNode,
Heuristic<N> heuristic,
GraphPath<N> outPath)
Performs a non-interruptible search, trying to find a path made up of nodes from the start node to the goal node attempting
to honor costs provided by the graph.
|
protected void |
visitChildren(N endNode,
Heuristic<N> heuristic) |
public IndexedAStarPathFinder.Metrics metrics
public IndexedAStarPathFinder(IndexedGraph<N> graph)
public IndexedAStarPathFinder(IndexedGraph<N> graph, boolean calculateMetrics)
public boolean searchConnectionPath(N startNode, N endNode, Heuristic<N> heuristic, GraphPath<Connection<N>> outPath)
PathFindersearchConnectionPath in interface PathFinder<N>startNode - the start nodeendNode - the end nodeheuristic - the heuristic functionoutPath - the output path that will only be filled if a path is found, otherwise it won't get touched.true if a path was found; false otherwise.public boolean searchNodePath(N startNode, N endNode, Heuristic<N> heuristic, GraphPath<N> outPath)
PathFindersearchNodePath in interface PathFinder<N>startNode - the start nodeendNode - the end nodeheuristic - the heuristic functionoutPath - the output path that will only be filled if a path is found, otherwise it won't get touched.true if a path was found; false otherwise.public boolean search(PathFinderRequest<N> request, long timeToRun)
PathFindersearch in interface PathFinder<N>request - the pathfinding requesttimeToRun - the time in nanoseconds that can be used to advance the searchtrue if the search has finished; false otherwise.protected void generateConnectionPath(N startNode, GraphPath<Connection<N>> outPath)
protected void addToOpenList(com.badlogic.gdx.ai.pfa.indexed.IndexedAStarPathFinder.NodeRecord<N> nodeRecord, float estimatedTotalCost)