Skip to main content

IndexedHypergraph

Struct IndexedHypergraph 

Source
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

Source

pub fn new(n_nodes: usize) -> Self

Create an empty hypergraph with n_nodes nodes indexed 0..n_nodes.

Source

pub fn n_nodes(&self) -> usize

Number of nodes (constant after construction).

Source

pub fn n_hyperedges(&self) -> usize

Number of hyperedges.

Source

pub fn hyperedges(&self) -> &[Hyperedge]

Immutable reference to all hyperedges.

Source

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.

Source

pub fn hyperedges_of_node(&self, node: usize) -> Option<&[usize]>

Return all hyperedge ids that contain node.

Source

pub fn degree(&self, node: usize) -> usize

Degree of a node = number of hyperedges it belongs to (unweighted).

Source

pub fn weighted_degree(&self, node: usize) -> f64

Weighted degree of a node = sum of weights of incident hyperedges.

Source

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.

Source

pub fn incidence_matrix_binary(&self) -> Array2<f64>

Compute the raw (unweighted) incidence matrix B where B[i,e] ∈ {0,1}.

Source

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.

Source

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

Source§

fn clone(&self) -> IndexedHypergraph

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 Debug for IndexedHypergraph

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V