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


Python Topology.node[v]['depth']方法代码示例

本文整理汇总了Python中fnss.topologies.topology.Topology.node[v]['depth']方法的典型用法代码示例。如果您正苦于以下问题:Python Topology.node[v]['depth']方法的具体用法?Python Topology.node[v]['depth']怎么用?Python Topology.node[v]['depth']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在fnss.topologies.topology.Topology的用法示例。


在下文中一共展示了Topology.node[v]['depth']方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: k_ary_tree_topology

# 需要导入模块: from fnss.topologies.topology import Topology [as 别名]
# 或者: from fnss.topologies.topology.Topology import node[v]['depth'] [as 别名]
def k_ary_tree_topology(k, h):
    """
    Return a balanced k-ary tree topology of with depth h
    
    Each node has two attributes:
     * type: which can either be *root*, *intermediate* or *leaf*
     * depth:math:`(0, h)` the height of the node in the tree, where 0 is the
       root and h are leaves.
    
    Parameters
    ----------
    k : int
        The branching factor of the tree
    h : int 
        The height or depth of the tree

    Returns
    -------
    topology : A Topology object
    """
    if not isinstance(k, int) or not isinstance(h, int):
        raise TypeError('k and h arguments must be of int type')
    if k <= 1:
        raise ValueError("Invalid k parameter. It should be > 1")
    if h < 1:
        raise ValueError("Invalid h parameter. It should be >=1")
    G = Topology(nx.balanced_tree(k, h))
    G.name = "k_ary_tree_topology(%d,%d)" % (k, h)
    G.graph['type'] = 'tree'
    G.graph['k'] = k
    G.graph['h'] = h
    G.node[0]['type'] = 'root'
    G.node[0]['depth'] = 0
    # Iterate through the tree to assign labels to nodes
    v = 1
    for depth in range(1, h + 1):
        for _ in range(k**depth):
            G.node[v]['depth'] = depth
            if depth == h:
                G.node[v]['type'] = 'leaf'
            else:
                G.node[v]['type'] = 'intermediate'
            v += 1                   
    return G
开发者ID:ccascone,项目名称:fnss,代码行数:46,代码来源:simplemodels.py


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