Struct DecisionGraph

Source
pub struct DecisionGraph { /* private fields */ }
Expand description

An immutable, bounded graph in authored priority order. Multi-state cycles are allowed: each update follows at most one edge.

Implementations§

Source§

impl DecisionGraph

Source

pub fn new( states: u16, initial: u16, edges: &[DecisionEdge], ) -> Result<DecisionGraph, AiError>

Construct a graph using the existing coarse error category. Use Self::new_checked for an actionable configuration diagnostic.

Source

pub fn validate( states: u16, initial: u16, edges: &[DecisionEdge], ) -> Result<(), DecisionGraphError>

Validate without allocating or building the graph.

Checks state count, initial state, then edge count. Edges are checked in slice order: destination, source, explicit self-transition, conflicting sensor masks, then delay. Only the first error is returned. Cycles, duplicate edges, unreachable states and priority-shadowed edges are allowed; this checks configuration validity, not behavioral reachability.

use ferravex_play::ai::{DecisionEdge, DecisionGraph, DecisionGraphError};
let edge = DecisionEdge {
    from: Some(0), to: 1, all: 4, none: 4, after: 0.,
};
let error = DecisionGraph::validate(2, 0, &[edge]).unwrap_err();
assert_eq!(error, DecisionGraphError::ConflictingGuards { edge: 0, flags: 4 });
assert!(error.to_string().contains("edge 0"));
Source

pub fn new_checked( states: u16, initial: u16, edges: &[DecisionEdge], ) -> Result<DecisionGraph, DecisionGraphError>

Construct a graph with the diagnostics from Self::validate. Copies at most MAX_DECISION_EDGES edges, only after validation passes.

use ferravex_play::ai::{DecisionEdge, DecisionGraph, DecisionGraphError};
let graph = DecisionGraph::new_checked(2, 0, &[
    DecisionEdge { from: Some(0), to: 1, all: 1, none: 0, after: 0.5 },
    DecisionEdge { from: Some(1), to: 0, all: 0, none: 1, after: 0. },
])?; // Cycles are valid.
assert_eq!(graph.initial().state(), 0);
assert_eq!(graph.edges()[1].to, 0);
Source

pub fn edges(&self) -> &[DecisionEdge]

Borrow the validated edges in priority order without allocating. Indices in diagnostics and explanations refer to this slice; see Self::new_checked for an example.

Source

pub fn initial(&self) -> DecisionState

Trait Implementations§

Source§

impl Debug for DecisionGraph

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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.