We had a related post here on 2021-12-01, “Apportionment Paradoxes—‘Fairness’ Is Impossible”, which described the problem of deciding how many U.S. house of representatives seats shall be assigned to each state based upon their population as prescribed by the U.S. constitution. As I noted in that post, in 1983 two mathematicians proved a theorem showing that any apportionment system which does not violate the quota rule will, when allocating to three or more states, always manifest one or more of the apportionment paradoxes. The fundamental problem, stated as a programmer would, is that they’re trying to store a rational number into an integer variable, and however you try to do it, you’re always going to lose significance.
The problem of drawing districts is far more complex. If you go through the desiderata for district boundaries given in the Quanta article, it’s immediately apparent they are mutually contradictory in a variety of ways. For example, if you draw districts to try to mirror the racial demographics of the state as a whole, votes of small minorities will be diluted by the majority and never affect the result on issues that matter to them or, in tribal terms, elect members of their group. If you draw the boundaries to create “minority majority” districts so that, assuming tribal voting, the composition of the legislature mirrors the racial composition of the state as a whole, then if the minorities vote heavily for one party, those districts will not be “competitive” and effectively one-party rule, and so on. It gets even worse and more contentious when one tries to determine which minorities are entitled to having districts drawn to grant them representation.
This is a problem which not only suffers from a combinatorial explosion if you try to exhaustively seek an optimal solution, it’s one in which the definition of an optimal solution is impossible to achieve even in principle because the criteria contradict one another and furthermore are written in lawyer-speak and interpreted by judges to mean all kinds of different things, so the problem is ill-defined.