networkclustering.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:eTraGo 作者: openego 项目源码 文件源码
def shortest_path(paths, graph):
    """ Finding minimum path lengths between sources and targets pairs defined
    in paths.

    Parameters
    ----------
    ways : list
        List of tuples containing a source and target node
    graph : :class:`networkx.classes.multigraph.MultiGraph
        Graph representation of an electrical grid.

    Returns
    -------
    df : pd.DataFrame
        DataFrame holding source and target node and the minimum path length.

    """

    idxnames = ['source', 'target']
    idx = pd.MultiIndex.from_tuples(paths, names=idxnames)
    df = pd.DataFrame(index=idx, columns=['path_length'])
    df.sort_index(inplace=True)

    for s, t in paths:

        try:
            df.loc[(s, t), 'path_length'] = \
                nx.dijkstra_path_length(graph, s, t)

        except NetworkXNoPath:
            continue

    return df
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号