在Graphviz中对群集节点进行排序

3
我有以下(简化的)图表,由以下.dot生成:

enter image description here

digraph Configurations {

  subgraph cluster_1 {
    s_0_0 [shape=circle,style=filled,fixedsize=true,width=0.5,label="0",fillcolor=yellowgreen]
    s_0_1 [shape=circle,style=filled,fixedsize=true,width=0.5,label="1",fillcolor=yellowgreen]
  }
  subgraph cluster_2 {
    s_1_0 [shape=circle,style=filled,fixedsize=true,width=0.5,label="0",fillcolor=yellowgreen]
    s_1_1 [shape=circle,style=filled,fixedsize=true,width=0.5,label="1",fillcolor=white]
  }
  subgraph cluster_3 {
    s_2_0 [shape=circle,style=filled,fixedsize=true,width=0.5,label="0",fillcolor=white]
    s_2_1 [shape=circle,style=filled,fixedsize=true,width=0.5,label="1",fillcolor=yellowgreen]
  }
  subgraph cluster_4 {
    s_3_0 [shape=circle,style=filled,fixedsize=true,width=0.5,label="0",fillcolor=white]
    s_3_1 [shape=circle,style=filled,fixedsize=true,width=0.5,label="1",fillcolor=white]
  }

  s_0_1 -> s_1_1
  s_0_0 -> s_2_0
  s_2_1 -> s_3_1
  s_1_0 -> s_3_0
}

我希望能够在子图内强制排序,以便每个子图的节点按升序显示(每个簇都应该放置节点(0,1),而不是(1,0))。据我了解,rankdir是我第一个尝试的方式,但它不支持子图,那么有没有适当的方法来实现这一点呢?我正在寻找一种解决方案,可以给我一个相似的布局(然后包括更多交叉的箭头),并且可扩展性好,因为实际上的图形将会非常大。
2个回答

3
原来这个问题可以通过在图形内部添加看不见的边缘并强制在相同级别内进行解决,如下所示:

subgraph cluster_1 {
    <b>{rank=same; s_0_0 s_0_1}
    s_0_0 -> s_0_1 [style=invis]</b>
    s_0_0 [shape=circle,style=filled,fixedsize=true,width=0.5,label="0",fillcolor=yellowgreen]
    s_0_1 [shape=circle,style=filled,fixedsize=true,width=0.5,label="1",fillcolor=yellowgreen]
}

使用了两个答案,但无法重新对齐节点,因为图中的连接似乎会重新排列顺序。 - Vasiliy
对我来说非常好用!即使有多个节点也是如此。谢谢! - mwiegboldt
1
在某些情况下,使用此解决方案连接不同集群中的节点可能会再次改变排序。您还可以在图形上设置 remincross=false 以防止发生这种情况。 - mwiegboldt

1
如果节点数超过2个,我们需要改变解决方案。
subgraph cluster1 {
{
    HL_1_n HL_1_1 HL_1_2 HL_1_3 HL_1_m
}
HL_1_1   [label="Hidden Layer 1 Node 1" color=3]
HL_1_2   [label="Hidden Layer 1 Node 2" color=3]
HL_1_3   [label="Hidden Layer 1 Node 3" color=3]
HL_1_m   [label="Hidden Layer 1 Node ..." color=3]
HL_1_n   [label="Hidden Layer 1 Node H_1" color=3]
label = "Hidden Layer"
}

看起来顺序已经确定,所以我们只需要改变节点的位置来适应输出。该解决方案不使用边约束和排名。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接