On May 5, 1:33 pm, MRAB <goo...@mrabarnett.plus.com> wrote: > Ross wrote: > > On May 5, 12:32 am, John Yeung <gallium.arsen...@gmail.com> wrote: > >> On May 5, 1:12 am, John Yeung <gallium.arsen...@gmail.com> wrote: > > >>> [...] the problem may require bigger guns (either much better > >>> math or much more sophisticated programming). > >> Yes, I'm responding to myself. > > >> Well, I went ahead with the approach I mentioned earlier, generating > >> all possible matches and then selecting among them as needed to fill > >> up the courts, trying to keep the number of matches played by each > >> player as fair as possible. (I should mention that this, or something > >> similar, was suggested earlier by someone else in a different thread, > >> in response to the same question by the same OP.) > > >> I did use "bigger guns" (mainly a class for player objects, with > >> custom __cmp__ method), but still didn't do anything with doubles. > > >> I haven't tested it much, but I'll post it if anyone's interested. > >> (That way people can pick on me instead of the OP. ;) > > >> John > > > I'm interested to see what you did. From your description, it sounds > > like I've tried what you've done, but when I implemented my version, > > it took minutes to evaluate for bigger numbers. If that isn't the case > > with yours, I'd be interested in seeing your implementation. > > Here's my approach (incomplete): > > def get_pair(player_list, played): > for first in range(len(player_list)): > player_1 = player_list[first] > for second in range(first + 1, len(player_list)): > player_2 = player_list[second] > pair = player_1, player_2 > sorted_pair = tuple(sorted(pair)) > if sorted_pair not in played: > played.add(sorted_pair) > del player_list[second] > del player_list[first] > return pair > return None > > def round_robin(player_list, courts, played): > playing = [] > for c in range(courts): > pair = get_pair(player_list, played) > if pair is None: > break > playing.append(pair) > byes = player_list[:] > player_list[:] = byes + [player for pair in playing for player in pair] > yield playing, byes > > def test_round_robin(players, rounds, courts, doubles=False): > player_list = range(players) > played = set() > for r in range(rounds): > for playing, byes in round_robin(player_list, courts, played): > print playing, byes- Hide quoted text - > > - Show quoted text -
Looks like somewhat of an improvement, although the bye distribution is still slightly lopsided. For example, in a singles league with 12 players, 12 rounds, and 4 courts, The first player had at least 2 less byes than every other player and 3 less byes than the players with the most number of byes. Thanks for your input though...I'll look into how I can improve upon it. -- http://mail.python.org/mailman/listinfo/python-list