2018-08-08 03:16:53 +00:00
|
|
|
/*
|
|
|
|
* This file is part of Baritone.
|
|
|
|
*
|
|
|
|
* Baritone is free software: you can redistribute it and/or modify
|
2018-09-17 22:11:40 +00:00
|
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
2018-08-08 03:16:53 +00:00
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
2018-08-08 04:15:22 +00:00
|
|
|
* Baritone is distributed in the hope that it will be useful,
|
2018-08-08 03:16:53 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2018-09-17 22:11:40 +00:00
|
|
|
* GNU Lesser General Public License for more details.
|
2018-08-08 03:16:53 +00:00
|
|
|
*
|
2018-09-17 22:11:40 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
2018-08-08 03:16:53 +00:00
|
|
|
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2018-08-22 20:15:56 +00:00
|
|
|
package baritone.pathing.calc.openset;
|
2018-08-03 20:31:33 +00:00
|
|
|
|
2018-08-22 20:15:56 +00:00
|
|
|
import baritone.pathing.calc.PathNode;
|
2018-08-03 13:55:17 +00:00
|
|
|
|
|
|
|
/**
|
2018-08-03 15:45:11 +00:00
|
|
|
* A linked list implementation of an open set. This is the original implementation from MineBot.
|
2018-08-06 01:17:04 +00:00
|
|
|
* It has incredibly fast insert performance, at the cost of O(n) removeLowest.
|
2018-08-29 22:35:41 +00:00
|
|
|
* It sucks. BinaryHeapOpenSet results in more than 10x more nodes considered in 4 seconds.
|
2018-08-06 01:17:04 +00:00
|
|
|
*
|
|
|
|
* @author leijurv
|
2018-08-03 13:55:17 +00:00
|
|
|
*/
|
2018-08-29 22:35:41 +00:00
|
|
|
class LinkedListOpenSet implements IOpenSet {
|
2018-08-03 16:50:09 +00:00
|
|
|
private Node first = null;
|
2018-08-03 13:55:17 +00:00
|
|
|
|
2018-08-05 15:30:50 +00:00
|
|
|
@Override
|
2018-08-03 13:55:17 +00:00
|
|
|
public boolean isEmpty() {
|
|
|
|
return first == null;
|
|
|
|
}
|
|
|
|
|
2018-08-05 15:30:50 +00:00
|
|
|
@Override
|
2018-08-03 16:50:09 +00:00
|
|
|
public void insert(PathNode pathNode) {
|
|
|
|
Node node = new Node();
|
|
|
|
node.val = pathNode;
|
2018-08-03 13:55:17 +00:00
|
|
|
node.nextOpen = first;
|
|
|
|
first = node;
|
|
|
|
}
|
|
|
|
|
2018-08-05 15:30:50 +00:00
|
|
|
@Override
|
|
|
|
public void update(PathNode node) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-08-03 13:55:17 +00:00
|
|
|
public PathNode removeLowest() {
|
|
|
|
if (first == null) {
|
|
|
|
return null;
|
|
|
|
}
|
2018-08-03 16:50:09 +00:00
|
|
|
Node current = first.nextOpen;
|
2018-08-03 13:55:17 +00:00
|
|
|
if (current == null) {
|
2018-08-03 16:50:09 +00:00
|
|
|
Node n = first;
|
2018-08-03 13:55:17 +00:00
|
|
|
first = null;
|
2018-08-03 16:50:09 +00:00
|
|
|
return n.val;
|
2018-08-03 13:55:17 +00:00
|
|
|
}
|
2018-08-03 16:50:09 +00:00
|
|
|
Node previous = first;
|
|
|
|
double bestValue = first.val.combinedCost;
|
|
|
|
Node bestNode = first;
|
|
|
|
Node beforeBest = null;
|
2018-08-03 13:55:17 +00:00
|
|
|
while (current != null) {
|
2018-08-03 16:50:09 +00:00
|
|
|
double comp = current.val.combinedCost;
|
2018-08-03 13:55:17 +00:00
|
|
|
if (comp < bestValue) {
|
|
|
|
bestValue = comp;
|
|
|
|
bestNode = current;
|
|
|
|
beforeBest = previous;
|
|
|
|
}
|
|
|
|
previous = current;
|
|
|
|
current = current.nextOpen;
|
|
|
|
}
|
|
|
|
if (beforeBest == null) {
|
|
|
|
first = first.nextOpen;
|
2018-08-03 16:50:09 +00:00
|
|
|
bestNode.nextOpen = null;
|
|
|
|
return bestNode.val;
|
2018-08-03 13:55:17 +00:00
|
|
|
}
|
|
|
|
beforeBest.nextOpen = bestNode.nextOpen;
|
2018-08-03 16:50:09 +00:00
|
|
|
bestNode.nextOpen = null;
|
|
|
|
return bestNode.val;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static class Node { //wrapper with next
|
2018-09-17 00:58:35 +00:00
|
|
|
private Node nextOpen;
|
|
|
|
private PathNode val;
|
2018-08-03 13:55:17 +00:00
|
|
|
}
|
|
|
|
}
|