CausaloidGraph

Struct CausaloidGraph 

Source
pub struct CausaloidGraph<T: Clone> { /* private fields */ }
Expand description

A specialized graph structure for representing and reasoning about causal relationships.

CausaloidGraph is a wrapper around an ultragraph graph, tailored for holding nodes that implement the Causable trait. This structure allows for modeling complex, non-linear causal systems where the activation of one cause can influence others in a directed, potentially acyclic, manner.

The graph uses an adjacency matrix for its underlying storage, which provides fast edge lookups but can be memory-intensive if the graph is sparse and has a large capacity.

§Type Parameters

  • T: The type of the nodes in the graph. It must implement Causable to allow for causal reasoning, PartialEq for node comparison, Clone to manage graph data, and Display for explanations. A common T is the Causaloid struct.

Implementations§

Source§

impl<T: Clone> CausaloidGraph<T>

Source

pub fn new(id: IdentificationValue) -> Self

Creates a new CausaloidGraph with a default capacity.

This constructor initializes the graph with a default capacity of 500 nodes. It utilizes an adjacency matrix for storage, which is suitable for dense graphs or graphs where the maximum number of nodes is known and not excessively large.

§Returns
Source

pub fn new_with_capacity(id: IdentificationValue, capacity: usize) -> Self

Creates a new CausaloidGraph with a specified capacity.

This constructor allows you to pre-allocate space for a given number of nodes, which can be beneficial for performance if the approximate size of the graph is known beforehand. The underlying storage uses an adjacency matrix.

§Arguments
  • capacity - The maximum number of nodes the graph is expected to hold.

Trait Implementations§

Source§

impl<I, O, PS, C> CausableGraph<Causaloid<I, O, PS, C>> for CausaloidGraph<Causaloid<I, O, PS, C>>
where I: Default + Send + Sync + 'static, O: Default + Debug + Send + Sync + 'static, PS: Default + Clone + Send + Sync + 'static, C: Clone + Send + Sync + 'static, Causaloid<I, O, PS, C>: MonadicCausable<I, O>,

Source§

fn is_frozen(&self) -> bool

Source§

fn freeze(&mut self)

Ensures the graph is in the immutable, performance-optimized Static state. Read more
Source§

fn unfreeze(&mut self)

Ensures the graph is in the mutable, Dynamic state. Read more
Source§

fn get_graph(&self) -> &UltraGraphWeighted<Causaloid<I, O, PS, C>, u64>

Returns a reference to the underlying CausalGraph. Read more
Source§

fn add_root_causaloid( &mut self, value: Causaloid<I, O, PS, C>, ) -> Result<usize, CausalityGraphError>

Adds a special “root” causaloid to the graph. Read more
Source§

fn contains_root_causaloid(&self) -> bool

Checks if a root causaloid has been set in the graph. Read more
Source§

fn get_root_causaloid(&self) -> Option<&Causaloid<I, O, PS, C>>

Retrieves an immutable reference to the root causaloid, if it exists. Read more
Source§

fn get_root_index(&self) -> Option<usize>

Retrieves the index of the root causaloid, if it exists. Read more
Source§

fn get_last_index(&self) -> Result<usize, CausalityGraphError>

Gets the index of the last causaloid added to the graph. Read more
Source§

fn add_causaloid( &mut self, value: Causaloid<I, O, PS, C>, ) -> Result<usize, CausalityGraphError>

Adds a new causaloid (node) to the graph. Read more
Source§

fn contains_causaloid(&self, index: usize) -> bool

Checks if a causaloid exists at a specific index in the graph. Read more
Source§

fn get_causaloid(&self, index: usize) -> Option<&Causaloid<I, O, PS, C>>

Retrieves an immutable reference to a causaloid at a given index. Read more
Source§

fn remove_causaloid( &mut self, index: usize, ) -> Result<(), CausalGraphIndexError>

Removes a causaloid from the graph at the specified index. Read more
Source§

fn add_edge(&mut self, a: usize, b: usize) -> Result<(), CausalGraphIndexError>

Adds a directed edge between two causaloids in the graph. Read more
Source§

fn add_edg_with_weight( &mut self, a: usize, b: usize, weight: u64, ) -> Result<(), CausalGraphIndexError>

Adds a weighted directed edge between two causaloids. Read more
Source§

fn contains_edge(&self, a: usize, b: usize) -> bool

Checks if a directed edge exists from causaloid a to causaloid b. Read more
Source§

fn remove_edge( &mut self, a: usize, b: usize, ) -> Result<(), CausalGraphIndexError>

Removes a directed edge between two causaloids. Read more
Source§

fn size(&self) -> usize

Returns the total number of causaloids (nodes) in the graph. Read more
Source§

fn is_empty(&self) -> bool

Checks if the graph contains no causaloids. Read more
Source§

fn clear(&mut self)

Removes all causaloids and edges from the graph. Read more
Source§

fn number_edges(&self) -> usize

Returns the total number of edges in the graph. Read more
Source§

fn number_nodes(&self) -> usize

Returns the total number of causaloids (nodes) in the graph. Read more
Source§

fn get_shortest_path( &self, start_index: usize, stop_index: usize, ) -> Result<Vec<usize>, CausalityGraphError>

Default implementation for shortest path algorithm. Read more
Source§

impl<T: Clone + Clone> Clone for CausaloidGraph<T>

Source§

fn clone(&self) -> CausaloidGraph<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for CausaloidGraph<CausaloidId>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Identifiable for CausaloidGraph<CausaloidId>

Source§

fn id(&self) -> u64

Source§

impl<V, PS, C> MonadicCausableGraphReasoning<V, PS, C> for CausaloidGraph<Causaloid<V, V, PS, C>>
where V: Default + Clone + Send + Sync + 'static + Debug, PS: Default + Clone + Send + Sync + 'static, C: Clone + Send + Sync + 'static, Causaloid<V, V, PS, C>: MonadicCausable<V, V>,

Source§

fn evaluate_single_cause( &self, index: usize, effect: &PropagatingEffect<V>, ) -> PropagatingEffect<V>

Evaluates a single, specific causaloid within the graph by its index using a monadic approach. Read more
Source§

fn evaluate_subgraph_from_cause( &self, start_index: usize, initial_effect: &PropagatingEffect<V>, ) -> PropagatingEffect<V>

Reasons over a subgraph by traversing all nodes reachable from a given start index, using a monadic approach. Read more
Source§

fn evaluate_shortest_path_between_causes( &self, start_index: usize, stop_index: usize, initial_effect: &PropagatingEffect<V>, ) -> PropagatingEffect<V>

Reasons over the shortest path between a start and stop cause using a monadic approach. Read more

Auto Trait Implementations§

§

impl<T> Freeze for CausaloidGraph<T>

§

impl<T> RefUnwindSafe for CausaloidGraph<T>
where T: RefUnwindSafe,

§

impl<T> Send for CausaloidGraph<T>
where T: Send,

§

impl<T> Sync for CausaloidGraph<T>
where T: Sync,

§

impl<T> Unpin for CausaloidGraph<T>
where T: Unpin,

§

impl<T> UnwindSafe for CausaloidGraph<T>
where T: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.