简体   繁体   English

节点的Python优先级队列

[英]Python Priority Queue for node

So I found the heapq implementation, but that does not seem to work for my purposes. 因此,我找到了heapq实现,但这似乎不适用于我的目的。 I need a priority queue where the priority is given by a function manhattan_distance(node, end_node) that stores the node. 我需要一个优先级队列,其优先级由存储节点的函数manhattan_distance(node,end_node)给出。 Heapq seems to only work for integers and gives no way to store the nodes? Heapq似乎仅适用于整数,却没有办法存储节点?

What is my best option for implementing this without having to write my own class? 无需编写自己的课程,我最好的选择是什么?

Any advice would be greatly appreciated. 任何建议将不胜感激。

Actually I figured it out. 其实我知道了。 I can use PriorityQueue from the Queue class. 我可以使用Queue类中的PriorityQueue。 I didn't realize you could put tuples into it. 我没有意识到你可以把元组放进去。

Sorry! 抱歉!

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

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