Python networkx : edge contraction

与世无争的帅哥 提交于 2019-12-04 05:30:00

How about:

add_node(XYZ)
add_edge(XYZ, A)
for edge incident on (X, Y, Z):
    v = nodes in edge not in (X, Y, Z, A)
    if v:
       remove_edge(edge)
       add_edge(v, XYZ)
for node in (X, Y, Z):
    remove_node(node)
xuanji

Instead of trying to use nx.condensation (which is meant for contracting strongly connected components, not groups of nodes in general) use these functions:

http://networkx.readthedocs.io/en/stable/reference/classes.graph.html#adding-and-removing-nodes-and-edges

to remove all but one of the collapsed nodes and rewire their nodes.

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