Class SearchTreeNode<P extends IGamePosition<P>>
- Type Parameters:
P- some implementation ofIGamePositionwhich corresponds to the game being searched by this tree.
- All Implemented Interfaces:
Serializable
public class SearchTreeNode<P extends IGamePosition<P>>
extends GameTreeNode<SearchTreeNode<P>, P>
implements Serializable
Implementation of
GameTreeNode that stores all nodes directly in memory. This
search tree is editable through search only (by expanding nodes and adjusting their
bounds), so the resulting tree always represents the game given by the IGamePosition
implementation P correctly.- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA class that stores the settings for aSearchTreeNodetree.Nested classes/interfaces inherited from class gametree.GameTreeNode
GameTreeNode.Result<N extends GameTreeNode<N,P>, P extends IGamePosition<P>> -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionSearchTreeNode(SearchTreeNode.Settings settings, SearchTreeNode<P> parent, P position, MetricKeeper... metrics) SearchTreeNode(SearchTreeNode.Settings settings, P position, MetricKeeper... metrics) -
Method Summary
Modifier and TypeMethodDescriptionboolean_adjustBounds(List<SearchTreeNode<P>> children, MetricKeeper... metrics) Method to implement functionality ofGameTreeNode.adjustBounds(List<N>, MetricKeeper...)._children(MetricKeeper... metrics) Method to implement functionality ofGameTreeNode.children(MetricKeeper...).long_depthOfLower(MetricKeeper... metrics) Method to implement functionality ofGameTreeNode.depthOfLower(MetricKeeper...).long_depthOfUpper(MetricKeeper... metrics) Method to implement functionality ofGameTreeNode.depthOfUpper(MetricKeeper...).double_lowerbound(MetricKeeper... metrics) Method to implement functionality ofGameTreeNode.lowerbound(MetricKeeper...).double_upperbound(MetricKeeper... metrics) Method to implement functionality ofGameTreeNode.upperbound(MetricKeeper...).booleanvoidattachMetrics(MetricKeeper... metrics) protected SearchTreeNode<P> createChild(SearchTreeNode<P> parent, P position) voidDisables pruning of irrelevant children nodes in the entire tree.voidDisables pruning of game positionsGameTreeNode.position()values for nodes after they have been expanded and evaluated - which is enabled by callingenablePositionPruning(long)on any node of the tree.voidenableIncorrectBoundsProtection(boolean set) If set totrue, enables incorrect-bounds protection for the pruning of irrelevant children nodes in the entire tree.voidenableIrrelevancePruning(long minimum_depth_to_prune) Enables pruning of irrelevant children nodes in the entire tree.voidenablePositionPruning(long minimum_depth_to_prune) Enables pruning of game positionsGameTreeNode.position()values for nodes after they have been expanded and evaluated.booleanevaluate(MetricKeeper... metrics) Evaluates this node if the tree has not been frozen in thesettings.voidfreeze()setTreeFrozen(boolean)withfrozen = true.static <P extends IGamePosition<P>>
SearchTreeNode<P> getTree(P start_position) static <P extends IGamePosition<P>>
SearchTreeNode<P> getTree(P start_position, boolean prune_positions, boolean prune_irrelevance) static <P extends IGamePosition<P>>
SearchTreeNode<P> getTree(P start_position, boolean prune_positions, long minimum_depth_to_prune_positions, boolean prune_irrelevance, long minimum_depth_to_prune_irrelevance) static <P extends IGamePosition<P>>
SearchTreeNode<P> getTree(P start_position, boolean prune_positions, long minimum_depth_to_prune_positions, boolean prune_irrelevance, long minimum_depth_to_prune_irrelevance, boolean incorrect_bounds_protection_for_irrelevance_pruning) static <P extends IGamePosition<P>>
SearchTreeNode<P> getTree(P start_position, long minimum_depth_to_prune_positions, long minimum_depth_to_prune_irrelevance) booleanbooleanbooleanisPruned()booleanThis isIGamePosition.maximising()from theGameTreeNode.position()of this node.booleanvoidPrunes theGameTreeNode.position()value of this node if enabled in thesettings.voidremoveChildren(boolean markAsPruned) voidsetAllowModifications(boolean set) booleansetBounds(double lowerbound, double upperbound) voidsetChildren(Collection<SearchTreeNode<P>> newChildren) settings()voidsetTreeFrozen(boolean frozen) Freezes or un-freezes theSearchTreeNodetree this node is a part of.toString()voidunfreeze()setTreeFrozen(boolean)withfrozen = false.Methods inherited from class gametree.GameTreeNode
adjustBounds, adjustBounds, adjustBounds, adjustBounds, CDF, children, clearPosition, combineMetricList, countSavedSubTree, depth, depthOfLower, depthOfUpper, findBest2, fromFile, getAllLeafnodes, getAttachedMetrics, getComparator, getSavedLeafnodes, hasAttachedMetrics, isRelevant, isRoot, leastPessimistic2, lowerbound, mostOptimistic2, parent, PMF, position, printTree, printTree, printTree, remainingSolveEffort, separation, separation, setParent, survivalFunction, toFile, updateMetrics, updateMetricsParental, updateTree, upperbound
-
Field Details
-
settings
-
-
Constructor Details
-
SearchTreeNode
public SearchTreeNode(SearchTreeNode.Settings settings, SearchTreeNode<P> parent, P position, MetricKeeper... metrics) -
SearchTreeNode
-
-
Method Details
-
settings
-
getTree
public static <P extends IGamePosition<P>> SearchTreeNode<P> getTree(P start_position, boolean prune_positions, long minimum_depth_to_prune_positions, boolean prune_irrelevance, long minimum_depth_to_prune_irrelevance, boolean incorrect_bounds_protection_for_irrelevance_pruning) -
getTree
public static <P extends IGamePosition<P>> SearchTreeNode<P> getTree(P start_position, boolean prune_positions, long minimum_depth_to_prune_positions, boolean prune_irrelevance, long minimum_depth_to_prune_irrelevance) -
getTree
public static <P extends IGamePosition<P>> SearchTreeNode<P> getTree(P start_position, long minimum_depth_to_prune_positions, long minimum_depth_to_prune_irrelevance) -
getTree
public static <P extends IGamePosition<P>> SearchTreeNode<P> getTree(P start_position, boolean prune_positions, boolean prune_irrelevance) -
getTree
-
setTreeFrozen
public void setTreeFrozen(boolean frozen) Freezes or un-freezes theSearchTreeNodetree this node is a part of. Frozen trees do not allow any node expansions, evaluations, or modifications to take place. This is useful for displaying the tree without modifying it.- Parameters:
frozen-trueto prevent new node expansions or evaluations. Orfalseto enable new node expansions and evaluations. This setting defaults totruefor all new trees.
-
freeze
public void freeze()setTreeFrozen(boolean)withfrozen = true. Freezes the tree this node is a part of - disabling any modifications untilunfreeze()orsetTreeFrozen(boolean)are called. -
unfreeze
public void unfreeze()setTreeFrozen(boolean)withfrozen = false. Unfreezes the tree this node is a part of - enabling all modifications untilfreeze()orsetTreeFrozen(boolean)are called. -
setAllowModifications
public void setAllowModifications(boolean set) -
allowModifications
public boolean allowModifications() -
enablePositionPruning
public void enablePositionPruning(long minimum_depth_to_prune) Enables pruning of game positionsGameTreeNode.position()values for nodes after they have been expanded and evaluated. This does not retroactively remove game positions, but only enables it from this moment on. A position that has been pruned can not be recovered. This only affects the functionality ofGameTreeNode.position(), which will returnnullwhen a node is pruned, the tree still functions normally in every other aspect. This reduces the memory usage of future expansions of the tree by not keeping all game positions in memory.This can be disabled again by calling
disablePositionPruning()on any node of the same tree.- Parameters:
minimum_depth_to_prune- minimum depth from the root node (wheredepth = 0). This refers to the root of the entire tree this node is in.
-
disablePositionPruning
public void disablePositionPruning()Disables pruning of game positionsGameTreeNode.position()values for nodes after they have been expanded and evaluated - which is enabled by callingenablePositionPruning(long)on any node of the tree. Does not retroactively modify the tree in any way. -
enableIrrelevancePruning
public void enableIrrelevancePruning(long minimum_depth_to_prune) Enables pruning of irrelevant children nodes in the entire tree. No nodes will be retroactively pruned. Can be disabled by callingdisableIrrelevancePruning().- Parameters:
minimum_depth_to_prune- the minimum depth at which nodes will be pruned. To preserve node structure at the children of the root, set this value to2or higher.
-
disableIrrelevancePruning
public void disableIrrelevancePruning()Disables pruning of irrelevant children nodes in the entire tree. Does not retroactively modify the tree in any way. Nodes already pruned can not be restored. Can be re-enabled by callingenableIrrelevancePruning(long). -
enableIncorrectBoundsProtection
public void enableIncorrectBoundsProtection(boolean set) If set totrue, enables incorrect-bounds protection for the pruning of irrelevant children nodes in the entire tree. This ensures that nodes pruned byenableIrrelevancePruning(long)are still kept in memory, but only their children are removed. This ensures the node can still be revisited if it becomes relevant again later (due to the evaluation function having incorrect bounds). It is important to note that this may result in anullerror ifenablePositionPruning(long)is enabled. Can be disabled by calling setting tofalse. Defaults tofalse.This does not retroactively modify the tree in any way.
- Parameters:
set- the value to set to
-
_children
Description copied from class:GameTreeNodeMethod to implement functionality ofGameTreeNode.children(MetricKeeper...).- Specified by:
_childrenin classGameTreeNode<SearchTreeNode<P extends IGamePosition<P>>, P extends IGamePosition<P>>
-
createChild
-
savedChildren
- Specified by:
savedChildrenin classGameTreeNode<SearchTreeNode<P extends IGamePosition<P>>, P extends IGamePosition<P>>- Returns:
- An Optional containing all children nodes saved in the memory of this
GameTreeNodeor an empty Optional if none are saved in memory. An Optional containing an empty List signifies a terminal node with no children.
-
prunePosition
public void prunePosition()Prunes theGameTreeNode.position()value of this node if enabled in thesettings. Only prunes nodes at a minimum depth ofSearchTreeNode.Settings.position_pruning_depththat have already been expanded and evaluated. -
evaluate
Evaluates this node if the tree has not been frozen in thesettings. Does nothing if the node has already been evaluated.- Parameters:
metrics- An array of metric keepers to keep track of the evaluations made through this method- Returns:
trueif the node has been evaluated.falseif the node is not yet evaluated after this method call (only when the tree is frozen and node not yet evaluated).
-
setBounds
public boolean setBounds(double lowerbound, double upperbound) -
removeChildren
public void removeChildren(boolean markAsPruned) -
setChildren
-
isEvaluated
public boolean isEvaluated() -
_upperbound
Description copied from class:GameTreeNodeMethod to implement functionality ofGameTreeNode.upperbound(MetricKeeper...).- Specified by:
_upperboundin classGameTreeNode<SearchTreeNode<P extends IGamePosition<P>>, P extends IGamePosition<P>>
-
_lowerbound
Description copied from class:GameTreeNodeMethod to implement functionality ofGameTreeNode.lowerbound(MetricKeeper...).- Specified by:
_lowerboundin classGameTreeNode<SearchTreeNode<P extends IGamePosition<P>>, P extends IGamePosition<P>>
-
hasSavedBounds
public boolean hasSavedBounds()- Specified by:
hasSavedBoundsin classGameTreeNode<SearchTreeNode<P extends IGamePosition<P>>, P extends IGamePosition<P>>
-
maximising
public boolean maximising()Description copied from class:GameTreeNodeThis isIGamePosition.maximising()from theGameTreeNode.position()of this node.- Specified by:
maximisingin classGameTreeNode<SearchTreeNode<P extends IGamePosition<P>>, P extends IGamePosition<P>>- Returns:
trueif the current player-to-move is maximising the score, orfalseif it is minimising the score.
-
_adjustBounds
Description copied from class:GameTreeNodeMethod to implement functionality ofGameTreeNode.adjustBounds(List<N>, MetricKeeper...).- Specified by:
_adjustBoundsin classGameTreeNode<SearchTreeNode<P extends IGamePosition<P>>, P extends IGamePosition<P>>
-
pruneIrrelevantChildren
-
isPruned
public boolean isPruned() -
_depthOfUpper
Description copied from class:GameTreeNodeMethod to implement functionality ofGameTreeNode.depthOfUpper(MetricKeeper...).- Specified by:
_depthOfUpperin classGameTreeNode<SearchTreeNode<P extends IGamePosition<P>>, P extends IGamePosition<P>>
-
_depthOfLower
Description copied from class:GameTreeNodeMethod to implement functionality ofGameTreeNode.depthOfLower(MetricKeeper...).- Specified by:
_depthOfLowerin classGameTreeNode<SearchTreeNode<P extends IGamePosition<P>>, P extends IGamePosition<P>>
-
attachMetrics
- Overrides:
attachMetricsin classGameTreeNode<SearchTreeNode<P extends IGamePosition<P>>, P extends IGamePosition<P>>
-
toString
-