mggg / GerryChain

Use MCMC to analyze districting plans and gerrymanders
https://mggg.github.io/GerryChain/
Other
132 stars 74 forks source link

max() over empty list in Gingleator #424

Open AustinLBuchanan opened 4 months ago

AustinLBuchanan commented 4 months ago

In Gingleator, if all districts become majority-minority, then an error occurs on line 144 of reward_partial_dist(). In this case, it tries to take the max( ) over an empty list, and the code breaks. The same issue could arise on line 171 of reward_next_highest_close().

https://github.com/mggg/GerryChain/blob/a83acf55a371e42d2de0574e24569e2808b5e0d4/gerrychain/optimization/gingleator.py#L144

https://github.com/mggg/GerryChain/blob/a83acf55a371e42d2de0574e24569e2808b5e0d4/gerrychain/optimization/gingleator.py#L171

It would be great if GerryChain could terminate gracefully in such circumstances, either terminating the chain early because a global max has been found, or finishing the chain as intended but without returning an exception. Either seems reasonable to me.