当前位置: 首页>>代码示例>>Python>>正文


Python UnionFind.make_set方法代码示例

本文整理汇总了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
开发者ID:LorenzoBi,项目名称:algorithm_design,代码行数:11,代码来源:clustering_big.py

示例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]
开发者ID:LorenzoBi,项目名称:algorithm_design,代码行数:16,代码来源:clustering.py

示例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
开发者ID:bryanj17,项目名称:python-automata,代码行数:17,代码来源:DFA.py


注:本文中的UnionFind.UnionFind.make_set方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。