moving away from linked list, so remove nextOpen from PathNode
This commit is contained in:
parent
cd2b5d001e
commit
d382de2b52
@ -54,7 +54,6 @@ public class AStarPathFinder extends AbstractNodeCostSearch {
|
|||||||
PathNode currentNode = openSet.removeLowest();
|
PathNode currentNode = openSet.removeLowest();
|
||||||
mostRecentConsidered = currentNode;
|
mostRecentConsidered = currentNode;
|
||||||
currentNode.isOpen = false;
|
currentNode.isOpen = false;
|
||||||
currentNode.nextOpen = null;
|
|
||||||
BlockPos currentNodePos = currentNode.pos;
|
BlockPos currentNodePos = currentNode.pos;
|
||||||
numNodes++;
|
numNodes++;
|
||||||
if (System.currentTimeMillis() > lastPrintout + 1000) {//print once a second
|
if (System.currentTimeMillis() > lastPrintout + 1000) {//print once a second
|
||||||
|
@ -5,13 +5,15 @@ package baritone.bot.pathing.calc;
|
|||||||
* It has incredbly fast insert performance, at the cost of O(n) removeLowest.
|
* It has incredbly fast insert performance, at the cost of O(n) removeLowest.
|
||||||
*/
|
*/
|
||||||
public class LinkedListOpenSet implements IOpenSet {
|
public class LinkedListOpenSet implements IOpenSet {
|
||||||
private PathNode first = null;
|
private Node first = null;
|
||||||
|
|
||||||
public boolean isEmpty() {
|
public boolean isEmpty() {
|
||||||
return first == null;
|
return first == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void insert(PathNode node) {
|
public void insert(PathNode pathNode) {
|
||||||
|
Node node = new Node();
|
||||||
|
node.val = pathNode;
|
||||||
node.nextOpen = first;
|
node.nextOpen = first;
|
||||||
first = node;
|
first = node;
|
||||||
}
|
}
|
||||||
@ -20,18 +22,18 @@ public class LinkedListOpenSet implements IOpenSet {
|
|||||||
if (first == null) {
|
if (first == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
PathNode current = first.nextOpen;
|
Node current = first.nextOpen;
|
||||||
if (current == null) {
|
if (current == null) {
|
||||||
PathNode n = first;
|
Node n = first;
|
||||||
first = null;
|
first = null;
|
||||||
return n;
|
return n.val;
|
||||||
}
|
}
|
||||||
PathNode previous = first;
|
Node previous = first;
|
||||||
double bestValue = first.combinedCost;
|
double bestValue = first.val.combinedCost;
|
||||||
PathNode bestNode = first;
|
Node bestNode = first;
|
||||||
PathNode beforeBest = null;
|
Node beforeBest = null;
|
||||||
while (current != null) {
|
while (current != null) {
|
||||||
double comp = current.combinedCost;
|
double comp = current.val.combinedCost;
|
||||||
if (comp < bestValue) {
|
if (comp < bestValue) {
|
||||||
bestValue = comp;
|
bestValue = comp;
|
||||||
bestNode = current;
|
bestNode = current;
|
||||||
@ -42,9 +44,16 @@ public class LinkedListOpenSet implements IOpenSet {
|
|||||||
}
|
}
|
||||||
if (beforeBest == null) {
|
if (beforeBest == null) {
|
||||||
first = first.nextOpen;
|
first = first.nextOpen;
|
||||||
return bestNode;
|
bestNode.nextOpen = null;
|
||||||
|
return bestNode.val;
|
||||||
}
|
}
|
||||||
beforeBest.nextOpen = bestNode.nextOpen;
|
beforeBest.nextOpen = bestNode.nextOpen;
|
||||||
return bestNode;
|
bestNode.nextOpen = null;
|
||||||
|
return bestNode.val;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Node { //wrapper with next
|
||||||
|
Node nextOpen;
|
||||||
|
PathNode val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,14 +30,10 @@ class PathNode {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Is this a member of the open set in A*? (only used during pathfinding)
|
* 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.
|
||||||
*/
|
*/
|
||||||
boolean isOpen;
|
boolean isOpen;
|
||||||
|
|
||||||
/**
|
|
||||||
* In the linked list of open nodes, which one is next? (only used during pathfinding)
|
|
||||||
*/
|
|
||||||
PathNode nextOpen;
|
|
||||||
|
|
||||||
public PathNode(BlockPos pos, Goal goal) {
|
public PathNode(BlockPos pos, Goal goal) {
|
||||||
this.pos = pos;
|
this.pos = pos;
|
||||||
this.previous = null;
|
this.previous = null;
|
||||||
|
Loading…
Reference in New Issue
Block a user