Gerrymandering - Geospatial optimization to maximize votes in R
I found a number of interesting articles on mathematical analyses of gerrymandering. Hopefully some of these might give you some ideas on detecting / optimising against gerrymander.


Gerrymandering and Legislator Efficiency
Gerrymander and Convexity
Recursive Algorithm with Examples
Mary Solbrig's Automated District Model