Properties of adjacency matrix

2 ビュー (過去 30 日間)
Marc Laub
Marc Laub 2020 年 7 月 17 日
コメント済み: Marc Laub 2022 年 11 月 30 日
Hey
following thought about the adjacency matrix of a graph.
Is it possible to distinguish from the adjacency matrix of a graph if the whole system of points is interconnected, or if there are 2 or more subsystems, whcih have connections inside each subsystem but the subsystems are not connected to each other.
Which properties does the adjacency matrix need to represent a interconnected system, or where do i have to seed the "ones" in the matrox to ensure the whole system is interconnected?
I havent figured it out on my own my some example systems, but maybe someone has the answer on this already.
many thanks in advance

採用された回答

Bruno Luong
Bruno Luong 2020 年 7 月 27 日
編集済み: Bruno Luong 2020 年 7 月 27 日
Here is a quick and dirty calculation of connexed component using adjacent matrix. It returns the same output as MATLAB conncomp function in BINS and BINSIZES.
% TMW example
s = [1 2 2 3 3 3 4 5 5 5 8 8 9];
t = [2 3 4 1 4 5 5 3 6 7 9 10 10];
G = digraph(s,t,[],20);
A = G.adjacency;
A = spones(A + A'); % no need to symmetrize for undirected graph
n = size(A,1);
bins = zeros(n,1);
k = 0;
while any(bins==0)
x = sparse(find(~bins,1), 1, true, n, 1, n);
y = x;
while true
y = A*y;
y = y > 0 & ~x;
if nnz(y) == 0
break
end
x = x | y;
end
k = k+1;
bins(x) = k;
end
% Formating output
nodes = (1:n)';
Comptable = table(nodes, bins);
CompSet = accumarray(bins, nodes, [], @(x) {sort(x)'});
binsizes = accumarray(bins, 1);
Display
plot(G,'Layout','layered')
k = length(CompSet);
fprintf('Graph has %d bins(s)\n', k);
Comptable
binsizes
for i=1:k
fprintf('Compnent %d: Nodes = %s\n', i, mat2str(CompSet{i}));
end
  2 件のコメント
Bruno Luong
Bruno Luong 2022 年 11 月 29 日
What is the deal of accepting my answer after more than 2 years?
Thanks anyway.
Marc Laub
Marc Laub 2022 年 11 月 30 日
Someones answer to another recent question of mine was, that I marked to few answers as accepted. So I went back my whole history to catch up... Seems some people care more than others

サインインしてコメントする。

その他の回答 (3 件)

Bruno Luong
Bruno Luong 2020 年 7 月 17 日
Checkout conncomp
  3 件のコメント
Bruno Luong
Bruno Luong 2020 年 7 月 17 日
I can't see why you stop yourself of using graph, which is no more no less than the object build around an adjadcent matrix, with a lot of convenient build-in stock functions. Anyway it's your call.
I'll delete this answer in few hours since it's not what you are expected.
Steven Lord
Steven Lord 2020 年 7 月 17 日
What "special properties" did you need that prevented you from using graph or digraph? If you need the nodes and/or edges to have additional information associated with them, you can do that. See this documentation page for details.

サインインしてコメントする。


Christine Tobler
Christine Tobler 2020 年 7 月 27 日
In terms of the adjacency matrix, a disconnected graph means that you can permute the rows and columns of this matrix in a way where the new matrix is block-diagonal with two or more blocks (the maximum number of diagonal blocks corresponds to the number of connected components).
If you want to compute this from scratch, you'll be better off using graph-style algorithms instead of matrix terminology, specifically a breadth-first search or depth-first search. These can be implemented in terms of the adjacency matrix, although it will be less efficient than the built-in used in the graph object. See https://en.wikipedia.org/wiki/Component_(graph_theory) which has some discussion of the algorithms involved.
  1 件のコメント
Bruno Luong
Bruno Luong 2020 年 7 月 27 日
編集済み: Bruno Luong 2020 年 7 月 27 日
Here is a quick and dirty check of graph connexity using adjacent matrix. But I agree why not using stock function that is much better implemented (there is also some code on the FEX using graph algo, that once I checked out - can't remember the name - but I ended up using my own on implementation)
% A is the adjacent matrix, assumed to be symmetric (undirect graph)
n = size(A,1);
x = zeros(n,1);
x(1) = 1;
c = 1; % sum(x)
while true
x = A*x > 0 | x;
s = sum(x);
if s == c
break
end
c = s;
end
if c == n
fprintf('Single component\n');
else
fprintf('Multiple components\n');
end

サインインしてコメントする。


Bruno Luong
Bruno Luong 2020 年 7 月 27 日
編集済み: Bruno Luong 2020 年 7 月 27 日
Another way - most direct perhaps link to matrix property - is using this property of Laplacian matrix:
"The number of connected components in the graph is the dimension of the nullspace of the Laplacian and the algebraic multiplicity of the 0 eigenvalue." from https://en.wikipedia.org/wiki/Laplacian_matrix
Not sure how is the numerical stability (probably not very reliable).
% TMW example
s = [1 2 2 3 3 3 4 5 5 5 8 8 9];
t = [2 3 4 1 4 5 5 3 6 7 9 10 10];
G = graph(s,t);
A = G.adjacency;
Use Laplacian
D = diag(sum(A)); % degree matrix
L = D - A; % laplacian matrix
[Q,R,P] = qr(L);
nc = full(sum(abs(diag(R)) < eps)) % number of components
  1 件のコメント
Bruno Luong
Bruno Luong 2020 年 7 月 28 日
編集済み: Bruno Luong 2020 年 7 月 28 日
A basis of the null space of the Laplacian is actually the indicator (characteristic) functions of each connected component of G.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGraph and Network Algorithms についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by