Search code examples
algorithmuniquecombinationspermutation

Uniqueness in Permutation and Combination


I am trying to create some pseudocode to generate possible outcomes for this scenario:

There is a tournament taking place, where each round all players in the tournament are in a group with other players of different teams.

Given x amount of teams, each team has exactly n amount of players. What are the possible outcomes for groups of size r where you can only have one player of each team AND the player must have not played with any of the other players already in previous rounds.

Example: 4 teams (A-D), 4 players each team, 4 players each grouping.

Possible groupings are: (correct team constraint)

A1, B1, C1, D1
A1, B3, C1, D2

But not: (violates same team constraint)

A1, A3, C2, D2
B3, C2, D4, B1

However, the uniqueness constraint comes into play in this grouping

A1, B1, C1, D1
A1, B3, C1, D2

While it does follow the constraints of playing with different teams, it has broken the rule of uniqueness of playing with different players. In this case A1 is grouped up twice with C1

At the end of the day the pseudocode should be able to create something like the following

Round 1   Round 2   Round 3   Round 4
 a1 b1     a1 d4     a1 c2     a1 c4
 c1 d1     b2 c3     b4 d3     d2 b3

 a2 b2     a2 d1     a2 c3     a2 c1
 c2 d2     b3 c4     b1 d4     d3 b4

 a3 b3     a3 d2     a3 c4     a3 c2
 c3 d3     b4 c1     b2 d1     d4 b1

 a4 b4     a4 d3     a4 c1     a4 c3
 c4 d4     b1 c2     b3 d2     d1 b2

In the example you see that in each round no player has been grouped up with another previous player.


Solution

  • If the number of players on a team is a prime power (2, 3, 4, 5, 7, 8, 9, 11, 13, 16, 17, 19, etc.), then here's an algorithm that creates a schedule with the maximum number of rounds, based on a finite affine plane.

    We work in the finite field GF(n), where n is the number of players on a team. GF(n) has its own notion of multiplication; when n is a prime, it's multiplication mod n, and when n is higher power of some prime, it's multiplication of univariate polynomials mod some irreducible polynomial of the appropriate degree. Each team is identified by a nonzero element of GF(n); let the set of team identifiers be T. Each team member is identified by a pair in T×GF(n). For each nonzero element r of GF(n), the groups for round r are

    {{(t, r*t + c) | t in T} | c in GF(n)},
    

    where * and + denote multiplication and addition respectively in GF(n).

    Implementation in Python 3


    This problem is very closely related to the Social Golfer Problem. The Social Golfer Problem asks, given n players who each play once a day in g groups of size s (n = g×s), how many days can they be scheduled such that no player plays with any other player more than once?

    The algorithms for finding solutions to instances of Social Golfer problems are a patchwork of constraint solvers and mathematical constructions, which together don't address very many cases satisfactorily. If the number of players on a team is equal to the group size, then solutions to this problem can be derived by interpreting the first day's schedule as the team assignments and then using the rest of the schedule. There may be other constructions.