Optimization and constraint satisfaction
Sometimes we don't need a path, just the best possible configuration: where to place hospitals, how to schedule exams, how to pack delivery trucks. That is optimization.
Local search
Start with some solution and repeatedly move to a better neighboring solution.
- Hill climbing: always take the best neighbor. Simple, but it can stop at a local maximum, a solution better than its neighbors but not the best overall, like climbing the nearest hill instead of the mountain.
- Random restarts: run hill climbing many times from random starting points; keep the best.
- Simulated annealing: sometimes accept a worse move, more often early on (when the "temperature" is high) and rarely later. This lets the search escape local maxima.
Linear programming
When the goal and the limits are all linear (cost = 50 × hours of machine A + 80 × hours of machine B; total hours ≤ 40), linear programming finds the exact optimum efficiently. It runs airline crew scheduling, supply chains and energy grids.
Constraint satisfaction problems (CSPs)
Many problems are about satisfying rules: Sudoku, exam timetables, seating plans.
- Variables: things to decide (each exam's time slot).
- Domains: possible values (Monday morning, Monday afternoon…).
- Constraints: rules (two exams sharing a student can't share a slot).
Solvers use backtracking: assign a value, move on, and undo when a constraint breaks. They speed up dramatically with arc consistency (remove values that can't possibly work before trying them) and smart ordering (fill the most constrained variable first).
Why it still matters
Optimization is everywhere in modern AI too: training a neural network is an optimization problem, searching for the parameter values that minimize error. The idea of following the slope downhill, which you'll meet as gradient descent, is a cousin of hill climbing.
Check your understanding
Hill climbing stops at a solution better than all its neighbors but not the best overall. This is a:
Scheduling exams so no student has two at once is best modeled as a: