pub struct Hypergraph<N: Node, E: EdgeWeight, Ix: IndexType = u32> { /* private fields */ }
Expand description
A hypergraph structure where hyperedges can connect any number of vertices
A hypergraph is a generalization of a graph where edges (called hyperedges) can connect any number of vertices, not just two. This is useful for modeling complex relationships where multiple entities interact simultaneously.
Implementations§
Source§impl<N: Node, E: EdgeWeight, Ix: IndexType> Hypergraph<N, E, Ix>
impl<N: Node, E: EdgeWeight, Ix: IndexType> Hypergraph<N, E, Ix>
Sourcepub fn add_hyperedge(&mut self, nodes: HashSet<N>, weight: E) -> Result<usize>
pub fn add_hyperedge(&mut self, nodes: HashSet<N>, weight: E) -> Result<usize>
Sourcepub fn add_hyperedge_from_vec(
&mut self,
nodes: Vec<N>,
weight: E,
) -> Result<usize>
pub fn add_hyperedge_from_vec( &mut self, nodes: Vec<N>, weight: E, ) -> Result<usize>
Add a hyperedge from a vector of nodes (convenience method)
Sourcepub fn remove_hyperedge(
&mut self,
hyperedge_id: usize,
) -> Result<Hyperedge<N, E>>
pub fn remove_hyperedge( &mut self, hyperedge_id: usize, ) -> Result<Hyperedge<N, E>>
Remove a hyperedge by its ID
Sourcepub fn hyperedges(&self) -> Vec<Hyperedge<N, E>>
pub fn hyperedges(&self) -> Vec<Hyperedge<N, E>>
Get all hyperedges in the hypergraph
Sourcepub fn get_hyperedge(&self, hyperedge_id: usize) -> Option<Hyperedge<N, E>>
pub fn get_hyperedge(&self, hyperedge_id: usize) -> Option<Hyperedge<N, E>>
Get a specific hyperedge by its ID
Sourcepub fn hyperedges_containing_node(&self, node: &N) -> Vec<Hyperedge<N, E>>
pub fn hyperedges_containing_node(&self, node: &N) -> Vec<Hyperedge<N, E>>
Get all hyperedges that contain a specific node
Sourcepub fn neighbors(&self, node: &N) -> HashSet<N>where
N: Clone,
pub fn neighbors(&self, node: &N) -> HashSet<N>where
N: Clone,
Get all nodes that are connected to a given node through some hyperedge
Returns all nodes that share at least one hyperedge with the given node
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Number of nodes in the hypergraph
Sourcepub fn hyperedge_count(&self) -> usize
pub fn hyperedge_count(&self) -> usize
Number of hyperedges in the hypergraph
Sourcepub fn has_hyperedge(&self, hyperedge_id: usize) -> bool
pub fn has_hyperedge(&self, hyperedge_id: usize) -> bool
Check if the hypergraph contains a specific hyperedge
Sourcepub fn degree(&self, node: &N) -> usize
pub fn degree(&self, node: &N) -> usize
Get the degree of a node (number of hyperedges it participates in)
Sourcepub fn hyperedge_size(&self, hyperedge_id: usize) -> Option<usize>
pub fn hyperedge_size(&self, hyperedge_id: usize) -> Option<usize>
Get the size of a hyperedge (number of nodes it connects)
Sourcepub fn are_connected(&self, node1: &N, node2: &N) -> bool
pub fn are_connected(&self, node1: &N, node2: &N) -> bool
Check if two nodes are connected (share at least one hyperedge)
Sourcepub fn connecting_hyperedges(&self, node1: &N, node2: &N) -> Vec<usize>
pub fn connecting_hyperedges(&self, node1: &N, node2: &N) -> Vec<usize>
Get the hyperedges that connect two specific nodes
Sourcepub fn to_graph(&self) -> Graph<N, E, Ix>
pub fn to_graph(&self) -> Graph<N, E, Ix>
Convert to a regular graph by creating edges between all pairs of nodes that are connected by the same hyperedge
This creates the 2-section (or clique expansion) of the hypergraph
Sourcepub fn incidence_matrix(&self) -> Array2<u8>
pub fn incidence_matrix(&self) -> Array2<u8>
Get the incidence matrix of the hypergraph
Returns a matrix where rows represent nodes and columns represent hyperedges. Entry (i,j) is 1 if node i is in hyperedge j, 0 otherwise.
Sourcepub fn is_uniform(&self) -> bool
pub fn is_uniform(&self) -> bool
Check if the hypergraph is uniform (all hyperedges have the same size)
Sourcepub fn uniformity(&self) -> Option<usize>
pub fn uniformity(&self) -> Option<usize>
Get the uniformity of the hypergraph (the common size if uniform, None otherwise)
Sourcepub fn hyperedge_size_stats(&self) -> (usize, usize, f64)
pub fn hyperedge_size_stats(&self) -> (usize, usize, f64)
Get statistics about hyperedge sizes
Sourcepub fn maximal_cliques(&self) -> Vec<HashSet<N>>where
N: Clone,
pub fn maximal_cliques(&self) -> Vec<HashSet<N>>where
N: Clone,
Find all maximal cliques in the hypergraph
A maximal clique is a set of nodes that are all connected to each other and cannot be extended by adding another node while maintaining this property. In hypergraphs, this corresponds to finding maximal sets of nodes that all participate in some common hyperedge.
Sourcepub fn from_graph(graph: &Graph<N, E, Ix>) -> Self
pub fn from_graph(graph: &Graph<N, E, Ix>) -> Self
Create a hypergraph from a regular graph where each edge becomes a 2-uniform hyperedge
Trait Implementations§
Auto Trait Implementations§
impl<N, E, Ix> Freeze for Hypergraph<N, E, Ix>
impl<N, E, Ix> RefUnwindSafe for Hypergraph<N, E, Ix>
impl<N, E, Ix> Send for Hypergraph<N, E, Ix>where
Ix: Send,
impl<N, E, Ix> Sync for Hypergraph<N, E, Ix>where
Ix: Sync,
impl<N, E, Ix> Unpin for Hypergraph<N, E, Ix>
impl<N, E, Ix> UnwindSafe for Hypergraph<N, E, Ix>
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> 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