【问题标题】:Subgraph function from networknx python来自networknx python的子图函数
【发布时间】:2015-10-31 21:51:33
【问题描述】:

我想问是否有人可以帮助我理解这个 python 模块中的子图函数。例如在一些简单的图表上。子图函数在 1400 到 1458 行之间。

https://github.com/networkx/networkx/blob/e73face328281b9afe7eb848887f17d97be1709d/networkx/classes/graph.py#L1400-L1458

【问题讨论】:

  • 你能问一些问题吗?目前尚不清楚您对此做了什么或不了解。你希望用它做什么?你试过了吗?您是否已经创建了一个正在使用的 networkx.Graph 对象?
  • 我想了解该函数的算法以及如何从原始图中获取某些顶点的子图。我想用不同的语言对其进行编码,但没有足够的python知识。
  • 也许您应该将代码复制到gist 或将其粘贴到您的问题中,然后询问代码中的特定行。哪些台词让您感到困惑?
  • 你熟悉什么语言?您不了解如何用您选择的语言实现哪些部分?
  • gist.github.com/anonymous/11d26c0c6db2f798ae8e 我想知道这个具体的代码是如何工作的,以及在计算子图时处理的步骤。我在最后添加了图表示例。

标签: python graph subgraph


【解决方案1】:

这是该函数的一些伪代码。

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)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-12-01
    • 1970-01-01
    • 2020-10-26
    • 2016-12-31
    • 1970-01-01
    • 1970-01-01
    • 2022-08-03
    • 1970-01-01
    相关资源
    最近更新 更多