Every 10 years, following the decennial census, states redraw district boundaries to ensure that Congress and state legislatures represent the electorate. This process is prone to political gamesmanship as elected officials draw district lines in ways that protect incumbents or make their party more competitive without consideration of the impact it has on voters. The worst offenses have been found in states where a single party controls the state legislature and can unilaterally push through a partisan map. While states have proposed various independent commissions to lessen partisan fights over the design of these maps, the best solution might be to simply take humans out of the loop, and put an algorithm in charge.

There are relatively few requirements on how states draw district boundaries. At the federal level, the U.S. Constitution requires that districts contain equal populations, and the Voting Rights Act prohibits states from drawing lines that deny minorities the right to elect representatives of their choice. This latter requirement is designed to combat “cracking” — splitting minority voters into small pieces across multiple districts so they have little chance to impact an election — and “packing” — putting as many minority voters as possible into particular districts so that they have less impact elsewhere.

Many states have additional regulations, such as requiring districts to be contiguous, follow existing political boundaries, be reasonably compact and preserve communities of interest (i.e., people with shared social, cultural or economic interests). A few states have also tried to minimize political interference by having the state legislature turn over redistricting authority to an independent commission.

While courts have ruled congressional maps unconstitutional when they have found evidence of racial gerrymandering, they have been less likely to act in purely partisan cases. Given this leeway, multiple states have reshaped districts to achieve party control. For example, in Wisconsin, Democrats won the popular vote in 2012, but only 39 percent of the seats in the state Legislature. And in North Carolina, Republicans won 53 percent of the popular vote in 2016, but 77 percent of the state’s congressional seats.

It is likely that the Supreme Court will address this issue again soon. Earlier this year, a federal court ordered North Carolina lawmakers to redraw the state’s congressional map, ruling that the one proposed by the Republican-controlled Legislature was unconstitutional because it appeared to be designed to significantly hurt the viability of Democratic candidates (the Supreme Court later blocked this order). Similar cases over partisan gerrymandering are pending in Wisconsin and Maryland.

Data-driven analysis can better quantify gerrymandering. While there is no standard metric for measuring gerrymandering, many mathematicians are exploring possible solutions. For example, one technique involves computationally creating more than a billion randomly generated maps and then comparing any proposed map to this database to determine if it is an outlier in terms of partisan impact. Statisticians have served as expert witnesses in many of the cases over partisan gerrymandering, and their analysis can allow states to assess the effectiveness of different policies to address the problem, such as showing that states with independent commissions produce less partisan maps.

States could also try to simply eliminate human bias by using algorithms to design their maps. Algorithms can be designed to optimize features desirable for voting districts, such as compactness, and minimize undesirable characteristics, such as splitting neighborhoods. The idea is not new — it was proposed in the 1960s — but although states have flirted with the possibility, they have never fully embraced the idea. On the contrary, states are more likely to use digital redistricting tools to design highly partisan maps. The problem, of course, was not the algorithms, but those put in charge of using them. This is a lesson states should learn from today.

Given the current level of gerrymandering, it is time to re-evaluate how to engineer a fairer process for redistricting. It should be clear that humans are often the weakest link, and so states should explore reforms that automate the redistricting process using consistent metrics and open source algorithms. Doing so will create a more accountable process that is less likely to be subverted by partisan interests and more likely to restore voter confidence.