Struct Node

Source
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>

Source

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.

Source

pub fn check_unique_actions(&self) -> bool
where A: Eq + Hash,

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).

Source

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.

Source

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.

Source

pub fn optimal_path(&self) -> Vec<usize>

Returns optimal path from root.

Trait Implementations§

Source§

impl<T: Debug, A: Debug> Debug for Node<T, A>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T, A> Freeze for Node<T, A>
where T: Freeze,

§

impl<T, A> RefUnwindSafe for Node<T, A>

§

impl<T, A> Send for Node<T, A>
where T: Send, A: Send,

§

impl<T, A> Sync for Node<T, A>
where T: Sync, A: Sync,

§

impl<T, A> Unpin for Node<T, A>
where T: Unpin, A: Unpin,

§

impl<T, A> UnwindSafe for Node<T, A>
where T: UnwindSafe, A: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.