Genetic Algorithm — Knapsack

Evolutionary search for the optimal item selection given a weight limit

Fitness over generations

Generation: 0 | Best value: 0 | Weight: 0/100

Items (selected in green)

Block size ∝ weight, brightness ∝ value/weight ratio
The 0/1 knapsack problem is NP-hard: given items with weights and values, pick a subset fitting in the knapsack (capacity 100) that maximizes total value. Genetic algorithms encode each solution as a binary chromosome (gene=include item). Selection favors fitter individuals; crossover recombines parent solutions; mutation flips random bits. The population evolves toward the global optimum through generations of selection pressure — a direct analogy to natural selection.