I started to refresh my ai knowledge so i implemented some pathfind algorithms to solve 8-Puzzle.
I was wondering why my implementation of IDA* has a longer path. It should be optimal like A*.
% python puzzle8.py -a idastar -d hard
IDASTAR - RESULT in 161.6099:
1 | 2 | 3
4 | 5 | 6
7 | 8 | N
cost: 0 total_cost: 121
...
nodes 28
% python puzzle8.py -a astar -d hard
Max nodes 665 loops 1085
ASTAR - RESULT in 0.3148:
1 | 2 | 3
4 | 5 | 6
7 | 8 | N
cost: 0 total_cost: 115
...
nodes 24
Code is on gist https://gist.github.com/1629405
Update:
Code is now pointing to a working version.
% python puzzle8.py -a idastar -d hard
IDASTAR - RESULT in 234.4490:
1 | 2 | 3
4 | 5 | 6
7 | 8 | N
...
nodes 24
But i'm still wondering why IDA* takes so much longer under python than A*.
Update 2:
Code is changed prints now visited nodes.
IDASTAR creates 4184368 ASTAR 1748 nodes.
Because your implementation of IDASTAR increments the limit by 10 with each iteration, which only guarantees that your solution will be no more than 9 more than optimal. Change the increment to 1, and you should get an optimal result (but take longer to do so).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With