Here you will find daily news and tutorials about R, contributed by over 750 bloggers.
There are many ways to follow us - By e-mail:On Facebook: If you are an R blogger yourself you are invited to add your own R content feed to this site (Non-English R bloggers should add themselves- here)

Following the question on dinner table permutations on StackExchange (mathematics) and the reply that the right number was six, provided by hardmath, I was looking for a constructive solution how to build the resolvable 2-(20,5,1) covering. A few hours later. hardmath again came up with an answer, found in the paper Equitable Resolvable Coverings by van Dam, Haemers and Peek (2002). In the meanwhile (and even during the Big’MC seminar of yesterday!), I had been thinking of a simulated annealing implementation, which actually was used by van Dam, Haemers and Peek. Here is my (plain) R code

#initialisation of tables
#rows for individuals, columns for courses
T=sample(rep(1:4,5))
for (i in 2:6)
T=cbind(T,sample(rep(1:4,5)))
#encounters table
meet=function(T){
M=outer(T[,1],T[,1],"==")
for (i in 2:6)
M=M+outer(T[,i],T[,i],"==")
M
}
#number of missed encounters
penalty=function(M){ sum(M==0) }
penat=penalty(meet(T))
N=10^5
gamma=100
for (t in 1:N){
#random pick of switched individuals
prop=sample(1:20,2,prob=apply(meet(T)==0,1,sum))
cour=sample(1:6,1)
Tp=T
Tp[prop[1],cour]=T[prop[2],cour]
Tp[prop[2],cour]=T[prop[1],cour]
penatp=penalty(meet(Tp))
print(c(penat,penatp))
if (penatp==0){
T=Tp
break()
}
if (log(runif(1))<(penat-penatp)/gamma){
T=Tp
penat=penatp}
if (t%%10==0)
gamma=gamma*.999
}

which happened to provide a solution on the second round (got stuck at a penalty of 4 in the first round):