来自 networknx python 的子图函数
Subgraph function from networknx python
我想请问是否有人可以帮助我理解这个 python 模块中的子图函数。例如在一些简单的图表上。子图函数在1400行和1458行之间。
这是该函数的一些伪代码。
def get_subgraph(existing_graph, node_ids):
get the nodes that correspond to the node_ids
create a new graph, make sure it is the same type
for each node in the list of chosen nodes:
copy the node to the new graph, retaining its associated data
get a lookup table of edges for the nodes in the new graph
for each node in the new graph:
get its neighbors from the old graph
for each of the neighbors:
if the neighbor is in the new graph:
add the edge to the new graph (from both directions if needed)
我想请问是否有人可以帮助我理解这个 python 模块中的子图函数。例如在一些简单的图表上。子图函数在1400行和1458行之间。
这是该函数的一些伪代码。
def get_subgraph(existing_graph, node_ids):
get the nodes that correspond to the node_ids
create a new graph, make sure it is the same type
for each node in the list of chosen nodes:
copy the node to the new graph, retaining its associated data
get a lookup table of edges for the nodes in the new graph
for each node in the new graph:
get its neighbors from the old graph
for each of the neighbors:
if the neighbor is in the new graph:
add the edge to the new graph (from both directions if needed)