我在graphviz上有以下图表:
如何让 graphviz 重复图中的节点,以便我可以获得这样的树状图像:
我认为您不能在 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)