Introduction to Local Search Concepts
Understanding optimization through the classic N-Queens problem (n=4)The N-Queens problem is a classic constraint satisfaction and optimization problem. The goal is to place n queens on an n×n chessboard such that no two queens can attack each other.
Click on squares to place or remove queens. Watch how the utility function changes!
A utility function (or objective function) measures how "good" a particular state is. In the N-Queens problem, we can define utility in several ways:
Utility = 0 represents the optimal state (no conflicts).
Negative values represent penalty for each conflict.
This formulation clearly shows that any conflict is worse than none.
Here are different board states and their corresponding utility values:
Each state is represented as (r₀, r₁, r₂, r₃) where rᵢ is the row position of the queen in column i. This compact representation makes it easy to evaluate and modify states.
Each possible arrangement of queens represents a state. The state space contains all possible configurations.
The utility function creates a landscape where we search for peaks (high utility states).
Local search algorithms might get stuck in local maxima instead of finding the global optimum.
Small changes to the current state (moving one queen) define the neighborhood for local search.
Now that you understand the N-Queens problem and utility functions, you're ready to explore local search algorithms like Hill Climbing, Simulated Annealing, and Genetic Algorithms that can solve this problem efficiently.