Gerrymandering involves the redrawing of election district boundaries to give an electoral advantage to a particular candidate or party. The term derives from a redrawing of US Representative districts in Massachusetts before the 1812 elections, when Elbridge Gerry was governor. The story goes that two reporters were discussing the new map, and when one commented that the district north of Boston looked like a salamander, the other exclaimed, "No, a Gerry-mander!"
Read through the US Constitution, particularly Article 1. Note that the US Constitution requires that Representative seats should be apportioned among the states based on the results of a decennial census (Article 1, Section 2) but leaves it to the individual states to determine how to elect their Representatives (Section 4). The Constitution does not actually require states to elect their Representatives from geographic districts; this is just custom, mimicking the geographic apportionment by state.
The lack of specificity in the Constitution allows for a lot of political shenanigans. For example, there's nothing preventing a state legislature from re-drawing Congressional district boundareis any time it likes! Texas had 17 Democrat and 15 Republican US Representatives in 2002, when Republicans finally won a majority of seats in the Texas legislature. So with US House Speaker Tom DeLay's help, the Texas legislature re-drew the state's Congressional district boundaries again in 2003 so that the 2004 elections yielded 11 Democrat and 21 Republican US Representatives, boosting the Republican majority in Congress. Court challenges to this were unsuccessful. Read the Wikipedia entry on "Gerrymandering" for background information, and the entry on "2003 Texas redistricting" for the gory details of Tom DeLay's plot and fugitive Texas Democrats!
While we are all amused by horribly stringy or contorted district maps, there may be reasonable justifications for creating geometrically complex districts. While the courts have been very reluctant to intervene in redistricting, the Supreme Court has supported districts that improve representation of "communities of interest" even if this involves stringing together dispersed regions using strips of interstate highway (Illinois 4th), rivers, etc. Some coastal districts simply reflect population concentrations along coastlines.
In contrast to the usual wailing and hand-wringing over gerrymandering, a recent American Economic Review article by John Friedman and Richard Holden titled "Optimal Gerrymandering: Sometimes Pack, but Never Crack" (AER 98:113-144) explains how to maxmize your party's political advantage from gerrymandering. (If you're going to play this game, why not play to win?) "Packing" opposition voters into a minimum number of conceded districts is always an efficient strategy. "Cracking" the opposition to maximize the number of districts in which your party is in the majority is not. The paper assumes you can groups voters any way you like (geography doesn't matter!) but treats voting as quasi-random.
Data on your party affiliation, your age, gender, address and phone number, and which elections you voted in are all made available to politicians and political parties. These are the data used to draw district boundaries. The only secret is who you actually voted for. So a really smart gerrymandering strategy has to account for a lot of uncertainties: who will vote and who will stay home? Who will vote their party line, and who will cross over in what races?
The logistic red-state/blue-state models you analyzed in the previous project would be readily adaptable as probabilistic voting models here.