Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想在networkx中对A *使用启发式,但我不知道如何在启发式中访问节点属性(我的启发式需要它们)。如何在启发式函数中访问节点属性?
如果G是你的图,那么key节点的属性n可以通过
G
key
n
G.node[n][key]
如果G不在启发式函数的外部范围内,则要使G启发式函数可以访问,请使用闭包:
def make_heuristic(G): def heuristic(a, b): a_attr, b_attr = [G.node[n][key] for n in (a, b)] ... return heuristic nx.astar_path(G,start,end,make_heuristic(G))