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


Python Topology.node[m1+m2-1]['type']方法代码示例

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


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

示例1: dumbbell_topology

# 需要导入模块: from fnss.topologies.topology import Topology [as 别名]
# 或者: from fnss.topologies.topology.Topology import node[m1+m2-1]['type'] [as 别名]
def dumbbell_topology(m1, m2):
    """
    Return a dumbbell topology consisting of two star topologies
    connected by a path.

    More precisely, two star graphs :math:`K_{m1}` form the left and right
    bells, and are connected by a path :math:`P_{m2}`.

    The :math:`2*m1+m2`  nodes are numbered as follows.
     * :math:`0,...,m1-1` for the left barbell,
     * :math:`m1,...,m1+m2-1` for the path,
     * :math:`m1+m2,...,2*m1+m2-1` for the right barbell.

    The 3 subgraphs are joined via the edges :math:`(m1-1,m1)` and
    :math:`(m1+m2-1,m1+m2)`. If m2 = 0, this is merely two star topologies
    joined together.

    Please notice that this dumbbell topology is different from the barbell
    graph generated by networkx's barbell_graph function. That barbell graph
    consists of two complete graphs connected by a path. This consists of two
    stars whose roots are connected by a path. This dumbbell topology is
    particularly useful for simulating transport layer protocols.

    All nodes and edges of this topology have an attribute *type* which can be
    either *right bell*, *core* or *left_bell*

    Parameters
    ----------
    m1 : int
        The number of nodes in each bell
    m2 : int
        The number of nodes in the path

    Returns
    -------
    topology : A Topology object
    """
    if not isinstance(m1, int) or not isinstance(m2, int):
        raise TypeError('m1 and m2 arguments must be of int type')
    if m1 < 2:
        raise ValueError("Invalid graph description, m1 should be >= 2")
    if m2 < 1:
        raise ValueError("Invalid graph description, m2 should be >= 1")

    G = Topology(type='dumbbell')
    G.name = "dumbbell_topology(%d,%d)" % (m1, m2)

    # left bell
    G.add_node(m1)
    for v in range(m1):
        G.add_node(v, type='left_bell')
        G.add_edge(v, m1, type='left_bell')

    # right bell
    for v in range(m1):
        G.add_node(v + m1 + m2, type='right_bell')
        G.add_edge(v + m1 + m2, m1 + m2 - 1, type='right_bell')

    # connecting path
    for v in range(m1, m1 + m2 - 1):
        G.node[v]['type'] = 'core'
        G.add_edge(v, v + 1, type='core')
    G.node[m1 + m2 - 1]['type'] = 'core'

    return G
开发者ID:fnss,项目名称:fnss,代码行数:67,代码来源:simplemodels.py


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