1

さまざまな距離の単純な複数出口迷路に A* パス検索アルゴリズムを実装していますが、適切なヒューリスティックを見つけることができず、幅優先検索を実行しているようです。

コストは初期設定で 1 です

私の試みは次のとおりです。

public void search(Node startNode, Node goalNode){
    System.out.println("Search Started");
    boolean found = false;
    boolean noPath = false;

    Queue<Node> open = new PriorityQueue<Node>(10,new Comparator<Node>(){

        @Override
        public int compare(Node t, Node t1) {
            return Double.compare(t.getCost(), t1.getCost());
        }
    });

    visited[startNode.getX()][startNode.getY()] = true;
    order[startNode.getX()][startNode.getY()] = 0;
    startNode.setCost(h(startNode, goalNode));
    open.add(startNode);

    while (found == false && noPath == false) {
        if (open.isEmpty()) {
            noPath = true;

        }else{

             Node current = open.remove();

            if(current.getX() == goalNode.getX() && current.getY() == goalNode.getY()){

                System.out.println("found Node");
                printOrder();
                found = true;
                break;


            }else{
                for (int i = 0; i < 4; i++){
                    Node nextNode = getAction(current.getX(),current.getY());
                    System.out.println("getting node:" + nextNode.getX() + " " + nextNode.getY());
                    int g2 = current.getCost()+cost+h(current, goalNode);
                    System.err.println(g2);
                    nextNode.setCost(g2);

                    if (nextNode.getX() != -1) {
                      count++;
                      visited[nextNode.getX()][nextNode.getY()] = true;
                      order[nextNode.getX()][nextNode.getY()] = count;
                      open.add(nextNode);

                    }
                }    
            }                
        }
    }
}

ヒューリスティック関数

public int h(Node current, Node goal){

    return (goal.getX() - current.getX()) + (goal.getY() - current.getY());

}

助けていただければ幸いです

4

1 に答える 1

1

典型的な迷路 (1 つの出口、1 つのパスのみ、path-width=1) の場合、A* は幅優先よりも有利ではありません。その違いは、ターゲットの空中方向に歩こうとすることに利点があり、以前に移動した距離が重要な戦略ゲームで見られるようなマップでのみ表示されます. 必要に応じて、他のアルゴリズムを見てください。

https://en.wikipedia.org/wiki/Maze_solving_algorithm

于 2012-06-07T09:47:27.280 に答える