NetLogo banner

 Contact Us

 Modeling Commons

 User Manuals:


NetLogo User Community Models

(back to the NetLogo User Community Models)

[screen shot]

If clicking does not initiate a download, try right clicking or control clicking and choosing "Save" or "Download".(The run link is disabled because this model uses external files.)


This model randomly generates district maps for a square state using standard districting rules -- equal populations and contiguous districts. A two-party system is assumed, with blue representing an individual who will vote for the democratic candidate and red representing an individual who will vote for the republican candidate. Election outcomes of each district are calculated using a first-past-the-post voting method and are shown on the square map in the party color. The outcomes are aggregated to display a histogram of the total districts won over many random maps.


The population is randomly distributed based on the number of city-centers. A proportion of the total number of voters is distributed using an exponential distribution. Democrats are clustered more closely around cities, where a larger proportion of republicans are distributed uniformly throughout the square state. This follows from demographic studies that show democrats have a tendency to pack naturally into districts. Cities follow an approximate Zipf’s law, where the population and density of cities diminishes with each city created.

Random individuals in the population are chosen to initialize districts. Districts expand by absorbing neutral neighboring patches and checking for population sizes given an internal threshold of “equal” populations. If districts become noncontiguous through this process, the smaller portion of the district becomes neutral once again and able to be absorbed by another district. If districts become too populous, half of its patches are reset as neutral. This process continues until all districts are within the threshold of equalness.

Then election outcomes are calculated by finding the majority party within each district. If there is a tie, a coin flip is used to decide the outcome (not unlike how actual US election ties have been decided in the past -- Grabar 2012).


Click the Set Population button, then the Create Districts button to generate a random district map and election outcome with the default settings. Continue to click the Create Districts button to add election results to the histogram. When changes are made to the population distribution, the histogram will reset.

The population distribution is determined by the sliders on the left labeled num-voters, num-districts, dem-percentage, and num-cities. The num-voters slider sets the total number of individuals in the population; the num-districts slider sets the number of districts created. Note, together these determine the number of constituents that each elected representative represents. The dem-percentage slider sets the proportion of the population that votes for the democratic candidate, rounded to the nearest whole person. The simulation assumes that the rest of the population votes for the republican candidate. The num-cities slider sets the number of city-centers in the square. This causes proportions of the population to cluster around the city-centers using an exponential probability distribution with a larger effect on democrats than republicans.

The Set Population button creates a random population based on the parameters set above.

The num-maps slider determines the number of maps and election outcomes that the simulation will randomly generate and include on the histogram.

The Create Districts button generates the user-defined number of random district maps, displaying the election outcome of every map created.

The Create Gerrymandered District Maps generates the user-defined number of gerrymandered random district maps by packing and cracking. The number of packed districts is set within the code to be the average of the minimum number needed to win all the districts (theoretically) and the maximum number that could be packed. The rest of the districts are cracked.

The check-specific-proportion button will calculate the percentage of maps created so far with a fixed population that resulted in the number of democratic districts requested.


Notice the number of districts that tend to elect democratic representatives in comparison to the proportion of democrats in the population. Is the proportion of districts won similar to the proportion of democrats in the square state? When is it similar? When is it not?

Notice the geographic sizes of the districts. Are they all roughly the same size? Why or why not?

Generally, compactness is required for districts, but it is not hard-coded into this model. Generate many maps. Do you notice compactness in the districts?

How do the random election outcomes compare to the gerrymandered result? Was the election outcome likely for the randomly generated non-gerrymandered maps?


Try setting the num-cities to zero. This uniformly distributes the population. What happens to the typical election outcome as dem-percentage changes. Is this what you expected?

Generate lots of random district maps with the ‘Create District Maps’ button (like, hundreds). Then, create a gerrymandered district map for the same population distribution. Note the number of Democrat district wins. Click the button ‘check-specific-proportion’ and choose the number of Democratic district wins from the drop-down menu. What does the output in the text box below tell you?

Generate a bunch of gerrymandered maps and non-gerrymandered maps for the same population distribution. How do the two distributions compare? (Be careful to note the bar endpoints -- the bars may be slightly offset.)


Make a gerrymander button to create biased maps that favor Democrats.

Use a snake-type method to wind around the world to collect only Democrats for the packed districts. This will create some interesting noncompact shapes, but what else happens?

Add a compactness measure and report it. Or, make compactness another condition on the districts.

Add in local lines for counties or school districts that must be maintained (or rivers or lakes).

Try to reproduce the results Chen and Rodden saw where Democrats unintentionally packing themselves into districts. Possibly start with parameter tweaks to change the relative densities of the cities to the rural areas.

In general, the code needs to be cleaned up. I’m sure there are lots of redundant and extraneous portions.


I used the Patch Clusters Example with slight modifications in the Netlogo Library to maintain the contiguity requirement.

I also found two related models:

Congressional Redistricting by Luke Elissiry on the NetLogo Modeling Commons (

NetDistrict by Collin Lysford on the Metric Geometry and Gerrymandering Group’s GitHub site (


Thanks to the Metric Geometry and Gerrymandering Group at Tufts University for the wonderful workshop I attended in Madison, WI. The expert witness workshop and sponsored hackathon inspired me to create an agent-based model to explore some of the ideas we discussed.

Bangia, Sachet, Christy Vaughn Graves, Gregory Herschlag, Han Sung Kang, Justin Luo, Jonathan C. Mattingly, and Robert Ravier. 2017. "Redistricting: Drawing the Line." (Apr): 1-44.

Chen, Jowei and Jonathan Rodden. 2013. "Unintentional Gerrymandering: Political Geography and Electoral Bias in Legislatures." Quarterly Journal of Political Science 8 (3) (Jan): 239-269.

Chikina, Maria, Alan Frieze, and Wesley Pegden. 2016. "Assessing Significance in a Markov Chain without Mixing." (Aug).

Grabar, Henry. 2012. "When a State Election can be Literally Determined by a Coin Toss." The Atlantic, Nov.

Liu, Yan Y., Wendy K. Tam Cho, and Shaowen Wang. 2016. "PEAR: A Massively Parallel Evolutionary Computation Approach for Political Redistricting Optimization and Analysis." Swarm and Evolutionary Computation 30 (May): 78-92. doi:10.1016/j.swevo.2016.04.004.

(back to the NetLogo User Community Models)