jeudi 26 avril 2018

C++ standard doesn t provide a hash for this type.

I try to implement a* algorithm for grids with unordered_map, I have my own priority queue(whitch)works fine. The problem is that when i run the program i get this error: C++ standard doesn t provide a hash for this type.
Can A* be implemented with other structures? Or how can i fix this?

    int main()
    {
        std::ifstream file("Labirint.txt");
        char **labirint;
        int nr_linii, nr_coloane;
        file >> nr_linii >> nr_coloane;
        locatie soricel;
        locatie branza;
        file >> soricel.x >> soricel.y;
        file >> branza.x >> branza.y;

        int deplasare_linie[] = { 0,0,-1,1 };
        int deplasare_coloana[] = { -1,1,0,0 };

        labirint = new char*[nr_linii];
        for (int i = 0; i < nr_linii; ++i)
            labirint[i] = new char[nr_coloane];

        for (int i = 0; i < nr_linii; i++)
            for (int j = 0; j < nr_coloane; ++j)
                file >> labirint[i][j];

        square_nod start,goal;
        start.pozitie = soricel;
        start.prioritate = 0;
        goal.pozitie = branza;

        PriorityQueue frontier;
        frontier.Insert(start);

        std::unordered_map<square_nod, int> came_from;
        std::unordered_map<square_nod, int> cost_so_far;

        cost_so_far.insert(std::make_pair(start, 0));

        while (!frontier.isEmpty())
        {
            square_nod current = frontier.minElement();
            frontier.extractMin();
            if (current == goal)
            {
                break;
            }

            for (int i = 0; i < 4; i++)
            {
                square_nod next;
                next.pozitie.x = current.pozitie.x + deplasare_linie[i];
                next.pozitie.y = current.pozitie.y + deplasare_coloana[i];
                int new_cost = cost_so_far[current] + 1;

                auto gasit = cost_so_far.find(next);
                if (gasit == cost_so_far.end() || new_cost < cost_so_far[next])
                {
                    cost_so_far[next] = new_cost;
                    int priority = new_cost + city_block_distance(goal, next);
                    next.prioritate = priority;
                    frontier.Insert(next);
                    came_from[next] = current.prioritate;
                }
            }
        }
    }

Aucun commentaire:

Enregistrer un commentaire