Graphviz .dot node ordering

倾然丶 夕夏残阳落幕 提交于 2019-12-02 17:31:44

Here's how I'd write that graph:

  • First of all, to me this is a graph which goes from top to bottom, not left to right, therefore I removed the rankdir=LR and added rank=same only for nodes 0/1 and nodes 2/3.
  • I removed all the weights
  • Most importantly, I added constraint=false to the edges going against the direction of the graph - the one going from node 4 to node 5, and the one from node 6 to node 3.

Here the source:

digraph G {
    0 [label = "start", shape = none]; 
    node [shape = circle];
    1 [label = "q1"];
    2 [label = "q2"];
    3 [label = "q3"];
    4 [label = "q4"];
    5 [label = "q5"];
    6 [label = "q6", shape = doublecircle];

    {rank = same; 0 -> 1; }
    1 -> 2 [label = "0"];
    {rank = same; 2 -> 3 [label = "ε"]; }
    4 -> 5 [label = "1"];
    edge [label = "ε"];
    3 -> 4;
    5 -> 6;
    5 -> 4 [constraint = false];
    6 -> 3 [constraint = false];
}

And here's the result:

Now if you want to, you could keep rankdir=LR, just take the markup you posted, remove the weights and add constraint=false to the same edges as I did, it works, too.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!