gpt4 book ai didi

graph - 如何使 graphviz 重复图中的节点以创建树状图像?

转载 作者:行者123 更新时间:2023-12-02 03:53:05 27 4
gpt4 key购买 nike

我在 graphviz 上有以下图表:

Original graph with converging paths

如何使 graphviz 重复图中的节点,以便获得像这样的树状图像:

Derived tree with repeated labels

最佳答案

我认为您不能在 graphviz 中对图形进行这种修改。你应该给 graphviz 提供一个不同的图,具有你想要的结构。该图可以通过如下过程(伪代码)获得:

function visit(path: a list of nodes):
let n be the last node on the path
for every child c of n:
write (a copy of) c to output
if c is not in path:
visit(path + [c])
write root to output
visit([root])

除了此列表path,您还可以在递归调用之前将节点标记为visited,并在调用之后删除该标志:

function visit(n: a node):
mark n as visited
for every child c of n:
write (a copy of) c to output
if c is not marked as visited:
visit(c)
mark n as not visited
write root to output
visit(root)

关于graph - 如何使 graphviz 重复图中的节点以创建树状图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13703207/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com