[][src]Struct max_tree::Ai

pub struct Ai<T, A, C> {
    pub utility: fn(_: &T, _: &C) -> f64,
    pub actions: fn(_: &T, _: &C) -> Vec<A>,
    pub execute: fn(_: &T, a: &A, _: &mut C) -> Result<T, ()>,
    pub undo: fn(_: &T, _: &mut C),
    pub settings: AiSettings,
    pub analysis: AiAnalysis,
}

AI setup.

Provides a common setup for different search algorithms. The search algorithm constructs a maximum tree, which can be used to find the optimal course of action.

The T parameter is the type of node data. This is used to store delta changes for undo operations. Also stores data that tracks internal state of the AI agent, when the AI agent is not interacting with the context (pure search). Node data is stored separately from the context, making it easy to analyse after constructing the maximum tree.

The A parameter is the type of action. It describes the choices the AI agent can make in a specific context. An action modifies the context and must be undone when rolling back changes.

The C parameter is the type of context (environment). This stores the data that is necessary to calculate utility. The context is modified by actions when exploring, but these changes are undone when rolling back changes.

Fields

utility: fn(_: &T, _: &C) -> f64

Calculates utility from data and context.

actions: fn(_: &T, _: &C) -> Vec<A>

Returns a list of possible actions.

execute: fn(_: &T, a: &A, _: &mut C) -> Result<T, ()>

Executes an action, returning new node data.

undo: fn(_: &T, _: &mut C)

Undoes change made to context.

The data required to rollback delta changes must be stored in node data.

settings: AiSettings

Stores AI settings.

analysis: AiAnalysis

Stores analysis.

Implementations

impl<T, A, C> Ai<T, A, C>[src]

pub fn node_size(&self) -> usize[src]

Computes the size of nodes in bytes.

pub fn utility_with_settings(&self, data: &T, depth: usize, ctx: &C) -> f64[src]

Calculates utility with extra terms computed from settings.

pub fn update<'a>(&mut self, node: &'a Node<T, A>, ctx: &mut C) -> Option<usize>[src]

Updates context by tracing the optimal path.

pub fn sub_breadth(&mut self, root: &mut Node<T, A>, depth: usize, ctx: &mut C) where
    A: Clone
[src]

A sub-procedure constructing maximum tree of all available actions.

Uses by other search algorithms.

pub fn memory_exceeded(&self) -> bool[src]

Returns true when estimated memory usage is exceeded, false otherwise.

Returns false when analysis is deactivated.

pub fn greedy(&mut self, root: &mut Node<T, A>, depth: usize, ctx: &mut C) where
    A: Clone
[src]

Only picks choices that increases utility.

In order to find global maximum, it requires utility gradient to be convex.

pub fn full(&mut self, root: &mut Node<T, A>, depth: usize, ctx: &mut C) where
    A: Clone
[src]

Performs a full construction of the entire maximum tree.

Auto Trait Implementations

impl<T, A, C> RefUnwindSafe for Ai<T, A, C>

impl<T, A, C> Send for Ai<T, A, C>

impl<T, A, C> Sync for Ai<T, A, C>

impl<T, A, C> Unpin for Ai<T, A, C>

impl<T, A, C> UnwindSafe for Ai<T, A, C>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.