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


Python Graph.add_edge方法代码示例

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


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

示例1: add_edge

# 需要导入模块: from networkx.classes.graph import Graph [as 别名]
# 或者: from networkx.classes.graph.Graph import add_edge [as 别名]
 def add_edge(self, u, v=None):  
     if v is None: (u,v)=u  # no v given, assume u is an edge tuple
     if self.has_edge(u,v): return # no parallel edges allowed
     elif u in self and v in self:
         raise NetworkXError("adding edge %s-%s not allowed in tree"%(u,v))
     elif u in self or v in self:
         Graph.add_edge(self,u,v)
         return
     elif len(self.adj)==0: # first leaf
         Graph.add_edge(self,u,v)            
         return
     else:
         raise NetworkXError("adding edge %s-%s not allowed in tree"%(u,v))
开发者ID:conerade67,项目名称:biana,代码行数:15,代码来源:tree.py

示例2: make_nonmultigraph

# 需要导入模块: from networkx.classes.graph import Graph [as 别名]
# 或者: from networkx.classes.graph.Graph import add_edge [as 别名]
def make_nonmultigraph(multigraph):
    """
        Removes duplicate edges. Instead of having multiple edges going from the same source to the same target,
        this function adds one edge with a weight attribute,
        Parameters:
            multigraph: The multi-graph with multi-edges
        Return:
            G: A new graph which is equivalent to the multi-graph.
    """
    G = Graph()
    for node in multigraph.nodes_iter():
        G.add_node(node)
    for edge in multigraph.edges_iter():
        for existing_edge in G.edges_iter():
            if existing_edge[0] == edge[0] and existing_edge[1] == edge[1]: #If the edge is already in the existing edge list...
                G.edge[edge[0]][edge[1]]['weight'] += 1 # the existing edge's weight is incremented
        G.add_edge(edge[0], edge[1], weight=1)
    return G
开发者ID:ArinT,项目名称:dac-network,代码行数:20,代码来源:calculate_author_network_statistics.py


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