pub trait CausableGraph<T>where
T: Clone,{
Show 23 methods
// Required methods
fn is_frozen(&self) -> bool;
fn freeze(&mut self);
fn unfreeze(&mut self);
fn get_graph(&self) -> &UltraGraphWeighted<T, u64>;
fn add_root_causaloid(
&mut self,
value: T,
) -> Result<usize, CausalityGraphError>;
fn contains_root_causaloid(&self) -> bool;
fn get_root_causaloid(&self) -> Option<&T>;
fn get_root_index(&self) -> Option<usize>;
fn get_last_index(&self) -> Result<usize, CausalityGraphError>;
fn add_causaloid(&mut self, value: T) -> Result<usize, CausalityGraphError>;
fn contains_causaloid(&self, index: usize) -> bool;
fn get_causaloid(&self, index: usize) -> Option<&T>;
fn remove_causaloid(
&mut self,
index: usize,
) -> Result<(), CausalGraphIndexError>;
fn add_edge(
&mut self,
a: usize,
b: usize,
) -> Result<(), CausalGraphIndexError>;
fn add_edg_with_weight(
&mut self,
a: usize,
b: usize,
weight: u64,
) -> Result<(), CausalGraphIndexError>;
fn contains_edge(&self, a: usize, b: usize) -> bool;
fn remove_edge(
&mut self,
a: usize,
b: usize,
) -> Result<(), CausalGraphIndexError>;
fn size(&self) -> usize;
fn is_empty(&self) -> bool;
fn clear(&mut self);
fn number_edges(&self) -> usize;
fn number_nodes(&self) -> usize;
// Provided method
fn get_shortest_path(
&self,
start_index: usize,
stop_index: usize,
) -> Result<Vec<usize>, CausalityGraphError> { ... }
}Required Methods§
fn is_frozen(&self) -> bool
Sourcefn freeze(&mut self)
fn freeze(&mut self)
Ensures the graph is in the immutable, performance-optimized Static state.
If the graph is already frozen, this operation is a no-op. Otherwise, it
converts the graph from a Dynamic state in-place. This is an O(V + E)
operation if a state change occurs.
Sourcefn unfreeze(&mut self)
fn unfreeze(&mut self)
Ensures the graph is in the mutable, Dynamic state.
If the graph is already dynamic, this operation is a no-op. Otherwise, it
converts the graph from a Static state in-place. This is an O(V + E)
operation if a state change occurs and requires node and edge data to be Clone.
Sourcefn get_graph(&self) -> &UltraGraphWeighted<T, u64>
fn get_graph(&self) -> &UltraGraphWeighted<T, u64>
Returns a reference to the underlying CausalGraph.
This method is primarily used to enable default implementations for
other traits like CausableGraphExplaining and CausableGraphReasoning,
allowing them to operate directly on the graph structure.
Sourcefn add_root_causaloid(&mut self, value: T) -> Result<usize, CausalityGraphError>
fn add_root_causaloid(&mut self, value: T) -> Result<usize, CausalityGraphError>
Adds a special “root” causaloid to the graph.
The root node serves as the starting point for causal reasoning and traversals. There can typically only be one root node in the graph.
§Arguments
value- The causaloid of typeTto be added as the root.
§Returns
The usize index of the newly added root node.
Sourcefn contains_root_causaloid(&self) -> bool
fn contains_root_causaloid(&self) -> bool
Checks if a root causaloid has been set in the graph.
§Returns
trueif a root node exists,falseotherwise.
Sourcefn get_root_causaloid(&self) -> Option<&T>
fn get_root_causaloid(&self) -> Option<&T>
Retrieves an immutable reference to the root causaloid, if it exists.
§Returns
Some(&T)containing a reference to the root causaloid if it’s present.Noneif no root node has been added to the graph.
Sourcefn get_root_index(&self) -> Option<usize>
fn get_root_index(&self) -> Option<usize>
Retrieves the index of the root causaloid, if it exists.
§Returns
Some(usize)containing the index of the root node if it’s present.Noneif no root node has been added to the graph.
Sourcefn get_last_index(&self) -> Result<usize, CausalityGraphError>
fn get_last_index(&self) -> Result<usize, CausalityGraphError>
Gets the index of the last causaloid added to the graph.
This is useful for understanding the current size or for linking to a newly added node.
§Returns
Ok(usize)containing the index of the last node.Err(CausalityGraphError)if the graph is empty and has no nodes.
Sourcefn add_causaloid(&mut self, value: T) -> Result<usize, CausalityGraphError>
fn add_causaloid(&mut self, value: T) -> Result<usize, CausalityGraphError>
Sourcefn contains_causaloid(&self, index: usize) -> bool
fn contains_causaloid(&self, index: usize) -> bool
Sourcefn get_causaloid(&self, index: usize) -> Option<&T>
fn get_causaloid(&self, index: usize) -> Option<&T>
Sourcefn remove_causaloid(
&mut self,
index: usize,
) -> Result<(), CausalGraphIndexError>
fn remove_causaloid( &mut self, index: usize, ) -> Result<(), CausalGraphIndexError>
Removes a causaloid from the graph at the specified index.
Note: Removing a causaloid will also remove all edges connected to it.
§Arguments
index- Theusizeindex of the causaloid to remove.
§Returns
Ok(())if the causaloid was successfully removed.Err(CausalGraphIndexError)if the providedindexis invalid or out of bounds.
Sourcefn add_edge(&mut self, a: usize, b: usize) -> Result<(), CausalGraphIndexError>
fn add_edge(&mut self, a: usize, b: usize) -> Result<(), CausalGraphIndexError>
Adds a directed edge between two causaloids in the graph.
This creates a causal link from the causaloid at index a to the one at index b.
§Arguments
a- Theusizeindex of the source causaloid (the cause).b- Theusizeindex of the target causaloid (the effect).
§Returns
Ok(())if the edge was successfully added.Err(CausalGraphIndexError)if eitheraorbis an invalid index.
Sourcefn add_edg_with_weight(
&mut self,
a: usize,
b: usize,
weight: u64,
) -> Result<(), CausalGraphIndexError>
fn add_edg_with_weight( &mut self, a: usize, b: usize, weight: u64, ) -> Result<(), CausalGraphIndexError>
Adds a weighted directed edge between two causaloids.
The weight can represent the strength, probability, or intensity of the causal relationship.
§Arguments
a- Theusizeindex of the source causaloid.b- Theusizeindex of the target causaloid.weight- Theu64weight of the edge.
§Returns
Ok(())if the weighted edge was successfully added.Err(CausalGraphIndexError)if eitheraorbis an invalid index.
Sourcefn contains_edge(&self, a: usize, b: usize) -> bool
fn contains_edge(&self, a: usize, b: usize) -> bool
Sourcefn remove_edge(
&mut self,
a: usize,
b: usize,
) -> Result<(), CausalGraphIndexError>
fn remove_edge( &mut self, a: usize, b: usize, ) -> Result<(), CausalGraphIndexError>
Removes a directed edge between two causaloids.
If multiple edges exist between a and b, this will remove one of them.
§Arguments
a- Theusizeindex of the source causaloid.b- Theusizeindex of the target causaloid.
§Returns
Ok(())if the edge was successfully removed.Err(CausalGraphIndexError)if the edge does not exist or if either index is invalid.
Sourcefn size(&self) -> usize
fn size(&self) -> usize
Returns the total number of causaloids (nodes) in the graph.
§Returns
A usize representing the total count of nodes in the graph.
Sourcefn is_empty(&self) -> bool
fn is_empty(&self) -> bool
Checks if the graph contains no causaloids.
§Returns
trueif the graph has no nodes.falseif the graph has one or more nodes.
Sourcefn clear(&mut self)
fn clear(&mut self)
Removes all causaloids and edges from the graph.
After calling this method, the graph will be empty.
Sourcefn number_edges(&self) -> usize
fn number_edges(&self) -> usize
Returns the total number of edges in the graph.
§Returns
A usize representing the total count of edges.
Sourcefn number_nodes(&self) -> usize
fn number_nodes(&self) -> usize
Returns the total number of causaloids (nodes) in the graph.
§Returns
A usize representing the total count of nodes.
Provided Methods§
Sourcefn get_shortest_path(
&self,
start_index: usize,
stop_index: usize,
) -> Result<Vec<usize>, CausalityGraphError>
fn get_shortest_path( &self, start_index: usize, stop_index: usize, ) -> Result<Vec<usize>, CausalityGraphError>
Default implementation for shortest path algorithm.
Finds the shortest path between two node indices in the graph.
start_index: The start node index stop_index: The target node index
Returns:
- Ok(
Vec<usize>): The node indices of the shortest path - Err(CausalityGraphError): If no path exists
Checks if start and stop nodes are identical and early returns error. Otherwise calls shortest_path() on the underlying CausalGraph.