evo game – fairness

10切れのケーキを2人で分け合うゲーム
戦略は0~10個を相手に要求するといった11種類。
利得は2人の要求数の和が10以下の場合、要求した数だけで、そうでない場合は0。

cakeG

# a simple implementation
N_game=50;N_slice=10;
PropDemand=runif(N_slice+1);
PropDemand=PropDemand/sum(PropDemand);
PayMat=rbind(c(rep(0,11)),c(rep(1,10),0),c(rep(2,9),0,0),c(rep(3,8),0,0,0),
 c(rep(4,7),rep(0,4)),c(rep(5,6),rep(0,5)),c(rep(6,5),rep(0,6)),c(rep(7,4),rep(0,7)),
 c(rep(8,3),rep(0,8)),c(rep(9,2),rep(0,9)),c(rep(10,1),rep(0,10)))
histPD=matrix(0,nrow=N_game,ncol=N_slice+1);
histPD[1,]=PropDemand;
for (i_gen in 2:N_game) {
  PD2=matrix(PropDemand,nrow=N_slice+1,ncol=N_slice+1,byrow=T)
  Ws=rowSums(PD2*PayMat);
  meanW=sum(outer(PropDemand,PropDemand)*PayMat);
  PropDemand=PropDemand*(Ws/meanW)
  histPD[i_gen,]=PropDemand;
}
cols=c("black","red","cyan","green","blue","magenta","pink","brown","gray","orange","black")
plot(histPD[,1],xlim=c(1,N_game),ylim=c(0,1),type='l',col='black');
for (i_slice in 2:(N_slice+1)) {
  lines(histPD[,i_slice],type='l',col=cols[i_slice])
}

# in a form of differential equations
PropDemand=runif(N_slice+1);
PropDemand=PropDemand/sum(PropDemand);
tStep=0.01;ts=seq(0,30,tStep);Nts=length(ts)
histPD=matrix(0,nrow=Nts,ncol=N_slice+1);
histPD[1,]=PropDemand;
for (i_gen in 2:Nts) {
  PD2=matrix(PropDemand,nrow=N_slice+1,ncol=N_slice+1,byrow=T)
  Ws=rowSums(PD2*PayMat);
  meanW=sum(outer(PropDemand,PropDemand)*PayMat);
  PropDemand=PropDemand+PropDemand*((Ws-meanW)/meanW)*tStep
  histPD[i_gen,]=PropDemand;
}
cols=c("black","red","cyan","green","blue","magenta","pink","brown","gray","orange","black")
plot(histPD[,1],xlim=c(1,Nts),ylim=c(0,1),type='l',col='black',lwd=3);
for (i_slice in 2:(N_slice+1)) {
  lines(histPD[,i_slice],type='l',col=cols[i_slice],lwd=3)
}