Commit ff10fb82 authored by tc360950's avatar tc360950
Browse files

minor fixes

parent 8484a4d5
......@@ -55,12 +55,12 @@ public abstract class Tree {
Solution solution = rollout(path);
backPropagate(leaf, solution);
memoryLimiter.updateRecentlyAccessedNodes(leaf);
if (solution.isEmpty() && leaf.getNodeStatistics().getDepth() > minDepthSubtreeRemoval) {
removeSubtreeWithNoSolutions((leaf));
}
memoryLimiter.updateRecentlyAccessedNodes(leaf);
while (memoryLimiter.shouldPruneTree()) {
removeLeaf(memoryLimiter.whichNodeToPrune());
}
......@@ -78,19 +78,15 @@ public abstract class Tree {
// Shouldn't happen if node limit is not very small.
if (node == root) {
root.setUnexpanded();
return;
}
node.getParent().removeChild(node);
memoryLimiter.removeNodeFromQueue(node);
if (node.getParent() != root && node.getParent().getChildrenSize() == 0) {
if (node.getParent().getChildrenSize() == 0) {
removeLeaf(node.getParent());
}
// There's a corner case in which root can lose its all children.
// If node limit is > ~10000 this should never happen.
if (node.getParent() == root && root.getChildrenSize() == 0) {
root.setUnexpanded();
}
}
}
......@@ -28,7 +28,7 @@ public class MemoryLimiterImpl implements MemoryLimiter {
while (current != null) {
if (current.isExpanded() && current.getParent() != null) { // If current is not leaf or root.
updateRecentlyAccessedNode(current);
accessQueue.pushBack(current);
}
current = current.getParent();
}
......@@ -40,7 +40,7 @@ public class MemoryLimiterImpl implements MemoryLimiter {
NodeImpl newNode = new NodeImpl(value);
newNode.linkToTree(parent);
accessQueue.pushBack(newNode);
return new NodeImpl(value);
return newNode;
}
@Override
......@@ -48,9 +48,4 @@ public class MemoryLimiterImpl implements MemoryLimiter {
count--;
accessQueue.removeNodeFromQueue((NodeImpl) node);
}
// Adds newly created or visited node to queue.
private void updateRecentlyAccessedNode(Node node) {
accessQueue.pushBack(node);
}
}
......@@ -63,9 +63,7 @@ public class MoveProviderImpl implements MoveProvider {
return toExpand;
}
IntStream.range(mctsWrapper.getMinDomainValue(depth), mctsWrapper.getMaxDomainValue(depth) + 1).
forEach(value -> {
Node newNode = memoryLimiter.createNode(toExpand, value);
});
forEach(value -> memoryLimiter.createNode(toExpand, value));
toExpand.setExpanded();
......
......@@ -19,7 +19,7 @@ public class Queue {
}
// Current node is not in queue.
if (this.empty()) { // If queue is empty.
if (this.empty()) {
this.front = this.back = node;
node.getQueueLinker().addToQueue(node,null);
} else {
......@@ -33,15 +33,12 @@ public class Queue {
}
public void removeNodeFromQueue(NodeImpl node) {
NodeImpl previous = node.getQueueLinker().getPrevious();
NodeImpl next = node.getQueueLinker().getNext();
if (front == node) {
this.front = next;
this.front = node.getQueueLinker().getNext();
}
if (back == node) {
this.back = previous;
this.back = node.getQueueLinker().getPrevious();
}
node.getQueueLinker().removeFromQueue();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment