我是R的新手,我需要以下要求的代码:
有src和trg记录,如1与2,2-3,3-4相匹配.
现在,当我要求系统提供1到4之间的链接时,它应该给我0/p作为1-2-3-4。
当我要求系统给出2到4之间的链接时,它应该以o/p的形式给出2-3-4。
请帮我提一些有价值的建议。
发布于 2018-05-23 09:58:41
只需使用网络
>>> import networkx as nx
>>> G = nx.Graph()
>>> G.add_nodes_from([1, 2, 3, 4])
>>> G.add_edges_from([(1, 2), (2, 3), (3, 4)])
>>> nx.algorithms.shortest_path(G, 1, 4)
[1, 2, 3, 4]https://stackoverflow.com/questions/50484946
复制相似问题