Source code for the two interactive grid partitioning tools, hosted on my academic webpage. The purpose of these widgets is to provide an easy interface for constructing examples on small grids for combinatorial questions and as a teaching tool for introducing people to some of the underlying mathematics of computational redistricting. The two versions offer different amount of customization and different metrics that are evaluated on the plans:
- Basic Version The basic version focuses on building partitions by coloring the nodes in a grid graph and measuring how many edges are cut in the resulting partition. Cut edges are edges of the graph whose endpoints belon to different districts. Usually, partitions with a smaller number of cut edges are more visually appealing. The figures below show a partition of the 5x5 grid into 5 equally sized pieces with the cut edges highlighted and then removed.
- Advanced Version The advanced version adds population and partisan data to the nodes which allows for more complex demonstrations. This version also reports some simple measures of partisan imbalance that are used to evaluate real-world districting plans. The figures below show that same districting plan as above but with populations and vote totals overlayed on the nodes of the grid and the table shows the basic statistcs for this combination of population, electoral, and districting data. Can you identify packing, cracking, and malaportionment in this example?
Total Population | 250 |
Ideal District Size | 50.0 |
Number of cut edges | 18 |
Proportion of cut edges | 0.45 |
Maximum Population Deviation | 22.0 |
Maximum Population Deviation % | 44.0 |
Mean-Median | −0.0473 |
Efficiency Gap | −0.188 |
Whole Plan | Votes | Votes % | Seats | Seats % |
Party 1 | 136 | 54.4 | 2 | 40.0 |
Party 2 | 114 | 45.6 | 3 | 60.0 |
District Number | 0 | 1 | 2 | 3 | 4 |
District Populations | 72 | 51 | 62 | 28 | 37 |
Deviation from Ideal | 22.0 | 1.0 | 12.0 | −22.0 | −13.0 |
Deviation from Ideal % | 44.0 | 2.0 | 24.0 | −44.0 | −26.0 |
Party 1 Votes | 42 | 34 | 29 | 13 | 18 |
Party 1 Votes % | 58.3 | 66.7 | 46.8 | 46.4 | 48.6 |
Party 2 Votes | 30 | 17 | 33 | 15 | 19 |
Party 2 Votes % | 41.7 | 33.3 | 53.2 | 53.6 | 51.4 |
- Grid Setup: The first set of inputs controls the dimensions of the grid and the number of colors to use.
- Initial Coloring: The next set controls the choice of initial coloring. Random, stripes, and empty are reasonably self-explanatory. If you select "Input Your Own" the coloring will start with the labels you input in the "Initial Coloring" box, otherwise this is ignored. I put together a nice starting example for the 5x5 to start you off.
- Color Choice: Whenever you change the settings above, a new random list of colors is generated. You can enter your own choices by replacing any of the ones listed in the terminal (particularly if it generated two colors that were too similar) and pressing the enter key. The full list of allowed color names can be found here.
- Changing Assignments: Changing values in the assignments matrix and pushing the submit button will update the colors in the plot and the population and cut edges computations below. Toggling the "Highlight Cuts" box will display the cut edges in red on the graph.
- Changing Populations: Changing values in the population matrix will adjust the number of voters living in each square of the grid. Note that forming population zero districts will crash the program.
- Changing Votes: The values in the votes matrix and represent the proportion of the population in the corresponding node that vote for the first party. Changing these values changes the distribution of voters across the grid and hence which party wins or loses each in each district.
- Exporting Colorings: If you make a coloring you particularly like, you can press the final checkbox to write the labels to the screen. This will allow you to copy this coloring and paste it into the "Your Matrix" box.
- Global Measures
- Total Population is the sum of all of the individual node populations.
- Ideal District Size is the total population divided by the number of districts.
- Number of Cut Edges is the number of edges that connect nodes of different colors.
- Proportion of Cut Edges is the fraction of edges that connect nodes of different colors.
- Population Deviation is the largest difference between the population of a specific district and the ideal population value.
- Votes is the total number of votes for each party.
- Seats is the total number of districts won by each party.
- Mean-Median is a measure of partisan bias equal to the difference between the median and mean of the district vote percentages.
- Efficiency Gap is a measure of partisan bias that divides the difference between the parties respective wasted vote totals by the total number of votes.
- District Measures
- Population is the sum of the populations of all nodes of each color.
- Population Deviation is the difference between the population of thedistrict and the ideal population value.
- Votes is the total number of votes for each party in that district.
- Given a fixed grid and number of colors can you find the coloring with the minimum number of cut edges?
- Using the 5x5 grid with all nodes having population 1 can you construct a set of districts along with some assignment of the votes so that party 1 gets 40% of the votes but no seats?
- Can you find a plan with a 50-50 vote share and a mean-median score less than 1% but with a difference of 2 seats between the parties?
- Can you find a plan with a small efficiency gap and a large mean-median score? How about the other way around?