2014年7月28日 星期一

[ALPS] SimpleGraphs

這是個簡單的繪圖,共有五個端點 (vertices) 以及五個連結 (edges) ,這東西的定義方式我們會將它放在一個 Lattice.xml 之中,而其內容如下:

<GRAPH vertices="5" edges="5">
<EDGE source="1" target="2"/>
<EDGE source="2" target="3"/>
<EDGE source="1" target="4"/>
<EDGE source="2" target="5"/>
<EDGE source="4" target="5"/>
</GRAPH>

整個內容是使用 <GTAPH> 和</GRAPH> 包含起來的,這是XML的格式,習慣HTML的人應該也多少不會太陌生,其中每個 edges 必須清楚告知它必須從哪個點連接到哪個點,也就是 source 和 target ,而這定義的風格似乎是盡量從左上往右下走,目前我尚且不明白這部分是否有任何特殊含意


 


這裡也提供另一種定義方法,是讓 vertices 帶有顏色的,如下圖:



這裡的紅、綠、藍分別使用 0 、 1 、 2 作為代碼,根據這個圖片我們可以寫下如此定義





<GRAPH vertices="5" edges="5">
<VERTEX id="1" type="0"/>
<VERTEX id="2" type="1"/>
<VERTEX id="3" type="0"/>
<VERTEX id="4" type="2"/>
<VERTEX id="5" type="2"/>
<EDGE source="1" target="2" type="0"/>
<EDGE source="2" target="3" type="0"/>
<EDGE source="1" target="4" type="1"/>
<EDGE source="2" target="5" type="1"/>
<EDGE source="4" target="5" type="0"/>
</GRAPH>

和上一次的程式碼不同的是,此次我們明白的指出了 vertices 的 id ,並在後頭指明它的 type ,也就是顏色,而這些資訊被包裹在 <VERTEX> 中,edge 的 type 也被標記了,這代表的是圖中的虛線和實線,當然最外層必須以 <GRAPH> 和 </GRAPH> 包著。


在網站上也提供了簡短版本的定義,這是基於一些 default 的東西所產生的,像是 VERTEX 和 EDGE 如果不進行指定,它的 type 會自動設定為零,而ID如果不特別指定,也會自動依序排下等等...….我不是很喜歡這種做法,易讀性感覺會受到影響,但仍能做為參考:





<GRAPH>
<VERTEX/>
<VERTEX type="1"/>
<VERTEX/>
<VERTEX type="2"/>
<VERTEX type="2"/>
<EDGE source="1" target="2"/>
<EDGE source="2" target="3"/>
<EDGE source="1" target="4" type="1"/>
<EDGE source="2" target="5" type="1"/>
<EDGE source="4" target="5"/>
</GRAPH>

 


接著是座標的部分,我們同樣可以使用直接指定座標的方式來定義 vertics





<GRAPH vertices="5" edges="5">
<VERTEX id="1"> <COORDINATE> 1 1 </COORDINATE> </VERTEX>
<VERTEX id="2"> <COORDINATE> 2 1 </COORDINATE> </VERTEX>
<VERTEX id="3"> <COORDINATE> 3 1 </COORDINATE> </VERTEX>
<VERTEX id="4"> <COORDINATE> 1 2 </COORDINATE> </VERTEX>
<VERTEX id="5"> <COORDINATE> 2 2 </COORDINATE> </VERTEX>
<EDGE source="1" target="2"/>
<EDGE source="2" target="3"/>
<EDGE source="1" target="4"/>
<EDGE source="2" target="5"/>
<EDGE source="2" target="3"/>
</GRAPH>

這方法是多了一個子目錄來存放座標元素,實際上取用我猜應該會視用類似 . id.coorinate 之類的方法吧?


 


參考資料與圖源:
http://alps.comp-phys.org/mediawiki/index.php/Tutorials:LatticeHOWTO:SimpleGraphs

沒有留言:

張貼留言