Lecture 05: Heuristic Functions and Optimality
A deep dive into heuristic evaluation, admissibility, consistency, dominance, effective branching factor, and generating admissible heuristics from relaxed problems using the 8-puzzle.
In informed search strategies, the search space is navigated using problem-specific knowledge to select nodes for expansion. Rather than searching blindly, an algorithm uses an evaluation function to estimate the cost of reaching the goal through node , expanding the node with the lowest evaluation first.
In algorithms like Greedy Best-First Search and Search, the evaluation function depends directly on a heuristic function :
- : The estimated cost of the cheapest path from state to a goal state.
- Domain-Specific Knowledge: is calculated purely from the description of state using domain-specific rules (e.g., straight-line distance in map routing, or tile distances in puzzle solving).
Conditions for Optimality
For search to guarantee finding the optimal (lowest-cost) solution, its heuristic function must satisfy specific mathematical properties depending on whether search is performed on a Tree or a Graph.
1. Admissibility (Optimistic Heuristics)
An admissible heuristic is one that never overestimates the true cost to reach the goal.
If represents the actual, true cost of the optimal path from node to the goal state:
Because is optimistic, it assumes the goal is closer or cheaper to reach than it actually is.
- Optimality Guarantee: If is admissible, using TREE-SEARCH is guaranteed to return an optimal solution.
- Example: Straight-line distance (Euclidean distance) between two cities on a map is admissible because the shortest path between any two spatial coordinates is a straight line. Physical roads can only bend or curve, making the actual road distance greater than or equal to the straight-line distance .
2. Consistency (Monotonicity)
A heuristic is consistent (or monotonic) if it satisfies a form of the triangle inequality. For every node and every successor node generated by taking any action :
This condition dictates that the estimated cost from to the goal cannot exceed the step cost of moving from to plus the estimated cost from to the goal.
- Monotonic Decreasing: Consistency ensures that the estimated total path cost is non-decreasing along any path.
- Optimality Guarantee: If is consistent, using GRAPH-SEARCH is optimal without needing complex node re-opening logic.
- Relationship to Admissibility: Every consistent heuristic is admissible, but not every admissible heuristic is consistent. If a heuristic is admissible but not consistent, extra bookkeeping (such as Path-Max equation or re-expanding nodes in closed lists) is necessary to ensure optimality in graph search.
Evaluating Heuristics: The 8-Puzzle
The 8-puzzle consists of a 3x3 board with 8 numbered tiles and one blank space. The goal is to reach a target arrangement by sliding adjacent tiles into the blank space.
State-Space Complexity & Parity Constraints
- Average Solution Depth: A typical 8-puzzle instance requires about 22 moves (the shortest solution for the start state above is 26 actions).
- Branching Factor: The blank tile can move in 2, 3, or 4 directions depending on whether it sits in a corner, edge, or center position, giving an average branching factor .
- Tree Search Complexity: A naive tree search to depth 22 explores approximately states.
- Graph Search Complexity: The 8-puzzle board has total tile permutations. However, exactly half of these configurations are unreachable due to parity constraints (inversion counts remaining invariant under valid moves). Thus, graph search reduces the state space to:
Common Admissible Heuristics
- (Misplaced Tiles): The number of tiles that are not in their target goal position.
- Admissibility: Every misplaced tile must move at least once to reach its destination.
- Start State Evaluation: For the start state shown above, all 8 tiles are out of place, so .
- (Manhattan Distance / City Block Distance): The sum of the horizontal and vertical grid distances of each tile from its goal position.
- Admissibility: Assuming no other tiles were blocking the path, a tile requires at least its Manhattan distance in moves.
- Start State Evaluation: Summing individual tile distances for the start state: Notice that (the true optimal cost ).
Step-by-Step Search Execution Example
Below is the search tree generated by using (Misplaced Tiles) on an 8-puzzle instance, expanding nodes by lowest evaluation :
Effect of Heuristic Accuracy: Dominance & Efficiency
Effective Branching Factor ()
One standard metric to evaluate heuristic performance is the Effective Branching Factor ().
If generates total nodes while finding a solution at depth , then is defined as the branching factor that a uniform tree of depth would need to contain nodes:
- Ideal Target: A perfectly accurate heuristic has .
- Numerical Example: If generates nodes to reach a solution at depth , we solve for :
Dominance ()
If two admissible heuristics and satisfy: we say that dominates .
- Search Efficiency: is more informed than .
- Node Expansion Theorem: using will never expand more nodes than using . Every node expanded under will also be expanded under , but will expand additional non-promising nodes that successfully prunes.
Empirical Comparison: AIMA 8-Puzzle Benchmarks
The table below (adapted from AIMA Fig 3.29) shows search performance averaged over 100 random 8-puzzle instances of varying solution depth , comparing Iterative Deepening Search (IDS), , and :
| Depth () | Search Cost: IDS | Search Cost: | Search Cost: | EBF (): IDS | EBF (): | EBF (): |
|---|---|---|---|---|---|---|
| 2 | 10 | 6 | 6 | 2.45 | 1.79 | 1.79 |
| 4 | 112 | 13 | 12 | 2.87 | 1.48 | 1.45 |
| 6 | 680 | 20 | 18 | 2.73 | 1.34 | 1.30 |
| 8 | 6,384 | 39 | 25 | 2.80 | 1.33 | 1.24 |
| 10 | 47,127 | 93 | 39 | 2.79 | 1.38 | 1.22 |
| 12 | 3,644,035 | 227 | 73 | 2.78 | 1.42 | 1.24 |
| 14 | — | 539 | 113 | — | 1.44 | 1.23 |
| 16 | — | 1,301 | 211 | — | 1.45 | 1.25 |
| 18 | — | 3,056 | 363 | — | 1.46 | 1.26 |
| 20 | — | 7,276 | 676 | — | 1.47 | 1.27 |
| 22 | — | 18,094 | 1,219 | — | 1.48 | 1.28 |
| 24 | — | 39,135 | 1,641 | — | 1.48 | 1.26 |
[!IMPORTANT] Key Takeaway: At depth , uninformed IDS expands 3,644,035 nodes, whereas expands only 73 nodes—making over 50,000 times more efficient!
- Computation Overhead Tradeoff: Although strictly dominates , calculating requires slightly more CPU cycles per node. A dominating heuristic is preferred provided its computation time does not outweigh the savings in node expansions.
Generating Admissible Heuristics
Where do good heuristics come from? Designing admissible heuristics requires constructing simplified models of the problem.
1. Relaxed Problems & Super-Graphs
A relaxed problem is created by removing constraints from the original problem definition.
- Super-Graph Property: Removing restrictions adds new edges to the state-space graph, turning it into a super-graph of the original state space.
- Admissibility Theorem: The cost of an optimal solution to a relaxed problem is guaranteed to be an admissible heuristic for the original problem.
Formal Language Example (8-Puzzle)
Suppose the original 8-puzzle movement rule is formally stated as:
"A tile can move from square A to square B if square A is adjacent to square B AND square B is blank."
By removing one or both conditions, we automatically construct three distinct relaxed problems:
- Relaxation (a): "A tile can move from square A to square B if A is adjacent to B." (Ignores whether B is blank yields Manhattan Distance ).
- Relaxation (b): "A tile can move from square A to square B if B is blank." (Ignores adjacency).
- Relaxation (c): "A tile can move from square A to square B." (Ignores both adjacency and blank status yields Misplaced Tiles ).
2. Pattern Databases
Rather than estimating whole-board costs, pattern databases store exact solution costs for disjoint subproblems (e.g., placing only tiles 1, 2, 3, and 4 into their goal positions).
- During search, the exact cost to solve the subproblem is retrieved from a precomputed lookup table.
- Taking the maximum across disjoint pattern databases preserves admissibility while drastically pruning search spaces (e.g., reducing 15-puzzle node expansions by a factor of 1,000+ compared to Manhattan distance alone).
3. Learning from Experience
An agent can learn by solving thousands of random instances offline. Each solved instance generates pairs of (state, true_cost_to_goal). Machine Learning techniques (e.g., deep neural networks, regression trees, or reinforcement learning) are used to approximate dynamically.
Lecture 04.2: A* Search and Extensions
Understanding A* search, admissible heuristics, and advanced variations like Weighted A* and IDA*.
Lecture 06.1: Game Theory and Nash Equilibrium
Introduction to Adversarial Search, Game Theory, Payoff Matrices, Dominant Strategies, Pareto Optimality, and Nash Equilibrium.