Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Iterate over all unique round robin tournaments of size n

There's a round robin tournament with n participants. That is, each pair of distinct nodes i and j will compete against each other, and the outcomes can be represented as a directed graph where there is either an edge from i to j or an edge from j to i.

Now, let's say n is 3, so the nodes are i, j, and k. There could be an edge from i to j, j to k, and k to i. Another possibility is an edge from i to k, k to j, and j to i, but if I'm performing operations that are agnostic to the identities of the "players," then these are effectively the same tournament. There is also a possibility of an edge from i to j, i to k, and j to k, which is of the other "class" of tournament on 3 nodes.

So, I want to come up with a program, preferably in Python, that will be able to iterate over every unique tournament on n participants.

My existing solution is to generate a bitfield of length n * (n-1) / 2, and use that to populate the upper triangle of the adjacency matrix. Then for every 0 in the upper triangle, the corresponding entry in the lower triangle is a 1. Obviously, this will find every round robin tournament of size n, but there are many many effectively identical tournaments and it is slowing things down considerably. I'm not expecting to need to operate in an n larger than, say, 15 at most, but that isn't feasible right now.

If someone knows or can derive a formula for how many unique round robin tournaments there are of size n, that would certainly help.

like image 382
Ctenochaetus Avatar asked Oct 24 '25 15:10

Ctenochaetus


1 Answers

How many tournaments are there?

the number of unlabeled tournaments on n vertices is given by sequence A000568 in the OEIS, but there's no simple formula. (There is a sum over partitions of n...)"

The OEIS link gives a formula (a sum over partitions of n), as well as implementations of this formula in several programming languages including Maple and Mathematica.

If you want to implement this formula in python, I suggest using library sympy to get the partitions of n.

like image 105
Stef Avatar answered Oct 26 '25 05:10

Stef