Message Boards Message Boards

0
|
7993 Views
|
7 Replies
|
0 Total Likes
View groups...
Share
Share this post:
GROUPS:

Random selection of pairs

Posted 9 years ago

I have a group of 16 people and wish to schedule them for 10 weeks in groups of 2. All 16 people meet (8 pairs of 2) each week and I do not wish to have any of the pairs repeat in future weeks. I have been able to come up with pairings but I am unsure as to how make the selections unique, i.e. some pairs are selected more than once. Any suggestions?

Here is the line of code that I've written:

For[i = 1, i < 11, i++,  Print[Partition[RandomSample[Range[1, 16], 16], 2]]]
POSTED BY: gmauser Mauser
7 Replies
Posted 9 years ago

Thank you for all of the help!

POSTED BY: gmauser Mauser
Posted 9 years ago

This should do it for 10 sets of games, if you alter the count above 11 it stalls.

a = Subsets[Range[16], {2}]; cnt = 0;
While[cnt <= 9, 
 b = Sort[Sort /@ Partition[RandomSample[Range[16]], 2]]; 
 If[Length[a] - Length[Complement[a, b]] == 8, Print[b]; 
  a = Complement[a, b]; cnt++]]

Paul.

POSTED BY: Paul Cleary
Posted 9 years ago

Here is a way to generate 15 weeks of no repeating game.

a = Subsets[Range[16], {2}]; Partition[RandomSample[a], {8}]

David, the line.

pairings = Select[Union[Sort /@ Tuples[{Range[16], Range[16]}]], #[[1]] != #[[2]] &];

can be replaced with

pairings = Subsets[Range[16], {2}]

Paul.

Forget this it doesn't account for same team playing in each round:(

POSTED BY: Paul Cleary
Posted 9 years ago

Random selection of pairs

POSTED BY: Dana DeLouis
Posted 9 years ago

First you want a clean set of pairings. Andy meeting Bob is pretty similar to Bob meeting Andy, and meeting yourself is pretty lonely, so we take the unique sorted pairs possible, and drop the equal ones:

pairings = Select[Union[Sort /@ Tuples[{Range[16], Range[16]}]], #[[1]] != #[[2]] &];

Partitioning is a very nice way to skip lots of these problems, but makes keeping track of pairs more complicated. Instead I remove repeated people every time I pick a pair.

pairs = RandomSample[pairings, 1];
Table[
  notUsed = Select[pairings, Nor @@ (MemberQ[Flatten[pairs], #] & /@ #) &];
  pairs = Append[pairs, RandomSample[notUsed, 1][[1]]];
  , {n, 7}];
pairs

Now we have a week, we can scrub these pairings from our sample and go again.

pairings = Complement[pairings, pairs];

All together:

pairings = Select[Union[Sort /@ Tuples[{Range[16], Range[16]}]], #[[1]] != #[[2]] &];
Table[
 pairs = RandomSample[pairings, 1];
 Table[
  notUsed = Select[pairings, Nor @@ (MemberQ[Flatten[pairs], #] & /@ #) &];
  pairs = Append[pairs, RandomSample[notUsed, 1][[1]]];
  , {n, 7}];
 pairings = Complement[pairings, pairs];
 pairs
 , {m, 7}]

Note that we can choose badly pretty easily. I ran this a few times to get a full list, as several random selections made further selection by our rules impossible!

POSTED BY: David Gathercole
Posted 9 years ago

Perhaps you can adapt this algorithm

POSTED BY: Bill Simpson
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract