如何在图形中找到最大度数的所有顶点?

时间:2012-01-16 00:25:58

标签: wolfram-mathematica

给出图表,说

g = Graph[{x -> a, y -> c, a -> b,
           b -> c, a -> c, d -> c,
           a -> d, b -> d},
      VertexLabels -> "Name"] 

g

如何在图形中找到具有最大度数的所有顶点,即具有最多边数的所有顶点的列表,并在图形中突出显示它们?

在这种情况下,它将是顶点{a,c}

3 个答案:

答案 0 :(得分:5)

您通常可以按度数突出显示顶点:

    HighlightGraph[g, 
 Table[Style[VertexList[g][[i]], 
   ColorData["TemperatureMap"][
    VertexDegree[g][[i]]/Max[VertexDegree[g]]]], {i, VertexCount[g]}]]

enter image description here

答案 1 :(得分:5)

以下是使用DegreeCentrality的方法:

(* In[41]:= *) max = Pick[VertexList[g], DegreeCentrality[g], Max[DegreeCentrality[g]]]

(* Out[41]= *) {a, c}

(* In[42]:= *) HighlightGraph[g, max]

enter image description here

答案 2 :(得分:3)

这是我试过的

HighlightGraph[g, 
 Part[VertexList@g, 
  Flatten@Position[VertexDegree@g, Max[VertexDegree@g]]]]

hg

使用Pick

相同
HighlightGraph[g, Pick[VertexList@g, VertexDegree@g, Max[VertexDegree@g]]]