Population equilibrium distributes residents fairly across geographic districts. A district is balanced when its total population falls between an acceptable lower bound and upper bound around the target average. section 8.8
A districting solution evaluates equilibrium by checking whether each district is:
- Overpopulated when its total exceeds the upper bound. section 8.8
- Underpopulated when its total falls below the lower bound. section 8.8
- Appropriately sized when its total remains within both bounds. section 8.8
- Optimal when the objective counts zero overpopulated or underpopulated districts. section 8.8
East Toronto districting
A genetic algorithm groups 16 East Toronto neighborhoods into three districts using population data, adjacency relationships, a margin of 6,000, and constraints for nonempty and contiguous districts. The resulting groups satisfy the population-balance objective. section 8.8
Listing 8.6 Solving a political districting problem using GA
import geopandas as gpd import pandas as pd import folium data_url="https://raw.githubusercontent.com/Optimization-Algorithms-Book/ #1 Code-Listings/main/Appendix%20B/data/PoliticalDistricting/" toronto = gpd.read_file(data_url+"toronto.geojson") #2 neighborhoods = pd.read_csv(data_url+"Toronto_Neighborhoods.csv") #3 range_limit = 16 #4 toronto_sample = toronto.tail(range_limit) #4 values = neighborhoods.tail(range_limit) #4 values = values.join(toronto_sample["cartodb_id"]) #4
Use the implementation listing to inspect preprocessing, population extraction, adjacency construction, genetic-algorithm parameters, and optimization. section 8.8
