python-igraph只有在属性对应条件

时间:2018-03-06 12:58:22

标签: python igraph

我的图是从db查询构造的,其中结果包含以下列:

source, target, weight, param

图形构造如下:

graph = igraph.Graph.DictList(vertices=None, edges=result, edge_foreign_keys=('source', 'target'))

使用

我可以找到没有问题的最短路径
dist = graph.shortest_paths_dijkstra(source='5501362',  target='5514175', weights='weight')

我也可以列出构成我的路径的所有节点

path = graph.get_shortest_paths('5501362',  to='5514175', weights='weight')

但是我必须添加一个条件,我只选择对应于param = 10

的边

如何将此条件添加到我的最短路径查询中?

修改: 以下是我使用的代码:

most = time.time()
with pyodbc.connect(connstr) as db:
    cr = db.cursor()
    rows = cr.execute(_sql).fetchall()
    db_cols = [column[0] for column in cr.description]

    result = []
    for row in rows:
        result.append(dict(zip(db_cols, row)))

print(f"DB query time: {time.time()-most}")
most = time.time()
graph = igraph.Graph.DictList(vertices=None, edges=result, edge_foreign_keys=('source', 'target'))
print(f"graph construction time: {time.time()-most}")
most = time.time()
dist = graph.shortest_paths_dijkstra(source='5501362',  target='5514175', weights='weight')
print(dist)
print(f"shortest_paths_dijkstra time: {time.time()-most}")
most = time.time()
path = graph.get_shortest_paths('5501362',  to='5514175', weights='weight')
print(f"get_shortest_paths time: {time.time()-most}")

0 个答案:

没有答案