Questions: Can someone help me figure out how to calculate cycles with the maximum number of pairs (three per cycle - see the last example)?
This is what I want to do:
-> a pair of two users each cycle to
- each user connects only once with another user in this cycle
- each user connects only once with every other user in all cycles
Real world:
You meet one new person from the list every week (week = cycle).
You never meet the same person again.
Each user is mapped to someone else per week.
That's my problem:
I can create user combinations and select pairs of users who have never met. However, sometimes I manage to match only two pairs in a loop instead of three. Therefore, I am looking for a way to create the best choice from a list of combinations.
1) I start with 6 users:
users = ["A","B","C","D","E","F"]
2) From this list I create possible combinations:
x = itertools.combinations(users,2) for i in x: candidates.append(i)
This gives me:
. A,BA,CA,DA,EA,F . . B,CB,DB,EB,F . . . C,DC,EC,F . . . . D,ED,F . . . . . E,F
or
candidates = [('A', 'B'), ('A', 'C'), ('A', 'D'), ('A', 'E'), ('A', 'F'), ('B', 'C'), ('B', 'D'), ('B', 'E'), ('B', 'F'), ('C', 'D'), ('C', 'E'), ('C', 'F'), ('D', 'E'), ('D', 'F'), ('E', 'F')]
3) Now I would like to select pairs from this list, so that the user (from A to F) is present only once, and all users connect to someone in this cycle
Example:
cycle1 = ('A','B'),('C','D') ('E','F')
The next cycle, I want to find another set of three pairs.
I calculated that with 6 users there should be 5 cycles with three pairs:
Example:
cycle 1: AF BC DE cycle 2: AB CD EF cycle 3: AC BE DF cycle 4: AE BD CF cycle 5: AD BF CE
Can someone help me figure out how to calculate loops with the maximum number of pairs (three per loop - see the last example)?