def findAllPaths(self, max_paths=10, sort=True, debug=False):
""" Find all paths through DAG to End
Params:
max_paths (int :default:=10): Number of paths to find
If this is > 1000, all paths will be found
sort (bool) : If True (default), sort paths
in ascending order of length
"""
if self.roots:
self.lockStart()
# shortest_simple_paths is slow for >1000 paths
if max_paths <= 1000:
return list(six.moves.map(lambda x: x[1:-1], \
islice(nx.shortest_simple_paths(self.G,
self.start,
self.end),
max_paths)))
else: # Fall back to all_simple_paths
ps = list(six.moves.map(lambda x: x[1:-1], \
nx.all_simple_paths(self.G, self.start, self.end)))
# If we do not intend to display paths, no need to sort them
if sort:
ps.sort(key=lambda x: len(x))
return ps
SanskritLexicalAnalyzer.py 文件源码
python
阅读 27
收藏 0
点赞 0
评论 0
评论列表
文章目录