pub struct Node<T, A> {
pub max: f64,
pub data: T,
pub children: Vec<(A, Node<T, A>)>,
}
Expand description
Stores action node (represented as a maximum tree).
Each node stores a maximum utility of itself or any children.
A terminal node has higher utility than any other children.
Fields§
§max: f64
Stores maximum utility of itself or any children.
data: T
Stores node data.
children: Vec<(A, Node<T, A>)>
Stores child nodes.
Each child has an associated action.
The associated action identifies the node.
This means the action should be unique among the children.
This invariant is enforced by trusted search algorithms.
Use check_unique_actions
when the input is not trusted.
Implementations§
Source§impl<T, A> Node<T, A>
impl<T, A> Node<T, A>
Sourcepub fn root(data: T) -> Node<T, A>
pub fn root(data: T) -> Node<T, A>
Creates a new root.
This sets the utility to NaN
(not a number).
There are no children, which must be added through search.
Sourcepub fn check_unique_actions(&self) -> bool
pub fn check_unique_actions(&self) -> bool
Returns true
if all actions among children are unique.
This algorithm does not provide any proof of the collision among children, since this use case is uncommon (the invariant is enforced by search algorithms).
Sourcepub fn terminal(&self) -> bool
pub fn terminal(&self) -> bool
Returns true
if the node is terminal.
A terminal node has no children with equal or greater utility. This means that without paying attention to terminal semantics, an unsafe AI design can lead to a “stranded” situation. For more information, see the section “Terminal semantics” at this crate’s top level documentation.
Sourcepub fn optimal(&self) -> Option<usize>
pub fn optimal(&self) -> Option<usize>
Returns the optimal course of action, if any.
Returns None
if no children has higher utility.
This means the node is terminal.
Sourcepub fn optimal_path(&self) -> Vec<usize>
pub fn optimal_path(&self) -> Vec<usize>
Returns optimal path from root.