1

I am trying to write a section of code in PHP which will work out for each team the best and worst possible outcome from a round robin type tournament.

This code will be executed after each round of games and so will lookup the current W-L-T record for each team as well as the future schedule of games for each team (all of this information is already stored in a database).

My initial thought was to run through each permutation of ranking of each team and remembering the extreme limits for each teams performance. However upon further thinking I realise that for the twelve teams in this case that would result in over 479 million permutations (which may take a little time to calculate, let alone being concise code).

I have unfortunately reached, I fear, the limit of my imagination in devising a logic system to deal with this so any help anyone could offer would be great.

Cheers in advance Edward

Jeffrey Blake
  • 9,659
  • 6
  • 43
  • 65
  • Wouldn't the best and worst case simply be that the team either wins or loses every game? – mikeyq6 Nov 06 '13 at 18:28
  • @mikeyq6 no, OP wants to recalculate the ods after each round. – Zlatko Nov 06 '13 at 18:35
  • 1
    @user2961751, You need to add a few more details. Additionally, you need to provide a very specific question, like "How can I calculate a permutation of 12..." etc, and the best results you get when you add a sample of your code or at least pseudocode. Ie. here you could add a sample pseudo- or php code on how this would go. – Zlatko Nov 06 '13 at 18:42
  • The possible outcomes are "all of them", unless you're modeling the NCAA :) – hobbs Nov 06 '13 at 18:57

1 Answers1

0

I'll assume a loss is worth 0 points, a tie 1 point and a win 2 points.

For each team t
    Sort the teams by their current point table so the last place
    team(s) come first and the top teams come last. Put all teams tied with t before t.
    Let i be the position of team t in this list
    From here on I'll name teams by their position in the list. So we have
    from left to right, teams currently worse than i, teams tied with team i, team i,
    and finally teams better than i.
    Make a working copy  of your matrix. For the rest of this
         iteration I'll implicitly refer to the working copy.
    Suppose (in the working copy) that team i has loses all its remaining games.
    For j from 0 up to i
         Make a backup copy of the working copy. 
         for( k:=n-1 ; k < j and j is behind or tied with i ; k := k-1 )
             If k hasn't played j and j is behind i
                 suppose that j beats k
             Else if k hasn't played j /* and is tied with k */
                  suppose that j ties k
          if j is still behind i
             revert to the backup made before the preceding loop
          discard the backup copy
          for all games j has yet to play suppose j loses

     At this point, all remaining games in the working copy are between teams ahead
     of team i, assume all remaining games are ties.
     Now (if we have really constructed a worst case scenario) the rank of team i
     in the working copy is the worst it can do. I.e. team i beats "count

I'm not completely sure this give the exact lower bound. An upper bound would be symmetric.

Theodore Norvell
  • 15,366
  • 6
  • 31
  • 45
  • Thank you for your help Theodore, This solution assumes that past performance has anything to do with theoretical best and worst performances (unless I have misunderstood your logic), which is not true. My problem is that team a could have lost to team b hundreds of times but it could still win that last time they played, for example – PickleBranston Nov 06 '13 at 20:41
  • No, I was assuming a single round-robin. I.e. n(n-1)/2 games in total. I think the idea can be extended to the more general case, but then I am less confident that it gives the right answer. – Theodore Norvell Nov 07 '13 at 13:33
  • My concern about this system is that it still seems to assume future results based on previous ones, something that I do not wish it to do. – PickleBranston Nov 07 '13 at 17:15
  • That was not my intention, so I haven't explained the idea well. Also I have some new ideas that are better. So I'll withdraw this answer. – Theodore Norvell Nov 09 '13 at 22:38