Okay, I actually have an alpha version working. I've run a few test cases, and it seems to work well with those.
The algorithm I use is this (my own custom):
1) Add up all player records (number of games played) and divide by 2. This represents the theoretical "midpoint score" you would want both teams to have, ideally. For example, say you are doing a 2v2. Say the number of games played is 50, 100, 100, and 50. The total is 300. Divided by 2, that's 150. So you'd want to make teams who's sum total records are as close to 150 as possible.
2) Generate a matrix of ALL POSSIBLE TEAMS, and add up all their records.
3) Grab all team configurations who's records are equally close to the "midpoint score" which was calculated earlier, and present them as solutions.
Here is the program output for the above "toy" example:
pug 50 100 100 50
1 1 2 2
1 2 1 2
2 1 2 1
2 2 1 1
Another "toy" example:
pug 100 200 300 400 500 600
1 2 1 2 2 1
1 2 2 1 1 2
1 2 2 1 2 1
2 1 1 2 1 2
2 1 1 2 2 1
2 1 2 1 1 2
A more realistic looking example (this wasn't contrived - I literally just threw some numbers down off the top of my head):
pug 78 34 56 233 366 500
1 2 1 2 2 1
2 1 2 1 1 2
If you add up the scores for those teams, you get 633 and 634. The program was trying to balance around the theoretical midpoint of 633.5, and it nailed it. It found 2 solutions out of all possible solutions which are closest to 633.5. Since both of those solutions are equally close to 633.5, it presented them both.
Any interest out there to develop this further?