Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does my a-star algorithm expand too many nodes despite having a correct heuristic?

I'm doing an assignment where I have to use a-star to solve a 15-puzzle (in C).

The heuristic function is Manhattan distance (aka taxicab distance).

We are given a sample input/output where the board is solved in 22 moves and after expanding 395 nodes (board states) (i.e we had to look at the children of 395 nodes)

By 'correct' heuristic I mean my function is the same as the one used to produce the sample outputs and produces the correct distance.

The problem is my solution expands more than 400 nodes to find the solution (it is optimal 22 moves but a different one).

I noticed the number changes depending on the order I generate the children nodes (move the space tile up,left,down,right or other directions).

There are 24 ways you can move the space tile up,down,left and right to generate the children and I tried all of them but none of them expanded 395 nodes.

Why is this happening?

Terminology:

  • node: each node is a configuration of the 15-puzzle board
  • children: the configurations that you can achieve by moving the space tile up,down,left or right from the current node

PS: I'm using a binary heap for the open list if that matters

Thanks

like image 496
Babak Avatar asked Oct 22 '11 12:10

Babak


1 Answers

Mmmh... In ideal case the A* does not depend on the order you generate the children. Unfortunately if you have in "queue" two or more nodes with the same distance-plus-cost heuristic value, the algorithm may chose "randomly" one of these nodes and find different solution (and explore different search path).

I think that you can try:

  • Check your distance-plus-cost heuristic function. (every action cost 1? You sum the distance of every squares from their right position in the right way?)
  • Check your heap. It returns the right nodes? How many nodes with the same heuristic value you can have in the same step?

This is the only thing that I can tell you with this information. :)

like image 97
Davide Aversa Avatar answered Sep 28 '22 04:09

Davide Aversa