Construct multiple graphs from sparse adjacency matrix

I have a sparse adjacency matrix (SparseMatrixCSC) representing connections between the elements of a collection. I see that I can neatly convert it to a graph with the Graph constructor from Graphs.jl.

However, I know that the connections represent many smaller, unconnected graphs.

Is there a way to create multiple graphs representing the distinct networks or to split the single graph after calling Graph on the matrix?

I’ve been looking through the docs for a bit but I’m not finding a solution.

Connected components is probably what you’re looking for. Looks like Graphs.jl supports it for undirected graphs.

In the adjacency matrix are the vertices in one graph mixed with another along the axis? Or is it something like A[1:5, 1:5] is the first graph, A[5:10, 5:10] is the second etc.

The vertices are all mixed through the adjacency matrix, unfortunately, so the graphs aren’t neat blocks.

So then the connected components functionality is probably what you want. Graph Algorithms — Graphs.jl 0.3 documentation

Yes, seems like it’s exactly what I’m looking for. Thanks! I guess I just didn’t stumble onto the correct part of the docs.

1 Like