pub struct IndexedHypergraph { /* private fields */ }Expand description
A hypergraph with usize-indexed nodes and rich algorithmic support.
§Example
use scirs2_graph::hypergraph::{IndexedHypergraph, clique_expansion};
let mut hg = IndexedHypergraph::new(5);
hg.add_hyperedge(vec![0, 1, 2], 1.0).unwrap();
hg.add_hyperedge(vec![2, 3, 4], 1.0).unwrap();
let g = clique_expansion(&hg);
assert!(g.edge_count() >= 3);Implementations§
Source§impl IndexedHypergraph
impl IndexedHypergraph
Sourcepub fn new(n_nodes: usize) -> Self
pub fn new(n_nodes: usize) -> Self
Create an empty hypergraph with n_nodes nodes indexed 0..n_nodes.
Sourcepub fn n_hyperedges(&self) -> usize
pub fn n_hyperedges(&self) -> usize
Number of hyperedges.
Sourcepub fn hyperedges(&self) -> &[Hyperedge]
pub fn hyperedges(&self) -> &[Hyperedge]
Immutable reference to all hyperedges.
Sourcepub fn add_hyperedge(&mut self, nodes: Vec<usize>, weight: f64) -> Result<usize>
pub fn add_hyperedge(&mut self, nodes: Vec<usize>, weight: f64) -> Result<usize>
Add a new hyperedge. Nodes that exceed n_nodes are rejected.
Returns the newly assigned hyperedge id.
Sourcepub fn hyperedges_of_node(&self, node: usize) -> Option<&[usize]>
pub fn hyperedges_of_node(&self, node: usize) -> Option<&[usize]>
Return all hyperedge ids that contain node.
Sourcepub fn degree(&self, node: usize) -> usize
pub fn degree(&self, node: usize) -> usize
Degree of a node = number of hyperedges it belongs to (unweighted).
Sourcepub fn weighted_degree(&self, node: usize) -> f64
pub fn weighted_degree(&self, node: usize) -> f64
Weighted degree of a node = sum of weights of incident hyperedges.
Sourcepub fn incidence_matrix(&self) -> Array2<f64>
pub fn incidence_matrix(&self) -> Array2<f64>
Compute the node–hyperedge incidence matrix B of shape (n_nodes × n_hyperedges).
B[i, e] = sqrt(w_e) when node i is in hyperedge e, else 0.
Sourcepub fn incidence_matrix_binary(&self) -> Array2<f64>
pub fn incidence_matrix_binary(&self) -> Array2<f64>
Compute the raw (unweighted) incidence matrix B where B[i,e] ∈ {0,1}.
Sourcepub fn star_expansion(&self) -> Graph<usize, f64>
pub fn star_expansion(&self) -> Graph<usize, f64>
Build the star expansion of this hypergraph.
Each hyperedge e is replaced by a new auxiliary node (indexed
n_nodes + e). The auxiliary node is connected to every member of
e with weight w_e. The resulting graph has n_nodes + n_hyperedges
nodes.
Sourcepub fn bipartite_representation(&self) -> BaseHypergraph<usize, f64>
pub fn bipartite_representation(&self) -> BaseHypergraph<usize, f64>
Build the bipartite representation of this hypergraph.
Returns a hypergraph where the left partition contains original nodes (indices 0..n_nodes) and the right partition contains hyperedge auxiliary nodes (indices n_nodes..n_nodes+n_hyperedges). Each 2-element hyperedge {original_node, aux_hyperedge_node} encodes a membership relation.
Trait Implementations§
Source§impl Clone for IndexedHypergraph
impl Clone for IndexedHypergraph
Source§fn clone(&self) -> IndexedHypergraph
fn clone(&self) -> IndexedHypergraph
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for IndexedHypergraph
impl RefUnwindSafe for IndexedHypergraph
impl Send for IndexedHypergraph
impl Sync for IndexedHypergraph
impl Unpin for IndexedHypergraph
impl UnsafeUnpin for IndexedHypergraph
impl UnwindSafe for IndexedHypergraph
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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