Graphviz .dot节点排序 [英] Graphviz .dot node ordering

查看:183
本文介绍了Graphviz .dot节点排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建epsilon NFA,以使用规范构造来识别正则表达式.我正在使用子图对正则表达式的各个部分进行分组. *运算符给我特别麻烦,因为dot决定移动节点的顺序.我尝试添加边缘权重以强制使特定边缘变短,以使边缘的顺序保持一致,但这似乎不起作用.

I'm building a epsilon NFA to recognize a regular expression using the canonical construction. I'm using subgraphs to group various parts of the regular expression. The * operator is giving me particular trouble since dot has decided to move the order of the nodes around. I've tried adding edge weights to force particular edges to be short to keep the order of the edges in line but that does not seem to be working.

我想做的是强制将子图中的节点按特定顺序放置,以便将输出图识别为特定类型的(众所周知的)构造.在下面的示例中,我希望边3、4、5和6以此顺序放置,但是点将它们以6、3、4、5的顺序放置.

What I would like to do is force the nodes in a subgraph in to be placed in a particular order so that the output graph is recognizable as a particular type of (well known) construction. In the example below I would like edges 3, 4, 5 and 6 placed in that order, however the dot places them in the order 6, 3, 4, 5. Any pointers appreciated.

请注意,当前的重量参数与重量参数完全没有区别.

Note that the current weight parameter produces no difference than no weight parameter at all.

我有以下内容

digraph G {
    rankdir = LR;
    node [shape = none];
            0 [label = "start"];
    node [shape = circle];
            1 [label = "q1"];
            2 [label = "q2"];
            3 [label = "q3"];
            4 [label = "q4"];
            5 [label = "q5"];
    node [shape = doublecircle];
            6 [label = "q6"];
    subgraph re1 {
            rank = same;
            edge[label = "0"];
            1 -> 2;
    };
    subgraph re2 {
            rank = same;
            edge[label = "ε"];
                    3 -> 4 [weight = 10];
            edge[label = "1"];
                    4 -> 5 [weight = 10];
            edge[label = "ε"];
                    5 -> 6 [weight = 10];
                    5 -> 4 [weight = 1];
                    6 -> 3 [weight = 1];
    };
    edge[color=black];
            0 -> 1
    edge[label = "ε"];
            2 -> 3;
}

推荐答案

这是我编写该图的方式:

Here's how I'd write that graph:

  • 首先,对我来说,这是一个从上到下而不是从左到右的图,因此我删除了rankdir=LR并仅对节点0/1和节点2/3添加了rank=same. /li>
  • 我除去了所有的重量
  • 最重要的是,我在与图的方向相反的边上添加了constraint=false-一个从节点4到节点5,一个从节点6到节点3.
  • 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.

来源:

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];
}

结果如下:

现在,如果需要,您可以保留rankdir=LR,只保留发布的标记,删除权重,然后将constraint=false添加到与我相同的边缘上,就可以了.

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.

这篇关于Graphviz .dot节点排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆