简体   繁体   English

在图形中查找所有路径,Python

[英]Finding all paths in graph, Python

I have a graph, represented in a way of a dictionary with pairs key|value - A node|Edges to other nodes . 我有一个图,用字典的方式表示, key|value - A node|Edges to other nodes对是一对key|value - A node|Edges to other nodes Example: 例:

{'5': '1 2 3 W', '0': '1 2 3 W', '2': '0 4 5 L', '1': '0 4 5 L', '4': '1 2 3 W', '3': '0 4 5 L'}

( W and L are the marks of the nodes) WL是节点的标记)
What is the best approach to find all the paths WLWL or LWLW ? 找到所有路径WLWLLWLW的最佳方法是什么? (Python 3.+) (Python 3. +)

A "breadth first search" algorithm may be what you are looking for. 您正在寻找“广度优先搜索”算法。 You can find a good explanation and a Python implementation here . 您可以在此处找到很好的解释和Python实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM