Struct Ai

Source
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,
}
Expand description

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§

Source§

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

Source

pub fn node_size(&self) -> usize

Computes the size of nodes in bytes.

Source

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

Calculates utility with extra terms computed from settings.

Source

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

Updates context by tracing the optimal path.

Source

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

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

Uses by other search algorithms.

Source

pub fn memory_exceeded(&self) -> bool

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

Returns false when analysis is deactivated.

Source

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

Only picks choices that increases utility.

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

Source

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

Performs a full construction of the entire maximum tree.

Auto Trait Implementations§

§

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

§

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§

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.