Get node names after a graph condensation

1 回表示 (過去 30 日間)
stam dadi
stam dadi 2017 年 12 月 4 日
コメント済み: Waseem AL Aqqad 2021 年 11 月 27 日
I have an adjacency matrix adj and a cellarray nodeManes that contains names that will be given to the graph G that will be constructed from adj
So I use
G = digraph(adj,nodeNames);
And I get the following graph :
Now , I want to find the strongly connected components in G and do a graph condensation so I use the following :
C = condensation(G);
p2 = plot(C);
So I get the following graph :
So I have 6 strongly connected components , but my problem is that I lost the node names , I want to get something like :
Is that any way to get the nodes names in the result of the condentation ?
Thanks.

採用された回答

Christine Tobler
Christine Tobler 2017 年 12 月 4 日
Here is some code that does this:
bins = conncomp(G);
compNames = cell(max(bins), 1);
for ii=1:length(bins)
if isempty(compNames{bins(ii)})
compNames{bins(ii)} = G.Nodes.Name{ii};
else
compNames{bins(ii)} = [compNames{bins(ii)} ', ' G.Nodes.Name{ii}];
end
end
C.Nodes.Name = compNames;
plot(C);
There's no one-line command to combine several node names based on the vector of bins used in condensation, so I wrote a for-loop to do this instead.
  2 件のコメント
stam dadi
stam dadi 2017 年 12 月 4 日
Thank's
Waseem AL Aqqad
Waseem AL Aqqad 2021 年 11 月 27 日
Thanks, Christine

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

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2017 年 12 月 4 日
Stealing basic technique from Christine, and reworking it without a loop:
bins = conncomp(G);
temp = accumarray(bins.', (1:length(bins)).', [], @(IDX) {G.Nodes.Name(IDX)});
C.Nodes.Name = cellfun(@(CS) strjoin(CS, ', '), temp, 'uniform', 0);
  10 件のコメント
stam dadi
stam dadi 2017 年 12 月 5 日
yes.. I just checked , I accidently deleted the line :
C = condensation(G);
Thank's
Waseem AL Aqqad
Waseem AL Aqqad 2021 年 11 月 27 日
Wow! Thanks.

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by