【问题标题】:A* Algorithm Quickest TimeA* 算法最快时间
【发布时间】:2015-07-03 03:34:26
【问题描述】:

我已经实现了 A* 算法来给出最短距离的路线,但是我正在尝试改变它,以便它可以计算出最快的路线。 使用这个伪代码:

function A*(start,goal)
    closedset := the empty set    // The set of nodes already evaluated.
    openset := {start}    // The set of tentative nodes to be evaluated, initially containing the start node
    came_from := the empty map    // The map of navigated nodes.

    g_score[start] := 0    // Cost from start along best known path.
    // Estimated total cost from start to goal through y.
    f_score[start] := g_score[start] + heuristic_cost_estimate(start, goal)

    while openset is not empty
        current := the node in openset having the lowest f_score[] value
        if current = goal
            return reconstruct_path(came_from, goal)

        remove current from openset
        add current to closedset
        for each neighbor in neighbor_nodes(current)
            if neighbor in closedset
                continue
            tentative_g_score := g_score[current] + dist_between(current,neighbor)

            if neighbor not in openset or tentative_g_score < g_score[neighbor] 
                came_from[neighbor] := current
                g_score[neighbor] := tentative_g_score
                f_score[neighbor] := g_score[neighbor] + heuristic_cost_estimate(neighbor, goal)
                if neighbor not in openset
                    add neighbor to openset

    return failure

我认为计算最快路线的最简单方法是将当前和邻居之间的距离除以该道路的限速:tentative_g_score := g_score[current] + (dist_between(current,neighbor)/neighbor.速度极限) 但是,这并没有在我的算法中给出正确的结果。

谁能指出我正确的方向如何有效地做到这一点?

这是我当前的代码:http://pastebin.com/QWi6AwF9

最快的路线,即从起点到达目的地所需时间最短的路线。

我的启发式函数是这样的

private double heuristic(Vertex goal, Vertex next) 
    {
        return (Math.sqrt(Math.pow((goal.x - next.x), 2) + Math.pow((goal.y - next.y), 2)));
    }

干杯

【问题讨论】:

  • 如果您附加了当前用 Java 实现的解决方案,其他人将能够运行它并帮助您更轻松。
  • 我不愿意这样做,因为这是一项作业,而且我知道我班上的其他学生使用这个网站;因此他们很容易看到我的代码。但是我已经将它上传到 pastebin 并且它有一个到期时间。
  • 您的方法似乎是正确的(如果限速为正数)。它给出的结果有什么不正确的地方?
  • 如果我计算同一条路线要求最短距离,那条路线的时间比要求最快时间时给出的时间短很多。它似乎探索了极少量的节点;比较相同的路线但最短的距离,它的探索量减少了大约 20 倍。
  • 看起来很奇怪的一件事是,您将速度限制作为(neightbour)节点的属性,而实际上它是从当前节点到当前节点的边的属性邻居节点。也许这是问题的一部分。

标签: java algorithm path shortest-path a-star


【解决方案1】:

启发式函数必须是可接受的(也就是说,它不应该高估到目标的距离)。一旦你开始将边的长度除以speedlimit,到目标的实际距离可能小于到它的欧几里得距离(如果speedlimit &gt; 1)。它破坏了算法。如何解决?例如,您可以使用dist / MAX_SPEED_LIMIT 作为启发式函数。

【讨论】:

  • 啊,谢谢,我假设这将是当前节点与目标之间的距离,除以所有边的最大速度限制?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-09-25
  • 1970-01-01
  • 1970-01-01
  • 2012-02-06
  • 2022-11-20
  • 2019-02-26
相关资源
最近更新 更多