示例#1
0
    def test_has_informative_repr(self):
        def my_function(x):
            return 150

        bound = constraints.LowerBound(my_function, 100)

        assert repr(bound) == "<LowerBound(my_function <= 100)>"
示例#2
0
## ## ## ## ## ## ## ## ## ## ## 
## set up a chain 
## ## ## ## ## ## ## ## ## ## ## 
proposal = partial(recom, pop_col=POP_COL, pop_target=ideal_pop, epsilon=EPS, 
                   node_repeats=1)

# compactness constraint: no higher than than initial partition
compactness_bound = constraints.UpperBound(lambda p: len(p["cut_edges"]), 
                                           len(init_partition["cut_edges"]))

# county splits: no higher than initial partition 
county_splits_bound = compactness_bound = constraints.UpperBound(lambda p: len(p["county_splits"]), 
                                           len(init_partition["county_splits"]))

# vra constraint: no lower than initial partition 
vra_bound = compactness_bound = constraints.LowerBound(lambda p: p["num_vra_districts"], 
                                           init_partition["num_vra_districts"])

## ## ## ## ## ## ## ## ## ## ## 
## Re-com chain and run it!
## ## ## ## ## ## ## ## ## ## ## 
chain = MarkovChain(
        proposal,
        constraints=[
            constraints.within_percent_of_ideal_population(init_partition, EPS),
            compactness_bound,
            county_splits_bound,
            vra_bound],
        accept=accept.always_accept,
        initial_state=init_partition,
        total_steps=ITERS)
示例#3
0
# population calculation
pop = 0

for n in graph.nodes:
    pop = pop + graph.nodes[n][pop_col]

# --- Create random initial partition -------

proposal = partial(recom,
                   pop_col=pop_col,
                   pop_target=pop / num_dist,
                   epsilon=0.05,
                   node_repeats=3)

bvap_con = constraints.LowerBound(
    lambda p: race_con(p["racial_demographics"], 1),
    race_con(racial_vap_ref, 1))
hvap_con = constraints.LowerBound(
    lambda p: race_con(p["racial_demographics"], 2),
    race_con(racial_vap_ref, 2))
avap_con = constraints.LowerBound(
    lambda p: race_con(p["racial_demographics"], 3),
    race_con(racial_vap_ref, 3))
nvap_con = constraints.LowerBound(
    lambda p: race_con(p["racial_demographics"], 4),
    race_con(racial_vap_ref, 4))
pvap_con = constraints.LowerBound(
    lambda p: race_con(p["racial_demographics"], 5),
    race_con(racial_vap_ref, 5))

racial_bound = constraints.Validator(
示例#4
0
    def test_bound_allows_equality(self):
        bound = constraints.LowerBound(lambda x: x, 100)

        assert bound(100) is True
示例#5
0
    def test_passes_values_above_bound(self):
        bound = constraints.LowerBound(lambda x: x, 100)

        assert bound(150) is True
示例#6
0
    def test_fails_values_below_bound(self):
        bound = constraints.LowerBound(lambda x: x, 100)

        assert bound(50) is False