pub struct BeliefGraph { /* private fields */ }Expand description
Dependency graph for beliefs (hypotheses)
Edge direction: A -> B means “A depends on B” So B is a “dependee” of A, and A is a “dependent” of B
Implementations§
Source§impl BeliefGraph
impl BeliefGraph
pub fn new() -> Self
Sourcepub fn add_dependency(
&mut self,
hypothesis_id: HypothesisId,
depends_on: HypothesisId,
) -> Result<()>
pub fn add_dependency( &mut self, hypothesis_id: HypothesisId, depends_on: HypothesisId, ) -> Result<()>
Add a dependency edge: hypothesis_id depends on depends_on
Returns error if this would create a cycle
Sourcepub fn remove_dependency(
&mut self,
hypothesis_id: HypothesisId,
depends_on: HypothesisId,
) -> Result<bool>
pub fn remove_dependency( &mut self, hypothesis_id: HypothesisId, depends_on: HypothesisId, ) -> Result<bool>
Remove a dependency edge
Sourcepub fn dependents(
&self,
hypothesis_id: HypothesisId,
) -> Result<IndexSet<HypothesisId>>
pub fn dependents( &self, hypothesis_id: HypothesisId, ) -> Result<IndexSet<HypothesisId>>
Get all hypotheses that depend on the given hypothesis (incoming edges)
If A depends on B, then A is in B’s dependents list
Sourcepub fn dependees(
&self,
hypothesis_id: HypothesisId,
) -> Result<IndexSet<HypothesisId>>
pub fn dependees( &self, hypothesis_id: HypothesisId, ) -> Result<IndexSet<HypothesisId>>
Get all hypotheses that the given hypothesis depends on (outgoing edges)
If A depends on B, then B is in A’s dependees list
Sourcepub fn dependency_chain(
&self,
hypothesis_id: HypothesisId,
) -> Result<IndexSet<HypothesisId>>
pub fn dependency_chain( &self, hypothesis_id: HypothesisId, ) -> Result<IndexSet<HypothesisId>>
Get full dependency chain (transitive closure) for a hypothesis
Returns all hypotheses that this hypothesis transitively depends on
Sourcepub fn reverse_dependency_chain(
&self,
hypothesis_id: HypothesisId,
) -> Result<IndexSet<HypothesisId>>
pub fn reverse_dependency_chain( &self, hypothesis_id: HypothesisId, ) -> Result<IndexSet<HypothesisId>>
Get all hypotheses that transitively depend on this hypothesis (reverse chain)
Sourcepub fn detect_cycles(&self) -> Vec<Vec<HypothesisId>>
pub fn detect_cycles(&self) -> Vec<Vec<HypothesisId>>
Detect all cycles in the belief dependency graph
Sourcepub fn would_create_cycle(
&self,
hypothesis_id: HypothesisId,
depends_on: HypothesisId,
) -> bool
pub fn would_create_cycle( &self, hypothesis_id: HypothesisId, depends_on: HypothesisId, ) -> bool
Check if adding an edge would create a cycle
Returns true if adding the edge WOULD create a cycle (cycle detected). Returns false if the edge is safe to add (no cycle).
Sourcepub fn nodes(&self) -> IndexSet<HypothesisId>
pub fn nodes(&self) -> IndexSet<HypothesisId>
Get all nodes in the graph
Sourcepub fn remove_hypothesis(&mut self, hypothesis_id: HypothesisId) -> Result<bool>
pub fn remove_hypothesis(&mut self, hypothesis_id: HypothesisId) -> Result<bool>
Remove a hypothesis and all its edges from the graph
Sourcepub fn all_edges(&self) -> Vec<(HypothesisId, HypothesisId)>
pub fn all_edges(&self) -> Vec<(HypothesisId, HypothesisId)>
Returns all dependency edges as (dependent, dependee) pairs
If A depends on B, returns (A, B)
Trait Implementations§
Auto Trait Implementations§
impl Freeze for BeliefGraph
impl RefUnwindSafe for BeliefGraph
impl Send for BeliefGraph
impl Sync for BeliefGraph
impl Unpin for BeliefGraph
impl UnsafeUnpin for BeliefGraph
impl UnwindSafe for BeliefGraph
Blanket Implementations§
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> 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