如果可能的话,我需要一种方法来在 O(1) 时间或真正的任何次线性时间内在充满 Node 对象的字典中找到最小值。
这是我需要的示例:
'''
Nodes have 4 attributes:
- stack
- backwards
- forwards
- total_score
'''
dict = {str(Node1.stack): Node1,
str(Node2.stack): Node2, ... } # note that keys are the stacks as strings
key, smallest = min(frontier.items(), key=lambda pair: pair[1].total_score)
( ^^^ something better than this! ^^^ )
Run Code Online (Sandbox Code Playgroud)
上面的最后一行(关键,最小...)是我到目前为止所拥有的。它工作正常,但速度太慢。我在网上读到 min() 函数需要 O(n) 时间。我有很多节点要处理,所以速度更快会很棒。
编辑之前应该提到过,但这是在 A* 算法中运行的 - 前沿动态更新。我需要能够做的操作是:
VSCode 无法导入气流模块。
Python == 3.10.6,
apache-airflow == 2.5.3
Airflow 服务器工作正常,可以创建 DAG,但 pylint 和 pylance 表示无法导入 Airflow。Airflow 是在没有 docker 的情况下配置的。