2017-02-19 83 views
1

我是graphviz的新手,並生成了一個包含時間約束的圖。也就是說,節點從左到右的順序很重要,但只在本地。這裏是我試圖強制執行的規則集:GraphViz節點的時間排序

1)只有和所有的'盒'形節點應該在圖的底部。這些代表終端節點。 2)任何在「雙圓」形節點處的規則都有時間限制(即排序問題)。

下面是執行這些規則的嘗試:

digraph G { 
0 [shape=box, fillcolor=lightgrey, style=filled, ranksep=0.5, nodesep=0.5] 
1 [shape=box, fillcolor=lightgrey, style=filled, ranksep=0.5, nodesep=0.5] 
2 [shape=box, fillcolor=lightgrey, style=filled, ranksep=0.5, nodesep=0.5] 
3 [shape=box, fillcolor=lightgrey, style=filled, ranksep=0.5, nodesep=0.5] 
4 [shape=box, fillcolor=lightgrey, style=filled, ranksep=0.5, nodesep=0.5] 
5 [shape=box, fillcolor=lightgrey, style=filled, ranksep=0.5, nodesep=0.5] 
6 [shape=box, fillcolor=lightgrey, style=filled, ranksep=0.5, nodesep=0.5] 
7 [shape=box, fillcolor=lightgrey, style=filled, ranksep=0.5, nodesep=0.5] 
8 [shape=box, fillcolor=lightgrey, style=filled, ranksep=0.5, nodesep=0.5] 
9 [shape=doublecircle, fillcolor=palegreen3, style=filled, color=blue, ranksep=0.5, nodesep=0.5] 
9 -> 0 [penwidth=3, weight=3] 
9 -> 2 [penwidth=3, weight=3] 
{ 
    rank=same; 
    0->2[color=white] 
    rankdir=LR; 
} 
10 [shape=doublecircle, fillcolor=palegreen3, style=filled, color=blue, ranksep=0.5, nodesep=0.5] 
10 -> 9 [penwidth=3, weight=3] 
10 -> 5 [penwidth=3, weight=3] 
{ 
    rank=same; 
    9->5[color=white] 
    rankdir=LR; 
} 
11 [shape=doublecircle, fillcolor=palegreen3, style=filled, color=blue, ranksep=0.5, nodesep=0.5] 
11 -> 4 [penwidth=3, weight=3] 
11 -> 10 [penwidth=3, weight=3] 
{ 
    rank=same; 
    4->10[color=white] 
    rankdir=LR; 
} 
12 [shape=doublecircle, fillcolor=palegreen3, style=filled, color=blue, ranksep=0.5, nodesep=0.5] 
12 -> 10 [penwidth=3, weight=3] 
12 -> 11 [penwidth=3, weight=3] 
{ 
    rank=same; 
    10->11[color=white] 
    rankdir=LR; 
} 
13 [shape=doublecircle, fillcolor=palegreen3, style=filled, color=blue, ranksep=0.5, nodesep=0.5] 
13 -> 4 [penwidth=3, weight=3] 
13 -> 9 [penwidth=3, weight=3] 
{ 
    rank=same; 
    4->9[color=white] 
    rankdir=LR; 
} 
14 [shape=doublecircle, fillcolor=palegreen3, style=filled, color=blue, ranksep=0.5, nodesep=0.5] 
14 -> 26 [penwidth=3, weight=3] 
14 -> 8 [penwidth=3, weight=3] 
{ 
    rank=same; 
    26->8[color=white] 
    rankdir=LR; 
} 
15 [shape=doublecircle, fillcolor=palegreen3, style=filled, color=blue, ranksep=0.5, nodesep=0.5] 
15 -> 12 [penwidth=3, weight=3] 
15 -> 13 [penwidth=3, weight=3] 
{ 
    rank=same; 
    12->13[color=white] 
    rankdir=LR; 
} 
26 [shape=circle, fillcolor=palegreen1, style=filled, color=blue, ranksep=0.5, nodesep=0.5] 
26 -> 12[label = "0.50", penwidth=2.0, weight=3 ] 
26 -> 15[label = "0.50", penwidth=2.0, weight=3 ] 
} 

從規則集,節點9應有0作爲左子和2右孩子,等等。該圖並不強制所有'盒形結點應位於圖的底部。使用GraphViz創建這樣一個圖表有可能嗎?

謝謝!

回答

0

我不完全確定你想如何看這張圖,但我已經做了一個嘗試。所有的盒子都在底部,這是使用一個集羣子圖完成的(如果你不喜歡盒子,你可以改變樣式)。爲了防止邊緣從「特殊」邊緣(代碼中的白色,因爲背景也是白色的紅色)干擾排序,我在這些邊上指定了constraint = false。讓我知道這是否有幫助。

的代碼:

digraph G { 
    subgraph clusterSquares { 
     rank = same 
     node [shape=box, fillcolor=lightgrey, style=filled, ranksep=0.5, nodesep=0.5] 
     0; 1; 2; 3; 4; 5; 6; 7; 8; 
    } 
    { 
     node [shape=doublecircle, fillcolor=palegreen3, style=filled, color=blue, ranksep=0.5, nodesep=0.5] 
     edge [penwidth=3, weight=3] 
     9 -> { 0; 2; } 
     10 -> { 5; 9; } 
     11 -> { 4; 10 } 
     12 -> { 10; 11; } 
     13 -> { 4; 9; } 
     14 -> { 26; 8; } 
     15 -> { 12; 13; } 
     26 -> { 12; 15; } 
    } 
    { 
     edge [color = red, constraint = false] 
     0 -> 2 
     9 -> 5 
     4 -> 10 
     10 -> 11 
     4 -> 9 
     26 -> 8 
     13 -> 13 
    } 
} 

所得圖像:

enter image description here