From 04ff4f9e8454f5a2216ac6a1c7309dae481ac067 Mon Sep 17 00:00:00 2001 From: Matt Karrmann <47995755+mkarrmann@users.noreply.github.com> Date: Fri, 28 Apr 2023 21:18:00 -0500 Subject: [PATCH] Use node_repeats in _bipartitions_tree_random_all (#406) --- gerrychain/tree.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/gerrychain/tree.py b/gerrychain/tree.py index bed78f8f..6c60b2a4 100644 --- a/gerrychain/tree.py +++ b/gerrychain/tree.py @@ -253,18 +253,23 @@ def _bipartition_tree_random_all( spanning_tree = spanning_tree_fn(graph) repeat = True + restarts = 0 attempts = 0 while max_attempts is None or attempts < max_attempts: - spanning_tree = spanning_tree_fn(graph) + if restarts == node_repeats: + spanning_tree = spanning_tree_fn(graph) + restarts = 0 h = PopulatedGraph(spanning_tree, populations, pop_target, epsilon) possible_cuts = balance_edge_fn(h, choice=choice) repeat = repeat_until_valid - attempts += 1 if not (repeat and len(possible_cuts) == 0): return possible_cuts + restarts += 1 + attempts += 1 + raise RuntimeError(f"Could not find a possible cut after {max_attempts} attempts.")