liveBook · Manning

Admissible heuristic

As explained in Classic Computer Science Problems in Swift: Essential techniques for practicing programmers

An admissible heuristic is a heuristic that never overestimates the cost of reaching the goal.

An admissible heuristic estimates the remaining cost to a goal without ever overestimating it. A* uses that estimate, h(n), alongside the cost already incurred, g(n), to explore the frontier state with the lowest f(n) = g(n) + h(n). With an admissible heuristic, the path A* finds is optimal. section 2.2

A four-direction maze

When movement has no diagonals, Manhattan distance adds the row and column distances to the goal. Walls may force a longer route, but cannot make that distance an overestimate. section 2.2

func manhattanDistance(ml: MazeLocation) -> Float {
    let xdist = abs(ml.col - goal.col)
    let ydist = abs(ml.row - goal.row)
    return Float(xdist + ydist)
}

This Swift function computes the Manhattan-distance estimate from a maze location to the goal. section 2.2

How Classic Computer Science Problems in Swift: Essential techniques for practicing programmers covers it

How deep it goes
Defines the no-overestimation rule and implements distance estimates, but defers a proof of optimality.
Examples
Uses a four-direction grid maze and Swift functions for Euclidean and Manhattan distance.
What it assumes
Assumes basic Swift functions and grid coordinates; introduces search costs and heuristic estimates in the maze example.
What you can do after
Apply it via A* search by supplying a distance heuristic that does not overestimate remaining maze cost.
How it connects
Connects A* search, cost functions, priority queues, breadth-first search, Euclidean distance, and Manhattan distance.

Also explained in

Compare how 3 books explain admissible heuristic →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Classic Computer Science Problems in Swift: Essential techniques for practicing programmers. The section links point to the parts of the book it draws on.