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>
impl<T, A, C> Ai<T, A, C>
Sourcepub fn utility_with_settings(&self, data: &T, depth: usize, ctx: &C) -> f64
pub fn utility_with_settings(&self, data: &T, depth: usize, ctx: &C) -> f64
Calculates utility with extra terms computed from settings.
Sourcepub fn update<'a>(&mut self, node: &'a Node<T, A>, ctx: &mut C) -> Option<usize>
pub fn update<'a>(&mut self, node: &'a Node<T, A>, ctx: &mut C) -> Option<usize>
Updates context by tracing the optimal path.
Sourcepub fn sub_breadth(&mut self, root: &mut Node<T, A>, depth: usize, ctx: &mut C)where
A: Clone,
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.
Sourcepub fn memory_exceeded(&self) -> bool
pub fn memory_exceeded(&self) -> bool
Returns true
when estimated memory usage is exceeded, false
otherwise.
Returns false
when analysis is deactivated.