简体   繁体   English

将 A* 与目标外部图一起使用

[英]Using A* with target ouside graph

My goal is to find the shortest path between A and B but B might be outside of the known graph.我的目标是找到 A 和 B 之间的最短路径,但 B 可能在已知图之外。 Currently my cost function works perfectly and heuristics function is 3D euclidean.目前我的成本 function 工作完美,启发式 function 是 3D 欧几里得。

To solve the problem of target might be outside of the graph, I've tried to exit the algorithm when priority value stopped changing a certain time but that didn't worked.为了解决目标可能在图表之外的问题,我尝试在优先级值停止更改某个时间但没有奏效时退出算法。 The algorithm spitted out a random path.该算法吐出一条随机路径。

The reason why I don't select a node that is closest to the target is that if I select that algorithm will try to reach that point for certain.我不 select 一个最接近目标的节点的原因是,如果我 select 该算法将尝试确定达到该点。 In my application I will rerun the algorithm when new information comes (ie update to the graph that might include the target).在我的应用程序中,当新信息出现时(即更新可能包含目标的图形),我将重新运行算法。

So what I need is to find a path that is closest to target outside graph with least cost.所以我需要的是找到一条最接近目标外部图且成本最低的路径。 I don't expect a code or whatsoever as an answer but any comment on how this kind of problem might be solved is greatly appreciated.我不希望有代码或任何答案作为答案,但非常感谢您对如何解决此类问题的任何评论。

Below, I've added my A* implementation, PriorityQueue is just an wrapper for heapq.下面,我添加了我的 A* 实现,PriorityQueue 只是 heapq 的包装器。

def a_star_search(mesh, start, goal):
    frontier = PriorityQueue()
    frontier.put(start, 0)
    came_from = {}
    cost_so_far = {}
    came_from[start] = None
    cost_so_far[start] = 0

    while not frontier.empty():
        current = frontier.get()

        if current == goal:
            break

        for i, next in enumerate(list(mesh.neighbors(current))):
            new_cost = cost_so_far[current] + mesh.cost(current, next)
            if next not in cost_so_far or new_cost < cost_so_far[next]:
                cost_so_far[next] = new_cost
                priority = new_cost + mesh.heuristic(next, goal) / mesh.unit
                frontier.put(next, priority)
                came_from[next] = current

    return came_from, cost_so_far

Example result when target is inside graph目标在图中时的示例结果目标在图中时的示例结果

What does it even mean to be "close" to something that's not in the graph?与不在图表中的事物“接近”甚至意味着什么? If the target node could appear anywhere, then there's no point in precomputing anything because you'll have to start over after it appears.如果目标节点可能出现在任何地方,那么预先计算任何东西都是没有意义的,因为您必须在它出现后重新开始。 If you know where it will eventually appear, then add it to the graph now and compute your path, then truncate the result at the edge of the (currently) known graph.如果您知道它最终会出现在哪里,那么现在将其添加到图中并计算您的路径,然后在(当前)已知图的边缘截断结果。

Can you just add goal to your graph (connected to every other node, presumably using whatever distance-metric your mesh used)?您可以将goal添加到您的图表(连接到每个其他节点,大概使用您的网格使用的任何距离度量)吗? Or if you don't want to modify the mesh data-structure, you could just loop over list(mesh.neighbors(current))+goal (after updating new_cost = … to handle that situation).或者,如果您不想修改网格数据结构,您可以循环list(mesh.neighbors(current))+goal (在更新new_cost = …以处理这种情况之后)。

Apologies if I've misunderstood something, and this doesn't apply at all…抱歉,如果我误解了什么,这根本不适用……

You can minimize the cost of reaching a node plus the estimated cost of reaching the target from that node.您可以最小化到达节点的成本加上从该节点到达目标的估计成本。 It won't be guaranteed to be optimal once you know the full grid, but depending on your heuristic it should be a reasonable guess.一旦你知道完整的网格,就不能保证它是最优的,但根据你的启发式,它应该是一个合理的猜测。

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

相关问题 将数据帧附加到多处理目标函数之外的列表 - Append dataframes to a list ouside of multiprocessing target function 如何使用Python绘制图形以获取数据集的每个属性和目标属性之间的相关系数 - How to plot a graph for correlation co-efficient between each attributes of a dataset and target attribute using Python 桑基图不显示流出和目标未定义 - Sankey graph not displaying outflow and target undefined 源 ID 和目标 ID 必须是从 0 开始的整数,使用 iGraph 生成网络图时发现类型 [dtype('O'), dtype('O')] 错误 - Source and target IDs must be 0-based integers, found types [dtype('O'), dtype('O')] error when generating a network graph using iGraph 使用编码的目标值 - Using encoded target value 使用 GridSearchCV 进行目标缩放 - target scaling using GridSearchCV 无源和目标顶点的无向加权图的最短路径 - Shortest path for undirected weighted graph without source and target vertices igraph:基于无向图中源/目标的选择边中的意外行为 - igraph: unexpected behavior in select edge based on source/target in an undirected graph 修剪没有到任何目标节点集的路径的图节点 - Prune graph nodes that have no path to any of a set of target nodes 将 pandas dataframe 列转换为具有源和目标的 networkx 图 - Transforming pandas dataframe column to networkx graph with source and target
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM