本文整理汇总了Python中UnionFind.UnionFind.make_set方法的典型用法代码示例。如果您正苦于以下问题:Python UnionFind.make_set方法的具体用法?Python UnionFind.make_set怎么用?Python UnionFind.make_set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnionFind.UnionFind
的用法示例。
在下文中一共展示了UnionFind.make_set方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: read_nodes
# 需要导入模块: from UnionFind import UnionFind [as 别名]
# 或者: from UnionFind.UnionFind import make_set [as 别名]
def read_nodes(filename):
clusters = UnionFind()
all_nodes = []
with open(filename) as inputfile:
next(inputfile)
for line in inputfile:
clusters.make_set(int(line.rstrip().replace(' ', ''), 2))
all_nodes.append(int(line.rstrip().replace(' ', ''), 2))
return clusters, all_nodes
示例2: compute_max_clusters_dist
# 需要导入模块: from UnionFind import UnionFind [as 别名]
# 或者: from UnionFind.UnionFind import make_set [as 别名]
def compute_max_clusters_dist(edges, k):
edges = sorted(edges)
clusters = UnionFind()
for i in range(1, 501):
clusters.make_set(i)
ithEdge = 0
while clusters.number_of_groups != k or len(clusters) != 500:
clusters.union(edges[ithEdge][1], edges[ithEdge][2])
ithEdge += 1
while clusters.find(edges[ithEdge][1]) == clusters.find(edges[ithEdge][2]):
ithEdge += 1
return edges[ithEdge][0]
示例3: f_equivalence_classes
# 需要导入模块: from UnionFind import UnionFind [as 别名]
# 或者: from UnionFind.UnionFind import make_set [as 别名]
def f_equivalence_classes(self):
"""Returns a partition of the states into finite-difference equivalence clases, using
the experimental O(n^2) algorithm."""
sd = symmetric_difference(self, self)
self_pairs = [(x, x) for x in self.states]
fd_equiv_pairs = sd.right_finite_states(self_pairs)
sets = UnionFind()
for state in self.states:
sets.make_set(state)
for (state1, state2) in fd_equiv_pairs:
set1, set2 = sets.find(state1), sets.find(state2)
if set1 != set2:
sets.union(set1, set2)
state_classes = sets.as_lists()
return state_classes