[−][src]Trait recon_mcts::SearchTree
An interface to reduce the number of bounds required to use a Tree
generically (i.e. the SearchTree
trait is used to avoid having to list the bounds used to
implement
SearchTree
for Tree
).
In the descriptions below the terms Tree
and SearchTree
maybe be used interchangeably.
Examples
use recon_mcts::prelude::*; fn use_tree_generically<T, GD, M>(t: &T) -> Status<<GD as GameDynamics>::Action> where T: SearchTree<GD = GD, Memory = M>, GD: ?Sized + GameDynamics, M: ?Sized, { while let Some(_) = t.step() { // ... } t.apply_best_action() } fn use_tree_generically_more<T, GD, M>(t: &T) where T: SearchTree<GD = GD, Memory = M>, GD: ?Sized + GameDynamics, M: ?Sized, <GD as GameDynamics>::Player: Clone, <GD as GameDynamics>::Score: Clone, { use_tree_generically(t); let info = t.get_root_info(); let moves = t.get_next_move_info(); // ... } fn use_tree_generically_more_other<T, GD, M>(t: &T) where T: SearchTree<GD = GD, Memory = M>, GD: ?Sized + GameDynamics, M: ?Sized, NodeAlias<GD, M>: OnDrop, { use_tree_generically(t); let children = t.find_children_sorted_with_depth(); let nodes = t.get_registry_info(); // ... }
Associated Types
type GD: ?Sized + GameDynamics
A type that implements GameDynamics
.
type Memory: ?Sized
A state_memory
mixin type used to configure how a Node
's
state is stored.
Required methods
fn step(&self) -> Option<<Self::GD as GameDynamics>::State>
Performs one iteration to expand the SearchTree
. Returns Some(state)
if the
SearchTree
was expanded with a new leaf node and None
otherwise. The state
in
Some(state)
is the GameDynamics::State
of the Node
that was expanded. Note that in a
multi-threaded context it is possible for this method to return None
even though
subsequent calls return Some(_)
. If this method is employed by the user to determine
whether progress has been made, it is the user's responsibility to check that no other
threads expanded the SearchTree
during the execution of this method (SearchTree
expansion results in an update of scores in the SearchTree
, which could lead to the
exploration of a new area of the SearchTree
).
fn best_action(&self) -> Status<<Self::GD as GameDynamics>::Action>
Returns a Status
with the currently anticipated GameDynamics::Action
if available.
fn apply_action(&self, a: &<Self::GD as GameDynamics>::Action)
Move the root based on the selected action
fn apply_best_action(&self) -> Status<<Self::GD as GameDynamics>::Action>
Check for the best action and then apply it to move the root
fn get_root_info(
&self
) -> NodeInfo<<Self::GD as GameDynamics>::State, <Self::GD as GameDynamics>::Player, <Self::GD as GameDynamics>::Score> where
<Self::GD as GameDynamics>::Player: Clone,
<Self::GD as GameDynamics>::Score: Clone,
&self
) -> NodeInfo<<Self::GD as GameDynamics>::State, <Self::GD as GameDynamics>::Player, <Self::GD as GameDynamics>::Score> where
<Self::GD as GameDynamics>::Player: Clone,
<Self::GD as GameDynamics>::Score: Clone,
Returns a NodeInfo
for the SearchTree
's root.
fn get_next_move_info(
&self
) -> Option<Vec<(<Self::GD as GameDynamics>::Action, NodeInfo<<Self::GD as GameDynamics>::State, <Self::GD as GameDynamics>::Player, <Self::GD as GameDynamics>::Score>)>> where
<Self::GD as GameDynamics>::Player: Clone,
<Self::GD as GameDynamics>::Score: Clone,
&self
) -> Option<Vec<(<Self::GD as GameDynamics>::Action, NodeInfo<<Self::GD as GameDynamics>::State, <Self::GD as GameDynamics>::Player, <Self::GD as GameDynamics>::Score>)>> where
<Self::GD as GameDynamics>::Player: Clone,
<Self::GD as GameDynamics>::Score: Clone,
Returns Some(Vec<(GameDynamics::Action, NodeInfo)>)
of all possible
GameDynamics::Action
s available from the SearchTree
's root. Returns a None
if no
actions are available or their existence has not been determined by calling
SearchTree::step
.
fn find_children_sorted_with_depth(
&self
) -> Vec<(ArcWrap<NodeAlias<Self::GD, Self::Memory>>, usize)> where
NodeAlias<Self::GD, Self::Memory>: OnDrop,
&self
) -> Vec<(ArcWrap<NodeAlias<Self::GD, Self::Memory>>, usize)> where
NodeAlias<Self::GD, Self::Memory>: OnDrop,
Returns a vector of topologically sorted (ArcNode, usize)
pairs where the usize
indicates the distance from the ArcNode
to the leaf that has the maximum reachable depth.
The vector is sorted such that index 0
is a leaf and the last element is the root node.
The vector represents the children, grandchildren, etc. of the root node (as well as the
root itself). Note that usize
is always strictly smaller for a child than its parent.
This is basically a depth first
search.
fn get_registry_nodes(
&self
) -> HashSet<WeakWrap<NodeAlias<Self::GD, Self::Memory>>> where
NodeAlias<Self::GD, Self::Memory>: OnDrop,
&self
) -> HashSet<WeakWrap<NodeAlias<Self::GD, Self::Memory>>> where
NodeAlias<Self::GD, Self::Memory>: OnDrop,
Returns a HashSet
of all Node
s currently in the SearchTree
.
fn get_registry_info(&self) -> &RegistryInfo
Returns summary statistics for the SearchTree
's registry.
fn get_game_dynamics(&self) -> Arc<Self::GD>
Returns a reference to the game dynamics.
Implementors
impl<GD, S, P, A, Q, I, M, II> SearchTree for TreeAlias<GD, M> where
Node<GD, S, P, A, Q, I, M>: StateMemory<State = S>,
GD: GameDynamics<Player = P, State = S, Action = A, Score = Q, ActionIter = II>,
II: IntoIterator<IntoIter = I, Item = (P, A)>,
I: Iterator<Item = (P, A)>,
A: Clone + Hash + Eq,
S: Clone + Hash + PartialEq<S>,
P: Hash + PartialEq<P>,
[src]
Node<GD, S, P, A, Q, I, M>: StateMemory<State = S>,
GD: GameDynamics<Player = P, State = S, Action = A, Score = Q, ActionIter = II>,
II: IntoIterator<IntoIter = I, Item = (P, A)>,
I: Iterator<Item = (P, A)>,
A: Clone + Hash + Eq,
S: Clone + Hash + PartialEq<S>,
P: Hash + PartialEq<P>,
type GD = GD
type Memory = M
fn step(&self) -> Option<<Self::GD as GameDynamics>::State>
[src]
fn best_action(&self) -> Status<<Self::GD as GameDynamics>::Action>
[src]
fn apply_action(&self, a: &<Self::GD as GameDynamics>::Action)
[src]
fn apply_best_action(&self) -> Status<<Self::GD as GameDynamics>::Action>
[src]
fn get_root_info(
&self
) -> NodeInfo<<Self::GD as GameDynamics>::State, <Self::GD as GameDynamics>::Player, <Self::GD as GameDynamics>::Score> where
<Self::GD as GameDynamics>::Player: Clone,
<Self::GD as GameDynamics>::Score: Clone,
[src]
&self
) -> NodeInfo<<Self::GD as GameDynamics>::State, <Self::GD as GameDynamics>::Player, <Self::GD as GameDynamics>::Score> where
<Self::GD as GameDynamics>::Player: Clone,
<Self::GD as GameDynamics>::Score: Clone,
fn get_next_move_info(
&self
) -> Option<Vec<(<Self::GD as GameDynamics>::Action, NodeInfo<<Self::GD as GameDynamics>::State, <Self::GD as GameDynamics>::Player, <Self::GD as GameDynamics>::Score>)>> where
<Self::GD as GameDynamics>::Player: Clone,
<Self::GD as GameDynamics>::Score: Clone,
[src]
&self
) -> Option<Vec<(<Self::GD as GameDynamics>::Action, NodeInfo<<Self::GD as GameDynamics>::State, <Self::GD as GameDynamics>::Player, <Self::GD as GameDynamics>::Score>)>> where
<Self::GD as GameDynamics>::Player: Clone,
<Self::GD as GameDynamics>::Score: Clone,
fn find_children_sorted_with_depth(
&self
) -> Vec<(ArcWrap<NodeAlias<Self::GD, Self::Memory>>, usize)> where
NodeAlias<Self::GD, Self::Memory>: OnDrop,
[src]
&self
) -> Vec<(ArcWrap<NodeAlias<Self::GD, Self::Memory>>, usize)> where
NodeAlias<Self::GD, Self::Memory>: OnDrop,
fn get_registry_nodes(
&self
) -> HashSet<WeakWrap<NodeAlias<Self::GD, Self::Memory>>> where
NodeAlias<Self::GD, Self::Memory>: OnDrop,
[src]
&self
) -> HashSet<WeakWrap<NodeAlias<Self::GD, Self::Memory>>> where
NodeAlias<Self::GD, Self::Memory>: OnDrop,
fn get_registry_info(&self) -> &RegistryInfo
[src]
fn get_game_dynamics(&self) -> Arc<GD>
[src]
fn get_tree(&self) -> &TreeAlias<Self::GD, Self::Memory> where
NodeAlias<Self::GD, Self::Memory>: OnDrop,
[src]
NodeAlias<Self::GD, Self::Memory>: OnDrop,