递归搜索networkx图
关于递归(以及与图形库networkx相切)的问题:我有一个有向图,其节点的边具有可以为0或1(有效地边权重)的属性[“值”]。
我希望能够递归地检查节点的邻居,直到邻居的节点未达到某个阈值。例如:
def checkAll(x):
for neighbor in graph.neighbors(x):
if neighbor is bad:
fail
else:
checkAll(neighbor)
#add all good neighbors here? This isn't working!
我在递归方面失败了,基本上,我认为是因为“for”循环的完成方式。我可以寻求帮助吗? (我查看了 这个其他帖子 但似乎不是特别相关?)
谢谢!
A question about recursion (and tangentially the graphing library networkx): I have an directed graph with node that have edges that have an attribute ["value"] that can be 0 or 1 (effectively edge weights).
I want to be able to examine a node's neighbor recursively until a neighbor's node fails a certain threshold. For example:
def checkAll(x):
for neighbor in graph.neighbors(x):
if neighbor is bad:
fail
else:
checkAll(neighbor)
#add all good neighbors here? This isn't working!
I'm failing at recursion, basically, I think because of the way the "for" loop is done. Can I get some help? (I looked at this other SO post but it didn't seem particularly relevant?)
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
免责声明:我对networkx一无所知,但根据我对你的问题的理解,也许这可以帮助:
disclaimer : I don't know anything about networkx, but from my understanding of your problem, maybe this can help: