MCPcopy Index your code
hub / github.com/clips/pattern / partition

Function partition

pattern/graph/__init__.py:982–997  ·  view source on GitHub ↗

Returns a list of unconnected subgraphs.

(graph)

Source from the content-addressed store, hash-verified

980 return list(set(a) - set(b))
981
982def 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

Callers 1

splitMethod · 0.85

Calls 8

lenFunction · 0.85
intersectionFunction · 0.70
unionFunction · 0.70
appendMethod · 0.45
fromkeysMethod · 0.45
flattenMethod · 0.45
copyMethod · 0.45
sortMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…