I need your help.
Let's say that I have a list of students that I need to split to 3 groups. I let every student choose up to 3 friends, and guaranteed that every one will have at least one friend of his choice in his group. Obviously, I would like to maximize the amount of total amount of friends connections as much as possible.
E.g:
I create a dataset of 4 columns: the student's name, and 3 friends that he has chosen.
data <- data.frame(matrix(ncol = 4, nrow = 50))
colnames(data) <- c("student.name", "friend1", "friend2", "friend3")
data$student.name <- c("John","Ben","Dan","James","Emma","Dana",
"Liam","Mohammad","Ethan","Noah","Lucas",
"Mason","Harper", "William","Billy", "Moses",
"Eli","Bob","Tilson","Mishel","Joel","Patrick",
"Ron","Gideon","Yair","Mike","Olivia", "Jacob",
"Owen","Levi","Sebastian","Logan","Aiden","Matt",
"Dave","Kenn","Myra","Natali","Lily","Cathrin", "Kevin",
"Igor","Heron","Kraus","Dosh","Milosh","Jerry","George",
"Kosmo","Elaine")
data$friend1 <- sample(data$student.name)
data$friend2 <- sample(data$student.name)
data$friend3 <- sample(data$student.name)
> data
student.name friend1 friend2 friend3
1 John Mishel Ethan Igor
2 Ben Ron Ben Eli
3 Dan Kenn Olivia Kraus
4 James Levi Mason Dan
5 Emma Kosmo Liam Kevin
6 Dana Mason Natali Matt
7 Liam Jacob Aiden Kenn
8 Mohammad Dan William Owen
9 Ethan Mike Harper Cathrin
10 Noah John Kosmo Ben
11 Lucas Jerry Sebastian Mike
12 Mason Kraus Dave Olivia
13 Harper Igor Mishel Kosmo
14 William Moses Kraus Levi
15 Billy Harper Noah Logan
16 Moses Ethan Dana Moses
17 Eli Gideon Myra Aiden
18 Bob Liam Mohammad George
19 Tilson Sebastian Gideon William
20 Mishel Elaine John Bob
21 Joel Logan Logan Myra
22 Patrick Ben Bob Jerry
23 Ron Cathrin Emma Yair
24 Gideon Lucas Dosh Billy
25 Yair Dana Yair Mason
26 Mike Natali Matt Dave
27 Olivia Matt Mike Dosh
28 Jacob Milosh Jerry Lucas
29 Owen Heron Eli Gideon
30 Levi Yair Lucas Jacob
31 Sebastian Emma Kenn John
32 Logan James Heron Emma
33 Aiden Billy Cathrin Elaine
34 Matt Kevin Tilson Sebastian
35 Dave Aiden Owen Lily
36 Kenn Tilson Billy Mishel
37 Myra Eli Jacob Liam
38 Natali George Moses Ron
39 Lily William Joel Tilson
40 Cathrin Dave Levi Natali
41 Kevin Dosh Dan Joel
42 Igor Lily Igor Harper
43 Heron Owen Milosh Dana
44 Kraus Olivia James Ethan
45 Dosh Noah Patrick Noah
46 Milosh Bob Ron Mohammad
47 Jerry Joel Elaine Milosh
48 George Patrick Kevin James
49 Kosmo Mohammad Lily Heron
50 Elaine Myra George Patrick
question from:
https://stackoverflow.com/questions/65907705/what-function-can-i-use-to-generate-student-groups-with-at-least-one-friend-in-r