我正在构建一个epsilon NFA,以使用规范构造识别正则表达式。我正在使用子图来对正则表达式的各个部分进行分组。由于dot决定移动节点的顺序,*运算符给了我特别的麻烦。我已经尝试添加边缘权重以强制特定边缘变短以保持边缘的顺序,但这似乎不起作用。
我想要做的是强制子图中的节点按特定顺序放置,以便输出图可以识别为特定类型的(众所周知的)构造。在下面的示例中,我希望边缘3,4,5和6按此顺序放置,但是点将它们按6,3,4,5的顺序放置。任何指针都会被欣赏。
请注意,当前权重参数与没有权重参数完全没有区别。
我有以下
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;
}
答案 0 :(得分:32)
以下是我写这个图表的方法:
rankdir=LR
并仅为节点0/1和节点2添加了rank=same
/ 3。constraint=false
添加到与图形方向相反的边缘 - 从节点4到节点5的边缘,以及从节点6到节点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
添加到与我相同的边缘,它也可以。