Search code examples
searchartificial-intelligencea-starheuristics

A* and Manhattan distance cost


Hello this semester we started a course for AI and we have a project, to calculate the best route to reach a target at a NxN board. This board can also randomnly contain obstacles that we cant pass through them and also we can move only vertically and horizontally. The cost of each vertical move is 1.0 and the cost of horizontal move is 0.5. We are asked to calculate it with the A* algorithm using the manhattan heuristic method.

My question is: When we are calculating the manhattan distance (i know that u have to add the horizontal and vertical "squares" until you reach the target) do we have to add the cost to each "square" ( 0.5 or 1.0) ?. Or Manhattan distance just counts the "squares" you need to reach the target?


Solution

  • You need to use the distance of your problem, i.e. 1 and 0.5 in your case.

    When using A*, the distance from the start to the current node will be a sum of 1s and 0.5s along the real path to that point, and the estimate remaining distance to the end will be a sum of 1s and 0.5s along a 'perfect path', i.e. with no obstacles.

    I hope that answers your question.