2016-10-24 108 views
0

我有一群人每个都提交了一个会议的演示文稿。每个演示文稿需要由其他提交者审核7次,但没有提交者应该审核自己的演示文稿。我想随机分配每个人审查7个演示文稿,每个演示文稿只审核7次,没有人审查自己的演示文稿。随机分配数据

实施例的数据:

DT = data.frame(First_Name = letters[1:10], Presentation = 1:10)

我公开在R或Excel中这样做。任何帮助表示赞赏。

+0

有多少人的组中?? –

+0

我们有142个人 – josh453

+0

我的解决方案可以使用任何编号...............见下文........... –

回答

1

使用的Excel被表示为具有10个顶点,每度7.

这里是在库中一种这样的方法的曲线图该组中的成员列A

enter image description here

和运行此宏:

Sub Reviewers() 
    Dim N As Long, i As Long, j As Long, rA As Range 

    N = Cells(Rows.Count, "A").End(xlUp).Row 
    Set rA = Range("A1:A" & N) 
    ' 
    '----------------------------------PART 1 
    ' 
    For i = 1 To N 
     j = i + 1 
     rA.Copy Cells(1, j) 
     Cells(i, j).Delete shift:=xlUp 
    Next i 
    ' 
    '---------------------------------PART 2 
    ' 

    For i = 2 To N + 1 
     Call SkrambleRange(Range(Cells(1, i), Cells(N - 1, i))) 
    Next i 
End Sub 

    Sub SkrambleRange(rng As Range) 
     Dim arr(), r As Range, i As Long 
     ReDim arr(1 To rng.Count) 
     i = 1 
     For Each r In rng 
      arr(i) = r.Value 
      i = i + 1 
     Next r 

     Call Shuffle(arr) 

     i = 1 
     For Each r In rng 
      r.Value = arr(i) 
      i = i + 1 
     Next r 
    End Sub 

    Public Sub Shuffle(InOut() As Variant) 
     Dim i As Long, j As Long 
     Dim tempF As Double, Temp As Variant 

     Hi = UBound(InOut) 
     Low = LBound(InOut) 
     ReDim Helper(Low To Hi) As Double 
     Randomize 

     For i = Low To Hi 
      Helper(i) = Rnd 
     Next i 


     j = (Hi - Low + 1) \ 2 
     Do While j > 0 
      For i = Low To Hi - j 
       If Helper(i) > Helper(i + j) Then 
       tempF = Helper(i) 
       Helper(i) = Helper(i + j) 
       Helper(i + j) = tempF 
       Temp = InOut(i) 
       InOut(i) = InOut(i + j) 
       InOut(i + j) = Temp 
       End If 
      Next i 
      For i = Hi - j To Low Step -1 
       If Helper(i) > Helper(i + j) Then 
       tempF = Helper(i) 
       Helper(i) = Helper(i + j) 
       Helper(i + j) = tempF 
       Temp = InOut(i) 
       InOut(i) = InOut(i + j) 
       InOut(i + j) = Temp 
       End If 
      Next i 
      j = j \ 2 
     Loop 
    End Sub 

第1部分产生评价者对每个提交者的列表。所以第B是Mary Smith (Mary Smith自己的名字已被删除)的评论列表;列ç是帕特里夏·约翰逊审稿列表等

第2个部分每个评审列:

enter image description here

要得到7个审稿玛丽·史密斯,拉头7洗牌来自列B的名称。
要获取Patricia Johnson的7位审阅者,请从列C等中提取前7个名称。

+0

使用此解决方案,每位评论者都有其他7个演示文稿进行审查? EG:玛丽史密斯有7人审查她的提案,但也有7个提案要审查。 – josh453

+0

@ josh453这就是为什么我使用列** B **的完整数据.....第一张纸使用** B1 **至** B7 **,第二张纸使用** B8 **至** B14 **等.............. ....因此,您可以从可用池中获得全部49个选项*(7 X 7)*。 –

+0

我想我明白了,谢谢! – josh453

0

R的igraph库具有随机图生成算法。这听起来像是你想随机将每个人与另外7个人连接起来,比如说一群10个人。

地点:这可能

library(igraph) 
plot(g <- sample_degseq(rep(7,10),method="vl")) 

enter image description here

0

下面是使用线性编程的解决方案。 (由Randomly assign elements repeatedly to a limited number of groupshttps://acoppock.github.io/subpages/Random_Assignment_Subject_To_Constraints.html启发)

library(lpSolve) 
library(tidyverse) 

df <- 
    # get all possible person-presentation combinations 
    expand.grid(person = letters[1:10], presentation = 1:10) %>% 
    mutate(person_number = match(person, letters)) %>% 
    # throw out self-matches 
    filter(presentation != person_number) 

# Two constraints: 
# each presentation is reviewed 7 times. 
# Each person conducts 7 reviews 

first <- t(sapply(1:10, function(i) as.numeric(df$presentation == i))) 
second <- t(sapply(letters[1:10], function(i) as.numeric(df$person == i))) 

const.mat <- rbind(first, second) 
const.dir <- rep(c("=", "="), c(10, 10)) 
const.rhs <- rep(c(7, 7), c(10, 10)) 

# This is the acutal stochastic part 
random_objective <- runif(ncol(const.mat)) 

mod <- lp(
    direction = "max", 
    objective.in = random_objective, 
    const.mat = const.mat, 
    const.dir = const.dir, 
    const.rhs = const.rhs, 
    all.bin = TRUE 
) 

df$assign_review <- mod$solution 

with(df, table(assign_review)) 
with(df, table(assign_review, presentation)) 
with(df, table(assign_review, person)) 

这产生输出作为期望:

> with(df, table(assign_review, presentation)) 
      presentation 
assign_review 1 2 3 4 5 6 7 8 9 10 
      0 2 2 2 2 2 2 2 2 2 2 
      1 7 7 7 7 7 7 7 7 7 7 
> with(df, table(assign_review, person)) 
      person 
assign_review a b c d e f g h i j 
      0 2 2 2 2 2 2 2 2 2 2 
      1 7 7 7 7 7 7 7 7 7 7