本文整理汇总了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