2012-01-16 126 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

相關問題