本文整理汇总了Python中UnionFind.UnionFind.get_root方法的典型用法代码示例。如果您正苦于以下问题:Python UnionFind.get_root方法的具体用法?Python UnionFind.get_root怎么用?Python UnionFind.get_root使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnionFind.UnionFind
的用法示例。
在下文中一共展示了UnionFind.get_root方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from UnionFind import UnionFind [as 别名]
# 或者: from UnionFind.UnionFind import get_root [as 别名]
class UFGraphBasedSegment:
def __init__(self, size, tau_k, root_dict):
self.uf = UnionFind(size, root_dict)
self.tau_k = tau_k
'''
Merge two components.
@param id1 : component id to merge
@param id2 : component id to merge
@param edge_value : difference value of intertested edge
@return bool : TRUE if merging two components, else FALSE
'''
def merge(self, id1, id2, edge_value):
root_node1 = self.uf.get_root(id1)
root_node2 = self.uf.get_root(id2)
if edge_value < self.mint(root_node1, root_node2):
self.uf.union(id1=id1, id2=id2, edge_value=edge_value)
'''
Calculate the minimum internal difference between two components.
@param id1 : One of two components to calculate minimum internal difference of boundary
@param id2 : One of two components to calculate minimum internal difference of boundary
@param mcl : Merged Component List
@return float : minimum internal difference between two components
'''
def mint(self, r1, r2):
return min(r1.get_min_dif()+self.tau(r1), r2.get_min_dif()+self.tau(r2))
'''
Calculate threashold based on the size of the component.
@param mc : merged component to calculate the threashold
@return float : threashold based on the size of the component
'''
def tau(self, root):
return float(self.tau_k / root.get_size())
'''
Get union find.
@return UnionFind : union find tree
'''
def get_union_find(self):
return self.uf