graphviz - compare graphic trees

旧城冷巷雨未停 提交于 2019-12-08 08:07:56

问题


I have to do a job with graphviz. I need to visualize the graphic representation of several trees, but in any case I have to compare two tree to see their differences: something like this, I have tree A and tree B. After create their representation and compare them I need to see only the nodes that don't have in common. Someone told me to use EMF Compare but unfortunately I don't know how to make this plugin accept the extension of graphviz.

Any advice or any other possible solution to face this job?

Regards.


回答1:


Given two .dot files, a1.dot:

digraph g1 {
    A -> B -> D -> E
    A -> C -> E
    }

... and a2.dot:

digraph g2 {
    A -> B -> F -> E
    A -> C -> F
    }

... you can find the nodes that are different between them as follows:

$ dot -Tplain a1.dot | sed -ne 's/^node \([^ ]\+\).*$/\1/p' | sort >a1.nodes
$ dot -Tplain a2.dot | sed -ne 's/^node \([^ ]\+\).*$/\1/p' | sort >a2.nodes
$ diff a1.nodes a2.nodes
4d3
< D
5a5
> F

I'm using sed to strip the list of node names for each .dot file out of the plain output from dot, sorting the nodes into order and then using diff to find the differences. This approach doesn't present the differences graphically, but that is a tricky thing to do at the best of times.



来源:https://stackoverflow.com/questions/16655065/graphviz-compare-graphic-trees

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!