Combinatorial problem about finding optimal subsets of numbers forming pairs

58 Views Asked by At

I am trying to solve a combinatorial problem computationally (currently using python) and cannot find a good algorithmic solution for it.

I have n individual numbers (eg. 0,1,2,3,4,5). These numbers form "imaginary" pairs and since the order within these pairs is irrelevant my initial numbers could form binomial(n, 2) pairs.

Now I would like to group these pairs into m smaller subsets (the size of these subsets can differ and does not has to). Within all of these m subsets, every pair has to occur equally often (p). Also, none of these pairs is allowed to occur in exactly the same subsets as another pair (i.e. every pair forms an individual pattern of subsets in which it occurs). Note that individual compounds automatically form these virtual pairs (eg. a set of 1,2,4,5 form six pairs [1,2],[1,4],[1,5],[2,4][2,5][4,5])

Now my code needs to minimalize m while still fulfilling all the rules (1. The same number of subsets, 2. Differing patterns) so my question is:

How can I distribute the numbers into the different subsets while minimizing the number of sets m? Is there a non-heuristic and cool mathematical way of doing this? At the moment I count m up while checking how many different pairs I could map with every p < m. When the code found a solution I try to randomly fill every set (equally distributed) with my numbers 0 to n and check if the conditions are satisfied. Then, I calculate a cost function (How often are both conditions not fulfilled - here I tried different options) randomly switch two compounds, and check if the cost function got better. I repeat this quite often (usually 1 to 10 Mio times) and if the program could not find a solution I increase m and p and start the initialization again. As you can imagine - this takes forever and I hope someone has a nice mathematically inspired method since I am not capable of solving this.

Please excuse me if my question is not formulated nicely from the mathematical perspective. I am a PhD Student in the field of chemistry and some reviewers on our current paper asked a question about finding a solution to this. Since I have no strong mathematical background I thought that this question could have been adressed before.