split_out_subgraphs: Split adjacency matrix into subgraphs

View source: R/split_out_subgraphs.R

split_out_subgraphsR Documentation

Split adjacency matrix into subgraphs

Description

Given a graph represented by an adjacency matrix splits into all connected subgraphs.

Usage

split_out_subgraphs(adjacency_matrix)

Arguments

adjacency_matrix

An adjacency matrix where the diagonal is zeroes and the off-diagonal either ones (if the two vertices are directly connected) or zeroes (if not directly connected).

Details

This functions take any undirected graph (connected or unconnected) represented as an adjacency matrix and identifies all connected subgraphs and returns these as a list of adjacency matr(ices).

Value

A list of all connected subgraphs represented as adjacency matri(ces).

Author(s)

Graeme T. Lloyd graemetlloyd@gmail.com

Examples


# Create an adjacency matrix representing an unconnected graph:
adjacency_matrix <- matrix(
  data = c(
    0, 0, 0, 1, 1, 0,
    0, 0, 1, 0, 0, 1,
    0, 1, 0, 0, 0, 1,
    1, 0, 0, 0, 0, 0,
    1, 0, 0, 0, 0, 0,
    0, 1, 1, 0, 0, 0
  ),
  ncol = 6,
  byrow = TRUE,
  dimnames = list(LETTERS[1:6], LETTERS[1:6])
)

# Check graph is connected:
split_out_subgraphs(adjacency_matrix = adjacency_matrix)


Claddis documentation built on Sept. 11, 2024, 9:18 p.m.