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
impl DecisionGraph
Sourcepub fn new(
states: u16,
initial: u16,
edges: &[DecisionEdge],
) -> Result<DecisionGraph, AiError>
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.
Sourcepub fn validate(
states: u16,
initial: u16,
edges: &[DecisionEdge],
) -> Result<(), DecisionGraphError>
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"));Sourcepub fn new_checked(
states: u16,
initial: u16,
edges: &[DecisionEdge],
) -> Result<DecisionGraph, DecisionGraphError>
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);Sourcepub fn edges(&self) -> &[DecisionEdge]
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.