Struct WeightedUndirectedAdjacencyMatrixCondensed

Source
pub struct WeightedUndirectedAdjacencyMatrixCondensed { /* private fields */ }
Expand description

An adjacency matrix representing an undirected graph is symmetric with respect to the main diagonal, i.e. g[i][j] = g[j][i]. Thus, only half of the values in the matrix need to be stored. In addition, The assumption that g[i][i] = 0 works fine in most cases, so weights representing these self-pointing edges are also not stored.

Thus a condensed matrix stores only g[i][j] where i < j in a vector of length ${}^{n}C_{2} = \dfrac{n(n-1)}{2}$ (n-choose-2). For example, in a graph with 4 vertices, the 6 weights in the condensed vector represents g[0 -> 1], g[0 -> 2], g[0 -> 3], g[1 -> 2], g[1 -> 3], g[2 -> 3], respectively.

Implementations§

Source§

impl WeightedUndirectedAdjacencyMatrixCondensed

Source

pub fn new(node_count: usize) -> Self

Source

pub fn from_adjacency_list(inp: &WeightedAdjacencyList) -> Self

Build a WeightedUndirectedAdjacencyMatrixCondensed from WeightedAdjacencyList. The graph must be undirected. Even if the WeightedAdjacencyList were build with directed edges, they are treated as undirected edges.

§Panics

Panics if the WeightedAdjacencyList contains both g[i -> j] and g[j -> i] but their weights differ

Source

pub fn from_slice(inp: &[f64]) -> Self

Builds a WeightedUndirectedAdjacencyMatrixCondensed from its inner representation.

Source

pub fn edges(&self) -> impl Iterator<Item = (usize, usize, f64)> + '_

Iterate over all pairs of nodes (i, j) where i < j with the weight associated with the pair. Each item is a tuple of 3: (i, j, weight). Note that only (i, j) but not (j, i) is outputted.

Source

pub fn node_count(&self) -> usize

Number of nodes (vertices) in the graph

Source

pub fn resized(&self, new_node_count: usize) -> Self

Trait Implementations§

Source§

impl Debug for WeightedUndirectedAdjacencyMatrixCondensed

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Display for WeightedUndirectedAdjacencyMatrixCondensed

Source§

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

Formats the value using the given formatter. Read more
Source§

impl From<WeightedAdjacencyList> for WeightedUndirectedAdjacencyMatrixCondensed

Source§

fn from(inp: WeightedAdjacencyList) -> Self

Converts to this type from the input type.
Source§

impl Index<(usize, usize)> for WeightedUndirectedAdjacencyMatrixCondensed

This allows indexing into graphs represented by WeightedUndirectedAdjacencyMatrixCondensed easier. For example, for a graph g, either g[(i, j)] or g[(j, i)] will give the weight associated with node i and node j (remember the graph is undirected)

Source§

type Output = f64

The returned type after indexing.
Source§

fn index(&self, (i, j): (usize, usize)) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl IndexMut<(usize, usize)> for WeightedUndirectedAdjacencyMatrixCondensed

Source§

fn index_mut(&mut self, (i, j): (usize, usize)) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. 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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.