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;
|
startNode.combinedCost = startNode.estimatedCostToGoal;
|
||||||
BinaryHeapOpenSet openSet = new BinaryHeapOpenSet();
|
BinaryHeapOpenSet openSet = new BinaryHeapOpenSet();
|
||||||
openSet.insert(startNode);
|
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])
|
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];
|
double[] bestHeuristicSoFar = new double[COEFFICIENTS.length];
|
||||||
for (int i = 0; i < bestHeuristicSoFar.length; i++) {
|
for (int i = 0; i < bestHeuristicSoFar.length; i++) {
|
||||||
@ -94,7 +93,6 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
PathNode currentNode = openSet.removeLowest();
|
PathNode currentNode = openSet.removeLowest();
|
||||||
currentNode.isOpen = false;
|
|
||||||
mostRecentConsidered = currentNode;
|
mostRecentConsidered = currentNode;
|
||||||
numNodes++;
|
numNodes++;
|
||||||
if (goal.isInGoal(currentNode.x, currentNode.y, currentNode.z)) {
|
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.previous = currentNode;
|
||||||
neighbor.cost = tentativeCost;
|
neighbor.cost = tentativeCost;
|
||||||
neighbor.combinedCost = tentativeCost + neighbor.estimatedCostToGoal;
|
neighbor.combinedCost = tentativeCost + neighbor.estimatedCostToGoal;
|
||||||
if (neighbor.isOpen) {
|
if (neighbor.isOpen()) {
|
||||||
openSet.update(neighbor);
|
openSet.update(neighbor);
|
||||||
} else {
|
} else {
|
||||||
neighbor.isOpen = true;
|
|
||||||
openSet.insert(neighbor);//dont double count, dont insert into open set if it's already there
|
openSet.insert(neighbor);//dont double count, dont insert into open set if it's already there
|
||||||
}
|
}
|
||||||
for (int i = 0; i < bestSoFar.length; i++) {
|
for (int i = 0; i < bestSoFar.length; i++) {
|
||||||
|
@ -58,12 +58,6 @@ public final class PathNode {
|
|||||||
*/
|
*/
|
||||||
public PathNode previous;
|
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.
|
* 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)) {
|
if (Double.isNaN(estimatedCostToGoal)) {
|
||||||
throw new IllegalStateException(goal + " calculated implausible heuristic");
|
throw new IllegalStateException(goal + " calculated implausible heuristic");
|
||||||
}
|
}
|
||||||
this.isOpen = false;
|
this.heapPosition = -1;
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
this.z = z;
|
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
|
* 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