graphviz中的节点顺序

Order of nodes in graphviz

我正在处理这张图:

digraph "example.gsn.yaml" {

  ## Elements
  "G1" [shape="box", label=<<B>G1</B><BR align="left"/>Goal 1>];
  "G2" [shape="box", label=<<B>G2</B><BR align="left"/>Goal 2>];
  "G4" [shape="box", label=<<B>G4</B><BR align="left"/>Goal 4>];
  "G3" [shape="box", label=<<B>G3</B><BR align="left"/>Goal 3>];
  "C1" [shape="box", style="rounded", label=<<B>C1</B><BR align="left"/>Context 1>];
  "S1" [shape="parallelogram", label=<<B>S1</B><BR align="left"/>Strategy 1>];
  "A1" [shape="oval", label=<<B>A1</B><BR align="left"/>Argument 1>];
  "A1":e -> "A1":e [headlabel=< <B>A</B> >, labeldistance=2.5, penwidth=0, arrowhead=none];
  "Sn1" [shape="circle", label=<<B>Sn1</B><BR align="left"/>Solution 1>];
  "Sn2" [shape="circle", label=<<B>Sn2</B><BR align="left"/>Solution 2>];
  "J1" [shape="oval", label=<<B>J1</B><BR align="left"/>Justification 1>];
  "J1":e -> "J1":e [headlabel=< <B>J</B> >, labeldistance=2.5, penwidth=0, arrowhead=none];

  ## Relations
  "G1" -> "G2";
  "G1" -> "G3";
  "G1" -> "G4";
  "G2" -> "S1";
  "G4" -> "Sn2";
  "G3" -> "Sn1";
  "G3" -> "C1" [arrowhead=empty];
  {rank = same; "G3"; "C1"; }
  "S1" -> "Sn1";
  "S1" -> "J1" [arrowhead=empty];
  "S1" -> "A1" [arrowhead=empty];
  {rank = same; "A1"; "S1"; }
  {rank = same; "S1"; "J1"; }
}


我想尽量减少交叉点。 我的首选布局是 A1、S1 和 J1 按从左到右的顺序位于同一等级。 但是我不知道该怎么做。

有人可以帮忙吗?提前致谢。

许多“显而易见”的解决方案都不起作用(排序、权重、不可见边缘)。将 A1、J1 和 S1 放在一个集群中就可以了:

digraph "example.gsn.yaml" {
  ## Elements
  "G1" [shape="box", label=<<B>G1</B><BR align="left"/>Goal 1>];
  "G2" [shape="box", label=<<B>G2</B><BR align="left"/>Goal 2>];
  "G4" [shape="box", label=<<B>G4</B><BR align="left"/>Goal 4>];
  "G3" [shape="box", label=<<B>G3</B><BR align="left"/>Goal 3>];
  "C1" [shape="box", style="rounded", label=<<B>C1</B><BR align="left"/>Context 1>];
  "S1" [shape="parallelogram", label=<<B>S1</B><BR align="left"/>Strategy 1>];
  "A1" [shape="oval", label=<<B>A1</B><BR align="left"/>Argument 1>];
  "A1":e -> "A1":e [headlabel=< <B>A</B> >, labeldistance=2.5, penwidth=0, arrowhead=none];
  "Sn1" [shape="circle", label=<<B>Sn1</B><BR align="left"/>Solution 1>];
  "Sn2" [shape="circle", label=<<B>Sn2</B><BR align="left"/>Solution 2>];
  "J1" [shape="oval", label=<<B>J1</B><BR align="left"/>Justification 1>];
  "J1":e -> "J1":e [headlabel=< <B>J</B> >, labeldistance=2.5, penwidth=0, arrowhead=none];

  subgraph clusterg1{
    graph[peripheries=0]  // no box around the cluster
    {rank = same; node[group=g1] edge[style=invis]  "A1" -> "S1" ->  "J1"}
  }

  ## Relations
  "G1" -> "G2";
  "G1" -> "G3";
  "G1" -> "G4";
  "G2" -> "S1";
  "G4" -> "Sn2";
  "G3" -> "Sn1";
  "G3" -> "C1" [arrowhead=empty];
  {rank = same; "G3"; "C1"; }
  "S1" -> "Sn1";
  "S1" -> "J1" [arrowhead=empty];
  "A1" -> "S1" [arrowhead=empty dir=back];
}

p.s。 A1->S1 箭头是否正确?