Skip to content

Commit

Permalink
Merge pull request #416 from cdonnay/recursive-tree-part
Browse files Browse the repository at this point in the history
`MarkovChain` validators and `recursive_tree_part`
  • Loading branch information
peterrrock2 authored Oct 11, 2023
2 parents 1b8430d + 6751a83 commit 4f3e2b8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion gerrychain/chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __init__(
"""
if callable(constraints):
is_valid = constraints
is_valid = Validator([constraints])
else:
is_valid = Validator(constraints)

Expand Down
6 changes: 4 additions & 2 deletions gerrychain/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,11 +374,12 @@ def recursive_tree_part(
for part in parts[:-1]:
min_pop = max(pop_target * (1 - epsilon), pop_target * (1 - epsilon) - debt)
max_pop = min(pop_target * (1 + epsilon), pop_target * (1 + epsilon) - debt)
new_pop_target = (min_pop + max_pop) / 2
nodes = method(
graph.subgraph(remaining_nodes),
pop_col=pop_col,
pop_target=(min_pop + max_pop) / 2,
epsilon=(max_pop - min_pop) / (2 * pop_target),
pop_target=new_pop_target,
epsilon=(max_pop - min_pop) / (2 * new_pop_target),
node_repeats=node_repeats,
)

Expand All @@ -389,6 +390,7 @@ def recursive_tree_part(
for node in nodes:
flips[node] = part
part_pop += graph.nodes[node][pop_col]

debt += part_pop - pop_target
remaining_nodes -= nodes

Expand Down

0 comments on commit 4f3e2b8

Please sign in to comment.