Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #extremely bad simulation
- res = NULL
- for (iter in 1:20){
- for (propmove in 0.05*1:20){
- nindivid = 240
- xposition = rnorm(nindivid)
- yposition = rnorm(nindivid)
- speeds = runif(nindivid)/20
- speeds[1] = 0.02
- radius = 0.05
- nummove = floor(nindivid*propmove)
- xposition = xposition - floor(xposition)
- yposition = yposition - floor(yposition)
- infectionstate = c(99, rep(0, nindivid-1))
- #0 = succ, > 0 = infected, -1 = recovered
- for (i in 1:100){
- whichmove =sample(nindivid, nummove)
- for (ind in whichmove){
- xposition[ind] = xposition[ind]+sign(rnorm(1))*speeds[ind]
- yposition[ind] = yposition[ind]+sign(rnorm(1))*speeds[ind]
- }
- distmat = as.matrix(dist(cbind(xposition, yposition)))
- for (ind in (1:nindivid)){
- if (infectionstate[ind]>0) infectionstate[ind] = infectionstate[ind]-4
- if (infectionstate[ind]==0){
- for (j in 1:nindivid){
- if ((distmat[ind, j]< radius) & (infectionstate[j] > 0)){
- infectionstate[ind] = 99
- }
- }
- }
- }
- #plot(xposition, yposition, col=sign(infectionstate) + 2, xlim=c(0,1), ylim=c(0,1), pch=19)
- }
- print(c(propmove, tail(res,1)))
- #table(sign(infectionstate))
- res = c(res,sum(infectionstate==0))
- }
- plot(1-rowMeans(matrix(res, 20))/250, ylim=c(0,1), type="l")
- }
Advertisement
Add Comment
Please, Sign In to add comment