Local Search Exercise

Hill Climbing vs. Simulated Annealing Analysis

Step-by-step comparison of optimization algorithms

Problem Statement

Consider 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.

Utility Grid:
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
Start: (3,2)
U = 9
Local Max
Starting position
Global Max: (4,4)
U = 12
Exercise Overview

You will compare two optimization algorithms starting from (3,2):

  • Part A: Steepest-ascent hill climbing
  • Part B: Simulated annealing with specific parameters
  • Part C: Analysis and comparison
Learning Outcomes

By completing this exercise, you will be able to:

  • Execute hill climbing algorithms step-by-step with neighbor evaluation
  • Apply simulated annealing with temperature schedules and probabilistic acceptance
  • Compare local vs. global optimization and understand escape mechanisms
  • 1. Run steepest-ascent hill climbing from $(3,2)$:
    • On each step, evaluate all in-bounds neighbors
    • Move to the neighbor with strictly highest U (break ties: Up, Right, Down, Left)
    • Stop when no neighbor has strictly higher U than current cell
  • Tasks:
    • List the sequence of visited coordinates with their utilities
    • State the final coordinate and utility
Hill Climbing Solution
1 Initial State: $(3,2)$ with $U = 9$
2 Evaluate all neighbors of $(3,2)$:
Grid Map - Neighbor Evaluation:
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
Current
Neighbors (All Worse)
Global Max
Current
$(3,2)$
U = 9
Up
$(2,2)$
U = 7
7 < 9 ❌
Right
$(3,3)$
U = 4
4 < 9 ❌
Down
$(4,2)$
U = 3
3 < 9 ❌
Left
$(3,1)$
U = 5
5 < 9 ❌
3 Stopping Condition: No neighbor has strictly higher utility than 9
Result: Algorithm stops immediately at the starting position
Hill Climbing Path:
$(3,2): U=9$ - LOCAL MAXIMUM


Final Result: $(3,2)$, $U = 9$
Key Insight

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.

  • 2. Run simulated annealing for exactly 3 proposals starting from $(3,2)$:
    • Objective: Maximize $U$
    • Acceptance rule: If $\Delta = U_{new} - U_{current}$, accept any move with $\Delta \geq 0$; otherwise accept with probability $P(accept) = e^{\Delta/T}$
    • Temperature schedule: $T_1=3$, $T_2=2$, $T_3=1$
    • Proposal sequence: Proposal 1 try Down, Proposal 2 try Right, Proposal 3 try Right
    • Random numbers: $r_1=0.10$, $r_2=0.60$, $r_3=0.50$
Temperature Schedule:
T₁ = 3
T₂ = 2
T₃ = 1
Simulated Annealing Solution
Step-by-Step Simulation:
0 Initial State: $(3,2)$ with $U = 9$
1 Proposal 1: Move Down, T = 3
Grid Map - Proposal 1:
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
Current (U=9)
Proposed (U=3)
T=3: High temp → Accept worse!
Current: $(3,2)$, $U_{current} = 9$
Proposed: $(4,2)$, $U_{new} = 3$
Change: $\Delta = U_{new} - U_{current} = 3 - 9 = -6$

Since $\Delta < 0$, calculate acceptance probability:
$P(accept) = e^{\Delta/T} = e^{-6/3} = e^{-2} \approx 0.1353$

Random number: $r_1 = 0.10$
Decision: $r_1 = 0.10 < 0.1353$ → ACCEPT

New state: $(4,2)$, $U = 3$
2 Proposal 2: Move Right, T = 2
Grid Map - Proposal 2:
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
Current (U=3)
Proposed (U=10)
T=2: Better → Auto accept!
Previous
Current: $(4,2)$, $U_{current} = 3$
Proposed: $(4,3)$, $U_{new} = 10$
Change: $\Delta = U_{new} - U_{current} = 10 - 3 = +7$

Since $\Delta \geq 0$, accept deterministically
→ ACCEPT

New state: $(4,3)$, $U = 10$
3 Proposal 3: Move Right, T = 1
Grid Map - Proposal 3:
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
Current (U=10)
GLOBAL MAX! (U=12)
T=1: Low temp, greedy!
SA Path
Current: $(4,3)$, $U_{current} = 10$
Proposed: $(4,4)$, $U_{new} = 12$
Change: $\Delta = U_{new} - U_{current} = 12 - 10 = +2$

Since $\Delta \geq 0$, accept deterministically
→ ACCEPT

New state: $(4,4)$, $U = 12$ GLOBAL MAXIMUM!
Summary Table:
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 Path:
$(3,2): U=9$ (Start)
$(4,2): U=3$ (Worse, but accepted!)
$(4,3): U=10$ (Better)
$(4,4): U=12$ (Global Maximum!)


Final Result: $(4,4)$, $U = 12$
Key Insight

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)$.

  • 3. In 2-3 sentences, explain why the two methods finished where they did on this landscape.
Comparison Analysis
Hill Climbing Result
$(3,2)$, $U = 9$

Why it stopped here:

  • Greedy algorithm - only accepts improving moves
  • $(3,2)$ is a local maximum
  • All neighbors have lower utility
  • Cannot escape local optima
Simulated Annealing Result
$(4,4)$, $U = 12$

Why it found the global optimum:

  • Probabilistic acceptance of worse moves
  • High temperature allowed escape
  • Temperature cooling guided search
  • Found path to global maximum
Detailed Explanation

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.

Local vs Global Optima
  • Local maximum: $(3,2)$ with $U=9$
  • Global maximum: $(4,4)$ with $U=12$
  • Hill climbing gets trapped at local peak
  • SA can "climb down" to find better peaks
Temperature Effect
  • High T: More random, exploration
  • Low T: More greedy, exploitation
  • Cooling schedule balances both
  • Critical for escape mechanism
Hill Climbing
  • Strategy: Always move to best neighbor
  • Advantage: Fast, simple, deterministic
  • Disadvantage: Gets stuck in local optima
  • Best for: Landscapes with few local maxima
Simulated Annealing
  • Strategy: Probabilistic acceptance with cooling
  • Advantage: Can escape local optima
  • Disadvantage: Slower, requires parameter tuning
  • Best for: Complex landscapes with many peaks
Key Educational Insights
  • Local optima problem: Major limitation of greedy search
  • Temperature metaphor: Controls exploration vs exploitation
  • Probabilistic acceptance: Key mechanism for escape
  • Parameter sensitivity: Temperature schedule affects performance
  • Trade-offs: Speed vs solution quality
  • Problem structure: Algorithm choice depends on landscape
  • Randomization benefits: Sometimes worse moves lead to better solutions
  • Cooling importance: Balance between exploration and convergence
Common Mistakes to Avoid
❌ Calculation Errors:
  • Wrong sign for Δ calculation
  • Incorrect exponential computation
  • Mixing up acceptance probability logic
  • Forgetting temperature in denominator
❌ Conceptual Errors:
  • Confusing maximization vs minimization
  • Not understanding probabilistic acceptance
  • Ignoring temperature effects
  • Misunderstanding local vs global optima
✅ Pro tip: Always verify your Δ calculation and remember that SA accepts improving moves automatically!

Continue Learning