pub struct WeightedAdjacencyMatrix { /* private fields */ }
Expand description
Dense graphs, are sometimes more efficient to be represented as adjacency matrices.
A WeightedAdjacencyMatrix
is based on a Matrix of size n * n
where n is the number of nodes (vertices) in
the graph.
For a WeightedAdjacencyMatrix
g
, g[i][j]
is the weight of the edge pointing from node i
to node j
. By convention, for two nodes i
and j
that are not connected, g[i][j] = INFINITY
,
and each node by default has a weight of 0
to point to itself (i.e. g[i][i]
= 0).
Implementations§
Source§impl WeightedAdjacencyMatrix
impl WeightedAdjacencyMatrix
pub fn with_size(n: usize) -> Self
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Number of nodes in the graph.
Sourcepub fn from_adjacency_list(inp: &WeightedAdjacencyList) -> Self
pub fn from_adjacency_list(inp: &WeightedAdjacencyList) -> Self
Converts a WeightedAdjacencyList
to WeightedAdjacencyMatrix
Sourcepub fn from_inner(matrix: Vec<Vec<f64>>) -> Self
pub fn from_inner(matrix: Vec<Vec<f64>>) -> Self
Builds a WeightedAdjacencyMatrix
from its underlying representation.
Trait Implementations§
Source§impl Display for WeightedAdjacencyMatrix
Pretty-prints a small graph represented by an adjacency matrix
impl Display for WeightedAdjacencyMatrix
Pretty-prints a small graph represented by an adjacency matrix
Source§impl From<WeightedAdjacencyList> for WeightedAdjacencyMatrix
For convinience
impl From<WeightedAdjacencyList> for WeightedAdjacencyMatrix
For convinience
Source§fn from(inp: WeightedAdjacencyList) -> Self
fn from(inp: WeightedAdjacencyList) -> Self
Source§impl Index<usize> for WeightedAdjacencyMatrix
This allows us to access the weight of edge i -> j
in graph g
by g[i][j]
rather than g.inner[i][j]
impl Index<usize> for WeightedAdjacencyMatrix
This allows us to access the weight of edge i -> j
in graph g
by g[i][j]
rather than g.inner[i][j]