Esempio n. 1
0
def three_by_three_grid():
    """Returns a graph that looks like this:
    0 1 2
    3 4 5
    6 7 8
    """
    graph = Graph()
    graph.add_edges_from([
        (0, 1),
        (0, 3),
        (1, 2),
        (1, 4),
        (2, 5),
        (3, 4),
        (3, 6),
        (4, 5),
        (4, 7),
        (5, 8),
        (6, 7),
        (7, 8),
    ])
    return graph
Esempio n. 2
0
from gerrychain import Partition, Graph
import math
from gerrychain.metrics.compactness import compute_polsby_popper, polsby_popper
from gerrychain.updaters import (
    Tally,
    boundary_nodes,
    cut_edges,
    cut_edges_by_part,
    exterior_boundaries,
    interior_boundaries,
    perimeter,
)
from gerrychain.partition.geographic import GeographicPartition

graph = Graph()
graph.add_edges_from([(0, 1), (1, 2), (2, 0)])

AREA_COL = 'area'
PERIM_COL = 'perimeter'

graph.nodes[0][AREA_COL] = 40
graph.nodes[0][PERIM_COL] = 18

graph.nodes[0][AREA_COL] = 120
graph.nodes[0][PERIM_COL] = 120

graph.nodes[0][AREA_COL] = 30
graph.nodes[0][PERIM_COL] = 20

partition = GeographicPartition(graph, {
    0: 0,
Esempio n. 3
0
from gerrychain import Partition, Graph
import math
from gerrychain.metrics.compactness import compute_polsby_popper, polsby_popper

graph = Graph()
graph.add_edges_from([(0, 1), (1, 2), (2, 0)]) # Arbitrary. copied this from Updaters documentation

POP_COL = 'vap'
VRA_POP_COL = 'bvap'
AREA_COL = 'area'
PERIM_COL = 'perimeter'

'''
Fake data here. Node 0 and 2 have enough to qualify alone, but pairing/districting
Node 1 with either can tank it.
'''

graph.nodes[0][POP_COL] = 100
graph.nodes[0][VRA_POP_COL] = 60

graph.nodes[1][POP_COL] = 100
graph.nodes[1][VRA_POP_COL] = 0

graph.nodes[2][POP_COL] = 100
graph.nodes[2][VRA_POP_COL] = 40

def num_vra_districts(partition, pop_col=POP_COL, vra_pop_col=VRA_POP_COL, vra_relative_threshold=0.37):
    # we'll count districts that satisfy the VRA threshold.
    total = 0

    # For each district,...