Hill Climbing vs. Simulated Annealing Analysis
Step-by-step comparison of optimization algorithmsConsider the following 4×4 "height" grid where each cell value represents the utility U to be maximized. From any cell, you can move to the four cardinal neighbors: Up, Down, Left, Right (ignore moves that would leave the grid).
Coordinates: $(row, col)$ with $(1,1)$ at the top-left.
| r\c | 1 | 2 | 3 | 4 |
|---|---|---|---|---|
| 1 | (1,1) 3 | (1,2) 4 | (1,3) 5 | (1,4) 2 |
| 2 | (2,1) 6 | (2,2) 7 | (2,3) 8 | (2,4) 1 |
| 3 | (3,1) 5 | (3,2) 9 | (3,3) 4 | (3,4) 3 |
| 4 | (4,1) 2 | (4,2) 3 | (4,3) 10 | (4,4) 12 |
You will compare two optimization algorithms starting from (3,2):
By completing this exercise, you will be able to:
Greedy local optimization
| r\c | 1 | 2 | 3 | 4 |
|---|---|---|---|---|
| 1 | (1,1) 3 | (1,2) 4 | (1,3) 5 | (1,4) 2 |
| 2 | (2,1) 6 |
(2,2)
7 Up |
(2,3) 8 | (2,4) 1 |
| 3 |
(3,1)
5 Left |
(3,2)
9 CURRENT |
(3,3)
4 Right |
(3,4) 3 |
| 4 | (4,1) 2 |
(4,2)
3 Down |
(4,3) 10 | (4,4) 12 |
Hill climbing gets stuck at $(3,2)$ because it's a local maximum. All neighbors have lower utility, so the algorithm cannot make any improving moves, even though the global maximum $(4,4)$ with $U=12$ exists elsewhere in the landscape.
Probabilistic escape from local optima
| r\c | 1 | 2 | 3 | 4 |
|---|---|---|---|---|
| 1 | (1,1) 3 | (1,2) 4 | (1,3) 5 | (1,4) 2 |
| 2 | (2,1) 6 | (2,2) 7 | (2,3) 8 | (2,4) 1 |
| 3 | (3,1) 5 |
(3,2)
9 CURRENT |
(3,3) 4 | (3,4) 3 |
| 4 | (4,1) 2 |
(4,2)
3 PROPOSED |
(4,3) 10 | (4,4) 12 |
| r\c | 1 | 2 | 3 | 4 |
|---|---|---|---|---|
| 1 | (1,1) 3 | (1,2) 4 | (1,3) 5 | (1,4) 2 |
| 2 | (2,1) 6 | (2,2) 7 | (2,3) 8 | (2,4) 1 |
| 3 | (3,1) 5 |
(3,2)
9 PREVIOUS |
(3,3) 4 | (3,4) 3 |
| 4 | (4,1) 2 |
(4,2)
3 CURRENT |
(4,3)
10 PROPOSED |
(4,4) 12 |
| r\c | 1 | 2 | 3 | 4 |
|---|---|---|---|---|
| 1 | (1,1) 3 | (1,2) 4 | (1,3) 5 | (1,4) 2 |
| 2 | (2,1) 6 | (2,2) 7 | (2,3) 8 | (2,4) 1 |
| 3 | (3,1) 5 |
(3,2)
9 START |
(3,3) 4 | (3,4) 3 |
| 4 | (4,1) 2 |
(4,2)
3 STEP 1 |
(4,3)
10 CURRENT |
(4,4)
12 PROPOSED |
| Proposal | Current | Proposed | U_curr | U_new | Δ | T | P(accept) | r | Decision |
|---|---|---|---|---|---|---|---|---|---|
| 1 | (3,2) | (4,2) | 9 | 3 | -6 | 3 | 0.1353 | 0.10 | ACCEPT |
| 2 | (4,2) | (4,3) | 3 | 10 | +7 | 2 | 1.0 | 0.60 | ACCEPT |
| 3 | (4,3) | (4,4) | 10 | 12 | +2 | 1 | 1.0 | 0.50 | ACCEPT |
Simulated annealing successfully escaped the local maximum by accepting the worse move $(3,2) \to (4,2)$ due to the high temperature ($T=3$). This temporary "sacrifice" allowed the algorithm to discover the path to the global maximum $(4,4)$.
Analysis of algorithm behaviors
Why it stopped here:
Why it found the global optimum:
Hill climbing stops at $(3,2)$ because it is a local maximum where all neighbors have lower utility values, making the algorithm unable to move despite the existence of better solutions elsewhere. Simulated annealing successfully escapes this local trap by temporarily accepting a worse move at high temperature (the probabilistic move from $(3,2)$ to $(4,2)$), which then allows it to discover the path leading to the global maximum at $(4,4)$ as the temperature decreases and the search becomes more focused.
Essential concepts and practical implications