2012-01-16 30 views
6

给定一个图,说如何找到最大度数的图中的所有顶点?

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

g

如何找到与最大程度即拥有数量最多的边的所有顶点的列表的图中所有的顶点,并强调他们在图表?

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

回答

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

+0

我认为'DegreeCentrality'行为类似于'VertexDegree'? “Pick”+1,节省了几条线,并且更加整洁[比我的方法] – 2012-01-17 00:15:16

3

这里是我一直在使用Pick

HighlightGraph[g, Pick[[email protected], [email protected], Max[[email protected]]]] 
+0

您的解决方案看起来就像是我想出了:'HighlightGraph [G, VertexList时,[G] [拼合[位置[vd,Max [vd = VertexDegree [g]]],1]]]]'您可以使用各自的谓词代替'VertexDegree'来突出显示'VertexInDegree'或'VertexOutDegree'。 – DavidC 2012-01-16 01:19:29

+0

看起来很适合我。 – kkm 2012-01-16 01:19:36

5

你通常可以通过突出学位顶点试图

HighlightGraph[g, 
Part[[email protected], 
    [email protected][[email protected], Max[[email protected]]]]] 

hg

一样:

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

enter image description here

+0

欢迎来到StackOverflow!我看着你的博客和Vimeo频道,这是非常复杂的。 :-)与SO相同格式的新Mathematica特定站点将在几天内发布。您可以[在此处提交](http://area51.stackexchange.com/proposals/37304/mathematica?referrer=23yK9sXkBPQIDM_9uBjtlA2)以获得早期访问权限。 – Szabolcs 2012-01-16 08:30:33

+0

谢谢,Szabolcs!我已经承诺;-) – 2012-01-16 14:54:23

相关问题