Skip to content

Commit 04ff4f9

Browse files
authored
Use node_repeats in _bipartitions_tree_random_all (#406)
1 parent ee00d5d commit 04ff4f9

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

gerrychain/tree.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -253,18 +253,23 @@ def _bipartition_tree_random_all(
253253
spanning_tree = spanning_tree_fn(graph)
254254

255255
repeat = True
256+
restarts = 0
256257
attempts = 0
257258
while max_attempts is None or attempts < max_attempts:
258-
spanning_tree = spanning_tree_fn(graph)
259+
if restarts == node_repeats:
260+
spanning_tree = spanning_tree_fn(graph)
261+
restarts = 0
259262
h = PopulatedGraph(spanning_tree, populations, pop_target, epsilon)
260263
possible_cuts = balance_edge_fn(h, choice=choice)
261264

262265
repeat = repeat_until_valid
263-
attempts += 1
264266

265267
if not (repeat and len(possible_cuts) == 0):
266268
return possible_cuts
267269

270+
restarts += 1
271+
attempts += 1
272+
268273
raise RuntimeError(f"Could not find a possible cut after {max_attempts} attempts.")
269274

270275

0 commit comments

Comments
 (0)