Partitions
A partition is a fancy word for a districting plan. It assigns every node in the graph (e.g. precincts, counties, blocks) with a particular label (e.g., Congressional district). We need an initial partition because it will serve as the "seed" plan for our Markov chain.
Properties
The Partition, once constructed, has the following properties:
| Partition Properties | Description |
|---|---|
num_dists (Int) | Number of districts in the Partition |
num_cut_edges (Int) | Number of cut edges in the Partition |
assignments Array{Int, 1} | An array of length(num_nodes) where assignments[i] is the assignment of node i |
dist_populations (Array{Int, 1} | An array of length(numdistricts) where `distpopulations[i]is the population of districti` |
cut_edges Array{Int, 1} | An array of length(numedges) where `cutedges[i]is 1 if edgei` is a cut edge, and 0 otherwise |
dist_adj SparseMatrixCSC{Int, Int} | An adjacency matrix of size length(numdistricts) x length(numdistricts) where districts i and j are adjacent if dist_adj[i, j] is the number of cut-edges between districts i and j. If the districts are not adjacent, this value is 0 |
dist_nodes BitSet | An array of sets where dist_nodes[i] is the set of all district nodes of district i |
parent Union{Partition, Nothing} | A field that holds the parent of the Partition. This value is Nothing in the first step of the chain when the Partition has no parent |
Partition
GerryChain.PartitionGerryChain.get_district_adj_and_cut_edgesGerryChain.get_district_nodesGerryChain.get_district_populationsGerryChain.update_partition_adjacency
Initializing a Partition
A Partition can be initialized in the following way:
GerryChain.Partition — TypePartition(graph::BaseGraph,
assignment_col::AbstractString)::PartitionPartition represents a partition of the nodes of the graph. It contains plan-specific information that will change each time we change our plan.
Arguments:
- graph: BaseGraph object that has the underlying network structure of the plan.
- assignment_col: the key denoting the district assignment at the node level
API
GerryChain.get_district_adj_and_cut_edges — Methodget_district_adj_and_cut_edges(graph::BaseGraph,
assignments::Array{Int, 1},
num_districts::Int)Returns:
- district_adj: a
num_districtsxnum_districtsmatrix where the elements are the number of cut edges between the districts - cut_edges: an Array of size(num_edges) where i'th element is 1 if edge
iis a cut_edge, 0 otherwise
GerryChain.get_district_nodes — Methodget_district_nodes(assignments::Array{Int, 1},
num_nodes::Int,
num_districts::Int)::Array{Set{Int}, 1}Returns an Array of Sets district_nodes where the nodes of the i'th district will be at district_nodes[i] as a Set.
GerryChain.get_district_populations — Methodget_district_populations(assignments::Array{Int, 1},
populations::Array{Int, 1},
num_nodes::Int,
num_districts::Int)::Array{Int, 1}Returns an Array of populations dist_pops where the population of the i'th district is at dist_pops[i].
GerryChain.update_partition_adjacency — Methodupdate_partition_adjacency(partition::Partition,
graph::BaseGraph)Updates the district adjacency matrix and cut edges to reflect the partition's assignments for each node.