BipartiteGraph

Struct BipartiteGraph 

Source
pub struct BipartiteGraph<N: Node, E: EdgeWeight, Ix: IndexType = u32> { /* private fields */ }
Expand description

A specialized bipartite graph structure

A bipartite graph is a graph whose vertices can be divided into two disjoint sets such that no two vertices within the same set are adjacent. This implementation enforces the bipartite property and provides optimized operations.

Implementations§

Source§

impl<N: Node + Debug, E: EdgeWeight, Ix: IndexType> BipartiteGraph<N, E, Ix>

Source

pub fn new() -> Self

Create a new empty bipartite graph

Source

pub fn from_graph(graph: Graph<N, E, Ix>) -> Result<Self>
where N: Clone, E: Clone,

Create a bipartite graph from a regular graph if it’s bipartite

§Arguments
  • graph - The input graph to convert
§Returns
  • Result<BipartiteGraph<N, E, Ix>> - The bipartite graph if conversion is successful
Source

pub fn add_node_to_set_a(&mut self, node: N)

Add a node to set A of the bipartition

Source

pub fn add_node_to_set_b(&mut self, node: N)

Add a node to set B of the bipartition

Source

pub fn add_edge(&mut self, source: N, target: N, weight: E) -> Result<()>
where N: Clone,

Add an edge between nodes from different sets

§Arguments
  • source - Source node (must be in one set)
  • target - Target node (must be in the other set)
  • weight - Edge weight
§Returns
  • Result<()> - Success or error if nodes are in the same set
Source

pub fn set_a(&self) -> &HashSet<N>

Get all nodes in set A

Source

pub fn set_b(&self) -> &HashSet<N>

Get all nodes in set B

Source

pub fn set_a_size(&self) -> usize

Get the size of set A

Source

pub fn set_b_size(&self) -> usize

Get the size of set B

Source

pub fn node_set(&self, node: &N) -> Option<u8>

Check which set a node belongs to

§Arguments
  • node - The node to check
§Returns
  • Some(0) if node is in set A, Some(1) if in set B, None if not found
Source

pub fn neighbors(&self, node: &N) -> Result<Vec<N>>
where N: Clone,

Get neighbors of a node (always from the opposite set)

Source

pub fn neighbors_in_a(&self, node: &N) -> Result<Vec<N>>
where N: Clone,

Get neighbors in set A for a node in set B

Source

pub fn neighbors_in_b(&self, node: &N) -> Result<Vec<N>>
where N: Clone,

Get neighbors in set B for a node in set A

Source

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

Get the degree of a node

Source

pub fn nodes(&self) -> Vec<&N>

Get all nodes in the graph

Source

pub fn edges(&self) -> Vec<Edge<N, E>>
where N: Clone, E: Clone,

Get all edges in the graph

Source

pub fn node_count(&self) -> usize

Number of nodes in the graph

Source

pub fn edge_count(&self) -> usize

Number of edges in the graph

Source

pub fn has_node(&self, node: &N) -> bool

Check if the graph has a node

Source

pub fn has_edge(&self, source: &N, target: &N) -> bool

Check if an edge exists between two nodes

Source

pub fn edge_weight(&self, source: &N, target: &N) -> Result<E>
where E: Clone,

Get the weight of an edge between two nodes

Source

pub fn biadjacency_matrix(&self) -> Array2<E>
where E: Zero + Copy, N: Clone,

Get the adjacency matrix representation of the bipartite graph

Returns a matrix where rows correspond to set A and columns to set B

Source

pub fn to_graph(self) -> Graph<N, E, Ix>

Convert to a regular graph

Source

pub fn as_graph(&self) -> &Graph<N, E, Ix>

Get a reference to the underlying graph

Source

pub fn is_complete(&self) -> bool

Check if the graph is complete bipartite (all possible edges exist)

Source

pub fn max_edges(&self) -> usize

Get the maximum possible number of edges for this bipartite graph

Source

pub fn density(&self) -> f64

Get the density of the bipartite graph (actual edges / max possible edges)

Trait Implementations§

Source§

impl<N: Node + Debug, E: EdgeWeight, Ix: IndexType> Default for BipartiteGraph<N, E, Ix>

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<N, E, Ix> Freeze for BipartiteGraph<N, E, Ix>

§

impl<N, E, Ix> RefUnwindSafe for BipartiteGraph<N, E, Ix>

§

impl<N, E, Ix> Send for BipartiteGraph<N, E, Ix>
where Ix: Send,

§

impl<N, E, Ix> Sync for BipartiteGraph<N, E, Ix>
where Ix: Sync,

§

impl<N, E, Ix> Unpin for BipartiteGraph<N, E, Ix>
where N: Unpin, E: Unpin, Ix: Unpin,

§

impl<N, E, Ix> UnwindSafe for BipartiteGraph<N, E, Ix>
where N: UnwindSafe, Ix: UnwindSafe, E: 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> 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, 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