epicly fast
This commit is contained in:
parent
0ef3386ebf
commit
d41aa5f9ae
@ -55,7 +55,6 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel
|
||||
startNode.combinedCost = startNode.estimatedCostToGoal;
|
||||
BinaryHeapOpenSet openSet = new BinaryHeapOpenSet();
|
||||
openSet.insert(startNode);
|
||||
startNode.isOpen = true;
|
||||
bestSoFar = new PathNode[COEFFICIENTS.length];//keep track of the best node by the metric of (estimatedCostToGoal + cost / COEFFICIENTS[i])
|
||||
double[] bestHeuristicSoFar = new double[COEFFICIENTS.length];
|
||||
for (int i = 0; i < bestHeuristicSoFar.length; i++) {
|
||||
@ -94,7 +93,6 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel
|
||||
}
|
||||
}
|
||||
PathNode currentNode = openSet.removeLowest();
|
||||
currentNode.isOpen = false;
|
||||
mostRecentConsidered = currentNode;
|
||||
numNodes++;
|
||||
if (goal.isInGoal(currentNode.x, currentNode.y, currentNode.z)) {
|
||||
@ -156,10 +154,9 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel
|
||||
neighbor.previous = currentNode;
|
||||
neighbor.cost = tentativeCost;
|
||||
neighbor.combinedCost = tentativeCost + neighbor.estimatedCostToGoal;
|
||||
if (neighbor.isOpen) {
|
||||
if (neighbor.isOpen()) {
|
||||
openSet.update(neighbor);
|
||||
} else {
|
||||
neighbor.isOpen = true;
|
||||
openSet.insert(neighbor);//dont double count, dont insert into open set if it's already there
|
||||
}
|
||||
for (int i = 0; i < bestSoFar.length; i++) {
|
||||
|
@ -58,12 +58,6 @@ public final class PathNode {
|
||||
*/
|
||||
public PathNode previous;
|
||||
|
||||
/**
|
||||
* Is this a member of the open set in A*? (only used during pathfinding)
|
||||
* Instead of doing a costly member check in the open set, cache membership in each node individually too.
|
||||
*/
|
||||
public boolean isOpen;
|
||||
|
||||
/**
|
||||
* Where is this node in the array flattenization of the binary heap? Needed for decrease-key operations.
|
||||
*/
|
||||
@ -76,12 +70,16 @@ public final class PathNode {
|
||||
if (Double.isNaN(estimatedCostToGoal)) {
|
||||
throw new IllegalStateException(goal + " calculated implausible heuristic");
|
||||
}
|
||||
this.isOpen = false;
|
||||
this.heapPosition = -1;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public boolean isOpen() {
|
||||
return heapPosition != -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: Possibly reimplement hashCode and equals. They are necessary for this class to function but they could be done better
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user