我是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作为右子项,依此类推。此图也不强制所有'box; -shaped节点应位于图的底部。是否可以使用GraphViz构建这样的图形?
谢谢!
答案 0 :(得分: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
}
}
结果图片: