Cliques in python

不问归期 提交于 2019-12-05 15:54:47

I think the trickiest problem here is dealing with shared edges. You don't want to search for cliques each time you remove an edge, and yet you need to remember which edges you've already removed.

Looking at the documentation, we find that the find_cliques function is a generator.

This implementation is a generator of lists each of which contains the members of a maximal clique

Does this mean that you can generate a clique, remove an edge, and then generate the next clique, and our generator will know that we've removed an edge?

Answering this question with another question: why not just break out of the generator each time you break down a clique?

edge_removed = True
while edge_removed:
    edge_removed = False
    for clique in nx.find_cliques(GC):
        if len (clique)>=3:
            GC.remove_edge(clique[0], clique[1])
            edge_removed = True
            break # Gotta restart the generator now...

You have to keep in mind that ANYTHING you do with cliques has the potential to be very resource-consuming, since even simply detecting a clique in a graph is NP-complete.

if len(clique)==3:
    GC.remove_edge(*clique[0:2])

or (equivalent)

if len(clique)==3:
    GC.remove_edge(clique[0], clique[1])

but i may be missing something important because that seems obvious and i'm no expert - i just read the networkx docs (which say that a clique is a list of nodes, and that remove_edge takes two nodes).

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