学生有 3 个有序的项目主题选择。
主题链接到主管。每个主管都有不同数量的主题。此外,每个导师也对他们总共监督多少学生有限制。
如果每个主题有几个学生,我们有一个优先排序的列表。
多年来,我们一直在手动执行此操作,但是随着学生人数的增加,它越来越没有乐趣了……
由于工作量的限制,它比第一眼看到的要复杂一些,所以不能那么快地编写代码。所以,我想知道是否有人已经这样做了并且它位于 GitHub 或 Moodle 存储库的某个地方。我会寻找 R 代码,因为我还不知道 Python 或 Julia(还)。或者,更方便的是,也许有某种应用程序可以用于它,比如涂鸦池等?
乐于帮助教育界。让我知道我是否可以更好地描述它,或者它是否鼓励您使用更多信息来编辑您的问题。
set.seed(1234) # used for repeatable random data in this example
# First we create the fake topics data.frame
topics <- data.frame(topic = LETTERS[1:6],
supervisor = c("John","Richard","Harriet","Brianna","Merlin","Lawrence"),
student_limit = c(5,2,4,2,3,5),
students_assigned = 0)
topics
# topic supervisor student_limit students_assigned
#1 A John 5 0
#2 B Richard 2 0
#3 C Harriet 4 0
#4 D Brianna 2 0
#5 E Merlin 3 0
#6 F Lawrence 5 0
sum(topics$student_limit) # for this example we'll have some spare spots
#[1] 21
# create fake students with fake preferences
n <- 20
student_names <- sample(rownames(USArrests), n, replace = F)
student_preferences <- cbind.data.frame(student_names, t(replicate(n, sample(topics$topic, 3)))) # fake top 3 sample
colnames(student_preferences) <- c("student","choice1","choice2","choice3")
student_preferences$topic_assigned <- NA
student_preferences$choice_rank <- NA
student_preferences
# student choice1 choice2 choice3 topic_assigned choice_rank
#1 Nevada F D E NA NA
#2 Kansas E D F NA NA
#3 Michigan C D F NA NA
#4 Oregon E B A NA NA
#5 Utah B C D NA NA
#6 Florida D C E NA NA
#7 California A C B NA NA
#8 Pennsylvania D B C NA NA
#9 Wisconsin B E C NA NA
#10 Arkansas F A B NA NA
#11 North Dakota C A E NA NA
#12 Rhode Island A F D NA NA
#13 West Virginia B A C NA NA
#14 Montana C B D NA NA
#15 Colorado F C A NA NA
#16 Iowa C A B NA NA
#17 Indiana F E A NA NA
#18 South Carolina C F B NA NA
#19 New Jersey E B C NA NA
#20 Mississippi F D E NA NA
此算法将根据谁先给出他们的偏好来填充。 如果学生的第一个偏好被填满,它会移动到他们的第二个,然后是他们的第三个
for(i in 1:n){
# CHOICE 1
topic_row <- which(topics[,"topic"] == student_preferences[i, "choice1"])
if(topics[topic_row, "students_assigned"] < topics[topic_row, "student_limit"]){
student_preferences[i, "topic_assigned"] <- student_preferences[i, "choice1"]
student_preferences[i, "choice_rank"] <- "choice1"
topics[topic_row, "students_assigned"] <- topics[topic_row, "students_assigned"] + 1
} else {
# CHOICE 2
topic_row <- which(topics[,"topic"] == student_preferences[i, "choice2"])
if(topics[topic_row, "students_assigned"] < topics[topic_row, "student_limit"]){
student_preferences[i, "topic_assigned"] <- student_preferences[i, "choice2"]
student_preferences[i, "choice_rank"] <- "choice2"
topics[topic_row, "students_assigned"] <- topics[topic_row, "students_assigned"] + 1
} else {
# CHOICE 3
topic_row <- which(topics[,"topic"] == student_preferences[i, "choice3"])
if(topics[topic_row, "students_assigned"] < topics[topic_row, "student_limit"]){
student_preferences[i, "topic_assigned"] <- student_preferences[i, "choice3"]
student_preferences[i, "choice_rank"] <- "choice3"
topics[topic_row, "students_assigned"] <- topics[topic_row, "students_assigned"] + 1
} else {
student_preferences$topic_assigned[i] <- "could not assign"
}
}
}
}
student_preferences
# student choice1 choice2 choice3 topic_assigned choice_rank
#1 Nevada F D E F choice1
#2 Kansas E D F E choice1
#3 Michigan C D F C choice1
#4 Oregon E B A E choice1
#5 Utah B C D B choice1
#6 Florida D C E D choice1
#7 California A C B A choice1
#8 Pennsylvania D B C D choice1
#9 Wisconsin B E C B choice1
#10 Arkansas F A B F choice1
#11 North Dakota C A E C choice1
#12 Rhode Island A F D A choice1
#13 West Virginia B A C A choice2
#14 Montana C B D C choice1
#15 Colorado F C A F choice1
#16 Iowa C A B C choice1
#17 Indiana F E A F choice1
#18 South Carolina C F B F choice2
#19 New Jersey E B C E choice1
#20 Mississippi F D E could not assign <NA>
topics
# topic supervisor student_limit students_assigned
#1 A John 5 3
#2 B Richard 2 2
#3 C Harriet 4 4
#4 D Brianna 2 2
#5 E Merlin 3 3
#6 F Lawrence 5 5
所以你仍然会有前 3 名没有达到的情况。需要知道您希望在这种情况下发生什么。