Showing posts with label graphviz. Show all posts

graphviz crazy testing

小Q讀書會12月討論《自願被吃的豬》,內容由100則小故事組合,每篇引起一些哲學思考實驗,完整的讀書心得在此。這本書每篇故事後面都指出另外四篇相關的文章,整理心得時突發奇想,若把這樣的關係圖畫出來不知會如何?

一想到共有100 nodes,400 edges,直覺就是拿 graphviz 來產生,否則要一一畫點連線,我會瘋掉~

by using raw editing, replacement text editor tips, the dot file was be written in the short time.
http://freetexthost.com/sjcxlh4ew1


這個dot檔有幾個特性:
1. 共有 100 個 node
2. 每個 node 會指向其他四個 node, 所以共有 400 條 edge
3. 相連的 node 相關性較高。所以可能有幾個 node 彼此相連,而不和其他 node 相關連的情況

透過 graphviz 畫出來的圖如下:
 自願被吃的豬
好花阿~跟想像中完全不一樣。
雖然知道一些 graphviz 排版技巧,但面對這麼複雜的圖,完全沒有頭緒從何排版起。

上了 graphviz 查了一下,原來有多種不同的 layout 方式可以使用。預設是標準的 dot layout
dot - ``hierarchical'' or layered drawings of directed graphs. The layout algorithm aims edges in the same direction (top to bottom, or left to right) and then attempts to avoid edge crossings and reduce edge length.

以下是使用不同 layout 產生的圖:

neato - ``spring model'' layouts. Neato attempts to minimize a global energy function, which is equivalent to statistical multi-dimensional scaling. The solution is achieved using stress majorization, though the older Kamada-Kawai algorithm, using steepest descent, is also available. fdp implements the Fruchterman-Reingold heuristic including a multigrid solver that handles larger graphs and clustered undirected graphs.
neato

fdp - ``spring model'' layouts similar to those of neato, but does this by reducing forces rather than working with energy. Fdp implements the Fruchterman-Reingold heuristic including a multigrid solver that handles larger graphs and clustered undirected graphs.
sfdp - multiscale version of fdp for the layout of large graphs.
sfdp

twopi - radial layouts, after Graham Wills 97. The nodes are placed on concentric circles depending their distance from a given root node.
twopi

至於我心中最理想的 circo layout algorithm 則跑不出結果,可能太複雜了吧。XD
circo - circular layout, after Six and Tollis 99, Kauffman and Wiese 02. This is suitable for certain diagrams of multiple cyclic structures such as certain telecommunications networks.

由結果可見 neato, sdfp, twopi 都有中心區塊較複雜、邊緣較簡單的情況,尤其以 twopi 更明顯,關連最多的點幾乎都在中心區塊了。而本圖的『群組』特性,則是 dot, sdfp 呈現的比較清楚,相關的 node 幾乎會在附近自成一圈。

這個 special case 還挺好玩的,graphviz 要深入摸索也還有很多有趣的點子。
真佩服這樣的 open source project,總帶來許多創意跟活力。

Graphviz

知道 Graphviz 這玩具已經很久了,不過一直以來沒有直接需求,也就一直沒去了解如何使用。近來因寫論文需要畫些關係圖,上網找了些 Graphviz 的資料,沒想到意外的簡單好用。

DOT文件的寫法相當straightforward,幾篇文章看完就上手了,至於細節的調整則是翻翻 manual 找一下語法就知道。以後關係圖只需要專心用鍵盤打文件,不用花時間抓著老鼠在螢幕上畫來滑去,軟體就該這麼白痴阿!

閒暇之餘也拿了小Q讀書會這次要討論的『貝納德的墮落』來畫了些關係圖,看那 graphviz 所畫出來的曲線,多麼的性感迷人!真不知道以前用 Visio 在畫些什麼鳥。

無向圖 (貝納德的墮落 人物關係)
harvest (by kywk)

有向圖 (貝納德的墮落 劇情發展)
harvest_guide (by kywk)

---
後記:
發覺 graphviz 無法繪製傳統流程圖如下,希望能列入TODO list,有空的話也會來看看 source code,自己來改寫一下新功能,回饋社群。


Graphviz - Graph Visualization Software
http://www.graphviz.org/

畫關係圖的小幫手 : graphviz - 紅塵一隅間拾得
http://greenisland.csie.nctu.edu.tw/wp/2007/04/13/989/
史丹利部落格 Doxygen and Graphviz
http://stenlyho.blogspot.com/2008/08/doxygen-and-graphviz.html
用 Graphviz 畫資料庫設計圖
http://shelandy.blogspot.com/2009/02/graphviz_24.html
用 Graphviz 来做图的 Visualization
http://lifegoo.pluskid.org/?p=360
Automate the creation of graphs with Graphviz
http://www.linuxfocus.org/English/August2005/article387.shtml
UML Diagrams Using Graphviz Dot
http://www.ffnn.nl/pages/articles/media/uml-diagrams-using-graphviz-dot.php