gpt4 book ai didi

Graphviz---随机节点顺序和经过标签的边

转载 作者:行者123 更新时间:2023-12-03 06:30:10 24 4
gpt4 key购买 nike

我有以下点文件:

digraph finite_state_machine {
{
rank=same;
node [shape = doublecircle]; q_5;
node [shape = circle];
q_1 -> q_2 [ label = "." ];
q_1 -> q_2 [ label = "\epsilon" ];
q_2 -> q_1 [ label = "\epsilon" ];
q_2 -> q_3 [ label = "a" ];
q_3 -> q_4 [ label = "^\wedge a" ];
q_3 -> q_4 [ label = "\epsilon" ];
q_4 -> q_3 [ label = "\epsilon" ];
q_4 -> q_5 [ label = "b" ];
}
}

我的印象是节点会按照它们被提及的顺序出现。但顺序对我来说似乎是随机的。我希望顺序是从左到右,按照下标的顺序。另外,边缘穿过标签,我怎样才能避免这种情况?

这是当前图像: current output

最佳答案

Graphviz 确实根据彼此之间的边来布局节点,而不是按照出现的顺序。如果您希望边不影响任何节点的位置,可以通过添加 constraint=false 来实现。

因此,该图:

digraph finite_state_machine {
pad=0.2;
{
rank=same;
node [shape = doublecircle]; q_5;
node [shape = circle];
q_1 -> q_2 [ label = "." ];
q_1 -> q_2 [ label = "\epsilon", constraint=false ];
q_2 -> q_1 [ label = "\epsilon", constraint=false ];
q_2 -> q_3 [ label = "a" ];
q_3 -> q_4 [ label = "^\wedge a" ];
q_3 -> q_4 [ label = "\epsilon", constraint=false ];
q_4 -> q_3 [ label = "\epsilon", constraint=false ];
q_4 -> q_5 [ label = "b" ];
}
}

会给你带来:

graphviz output finite state machine

我必须添加 pad 以免某些标签被切断。

关于Graphviz---随机节点顺序和经过标签的边,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12746224/

24 4 0