7

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

Babak
  • 582
  • 4
  • 14
  • 1
    @duffymo not AI, just computing II – Babak Oct 22 '11 at 12:51
  • The difference may simply be because their sample solution uses a *slightly* more clever heuristic (e.g. peeking ahead to determine dead ends faster). As long as the differences in expanded nodes are as small as they sound in your description (how much is "more than 400"?) and the solution is still optimal, I wouldn't worry too much about it. –  Oct 22 '11 at 12:54
  • 1
    @delnan I'm sure it's not optimised and it's plain Manhattan distance. One requirement is the program should expand the same number of nodes and it is said that if it's not, it's incorrect. That's why I worry about it. By changing directions of generating the children I could get anywhere from 420 to 670 ish. – Babak Oct 22 '11 at 13:01
  • @delnan sorry I correct myself. It is NOT said that they have to be the same. – Babak Oct 22 '11 at 13:04

1 Answers1

3

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. :)

Davide Aversa
  • 5,628
  • 6
  • 28
  • 40