Returns a list of unconnected subgraphs.
(graph)
| 980 | return list(set(a) - set(b)) |
| 981 | |
| 982 | def partition(graph): |
| 983 | """ Returns a list of unconnected subgraphs. |
| 984 | """ |
| 985 | # Creates clusters of nodes and directly connected nodes. |
| 986 | # Iteratively merges two clusters if they overlap. |
| 987 | g = [] |
| 988 | for n in graph.nodes: |
| 989 | g.append(dict.fromkeys((n.id for n in n.flatten()), True)) |
| 990 | for i in reversed(range(len(g))): |
| 991 | for j in reversed(range(i+1, len(g))): |
| 992 | if g[i] and g[j] and len(intersection(g[i], g[j])) > 0: |
| 993 | g[i] = union(g[i], g[j]) |
| 994 | g[j] = [] |
| 995 | g = [graph.copy(nodes=[graph[id] for id in n]) for n in g if n] |
| 996 | g.sort(lambda a, b: len(b) - len(a)) |
| 997 | return g |
| 998 | |
| 999 | #--- GRAPH THEORY | CLIQUE ------------------------------------------------------------------------- |
| 1000 |
no test coverage detected
searching dependent graphs…