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


Python DiGraph.selfloop_edges方法代码示例

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


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

示例1: build_graph

# 需要导入模块: from networkx import DiGraph [as 别名]
# 或者: from networkx.DiGraph import selfloop_edges [as 别名]
 def build_graph(self):
     new_graph = DiGraph()
     # Rebuild the graph from the LSDB
     for lsa in chain(self.routers.values(),
                      self.networks.values(),
                      self.ext_networks.values()):
         lsa.apply(new_graph, self)
     # Contract all IPs to their respective router-id
     for lsa in self.routers.values():
         lsa.contract_graph(new_graph, self.router_private_address.get(
             lsa.routerid, []))
     # Figure out the controllers layout
     base_net = ip_network(CFG.get(DEFAULTSECT, 'base_net'))
     controller_prefix = CFG.getint(DEFAULTSECT, 'controller_prefixlen')
     # Group by controller and log them
     for ip in new_graph.nodes_iter():
         addr = ip_address(ip)
         if addr in base_net:
             """1. Compute address diff to remove base_net
                2. Right shift to remove host bits
                3. Mask with controller mask
             """
             id = (((int(addr) - int(base_net.network_address)) >>
                    base_net.max_prefixlen - controller_prefix) &
                   ((1 << controller_prefix) - 1))
             self.controllers[id].append(ip)
     # Contract them on the graph
     for id, ips in self.controllers.iteritems():
         contract_graph(new_graph, ips, 'C_%s' % id)
     # Remove generated self loops
     new_graph.remove_edges_from(new_graph.selfloop_edges())
     self.apply_secondary_addresses(new_graph)
     return new_graph
开发者ID:jaepark,项目名称:FibbingNode,代码行数:35,代码来源:lsdb.py


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