Evolutionary Sport Pools Optimizer
Evolutionary AlgorithmsNumPyOptimizationIn amateur sports leagues, teams are split into regional pools, and each team plays everyone in its pool. A bad split means hours of extra driving every other weekend, something I know well as a volleyball player in Bordeaux (the most isolated city in all of France, as you can see on the map below). So I wrote a small genetic algorithm, in NumPy only, to find pools that minimize the total distance traveled.
How it works
You give the optimizer a list of city names, the number of pools and a population size. GPS coordinates are fetched automatically (with geopy) and turned into a pairwise distance matrix. Each chromosome is an array assigning every city to a pool (with a max of 12 teams per pool), and its fitness is the sum of distances between all teams of the same pool.
At each iteration:
- the population is ranked by total distance;
- the 20 best chromosomes are kept as is (elitism);
- 80 parents are sampled with a probability proportional to their rank;
- each parent is mutated by swapping the pools of a few random pairs of cities (2 to 10 swaps), which keeps pool sizes unchanged.
cities = ['Nantes', 'Toulouse', 'Talence', 'Tours', ...] opt = EvoPoolOpt(cities_list=cities, nb_pools=6, nb_chromosomes=100) opt.optimize(num_iterations=50_000) opt.display_map_pools_configuration(opt.best_chromosome)
Result
The final split forms compact regional groups. The repo includes a notebook reproducing this real use case.