pub struct TrajectoryGraph { /* private fields */ }Expand description
Trajectory DAG structure optimized for traversal operations.
A trajectory represents a sequence of experiences (episodes) forming a path through time. The DAG structure captures branching and regeneration points.
Implementations§
Source§impl TrajectoryGraph
impl TrajectoryGraph
Sourcepub fn from_edges(edges: impl IntoIterator<Item = Edge>) -> Self
pub fn from_edges(edges: impl IntoIterator<Item = Edge>) -> Self
Build graph from a list of edges.
§Arguments
edges- Iterator of (parent_id, child_id) pairs
§Example
use rag_plusplus_core::trajectory::{TrajectoryGraph, Edge, EdgeType};
let edges = vec![
Edge { parent: 1, child: 2, edge_type: EdgeType::Continuation },
Edge { parent: 2, child: 3, edge_type: EdgeType::Continuation },
Edge { parent: 2, child: 4, edge_type: EdgeType::Regeneration }, // Branch
];
let graph = TrajectoryGraph::from_edges(edges.iter().copied());
assert_eq!(graph.node_count(), 4);
assert!(graph.is_branch_point(2));Sourcepub fn get_node_mut(&mut self, id: NodeId) -> Option<&mut Episode>
pub fn get_node_mut(&mut self, id: NodeId) -> Option<&mut Episode>
Get a mutable reference to an episode.
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Number of episodes in the graph.
Sourcepub fn is_branch_point(&self, id: NodeId) -> bool
pub fn is_branch_point(&self, id: NodeId) -> bool
Check if an episode is a branch point.
Sourcepub fn find_branch_points(&self) -> Vec<BranchInfo>
pub fn find_branch_points(&self) -> Vec<BranchInfo>
Find all branch points in the graph.
Sourcepub fn traverse<F>(&self, order: TraversalOrder, visitor: F)
pub fn traverse<F>(&self, order: TraversalOrder, visitor: F)
Traverse the graph in specified order, calling visitor for each episode.
§Arguments
order- Traversal ordervisitor- Callback function for each episode
Sourcepub fn find_primary_path(
&self,
policy: PathSelectionPolicy,
) -> Option<PathResult>
pub fn find_primary_path( &self, policy: PathSelectionPolicy, ) -> Option<PathResult>
Find the primary path through the DAG using the specified selection policy.
The primary path is a linear sequence from a root to a leaf that represents the “best” version of the trajectory (e.g., after regenerations).
§Arguments
policy- How to choose at branch points
§Returns
PathResult containing the selected path and branch information.
Sourcepub fn find_all_paths_from(&self, start: NodeId) -> Vec<Vec<NodeId>>
pub fn find_all_paths_from(&self, start: NodeId) -> Vec<Vec<NodeId>>
Find all paths from an episode to all reachable leaves.
Sourcepub fn find_path_to(&self, target: NodeId) -> Option<Vec<NodeId>>
pub fn find_path_to(&self, target: NodeId) -> Option<Vec<NodeId>>
Find the path from root to a specific episode.
Trait Implementations§
Source§impl Clone for TrajectoryGraph
impl Clone for TrajectoryGraph
Source§fn clone(&self) -> TrajectoryGraph
fn clone(&self) -> TrajectoryGraph
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for TrajectoryGraph
impl Debug for TrajectoryGraph
Auto Trait Implementations§
impl Freeze for TrajectoryGraph
impl RefUnwindSafe for TrajectoryGraph
impl Send for TrajectoryGraph
impl Sync for TrajectoryGraph
impl Unpin for TrajectoryGraph
impl UnwindSafe for TrajectoryGraph
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<F, W, T, D> Deserialize<With<T, W>, D> for F
impl<F, W, T, D> Deserialize<With<T, W>, D> for F
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more