Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.42 KB | None | 0 0
  1. # COMMAND LINE ARGUMENTS
  2.  
  3. if (len(sys.argv)<7):
  4. INIT_POP = 100
  5. INIT_INFECTED = 5
  6. NUM_COLS = 10
  7. NUM_ROWS = 10
  8. NUM_STEPS = 10
  9. INIT_IMMUNE = 5
  10. print('***Default*** nInitial Population = '+str(INIT_POP)+'nInitial Infected = '+str(INIT_INFECTED)+'nNumber of Columns = '+str(NUM_COLS)
  11. +'nNumber of rows = '+str(NUM_ROWS)+'nNumber of Steps = '+str(NUM_STEPS)+'nNumber Immune = '+str(INIT_IMMUNE))
  12.  
  13. else:
  14. INIT_POP = int(sys.argv[1])
  15. INIT_INFECTED = int(sys.argv[2])
  16. NUM_COLS = int(sys.argv[3])
  17. NUM_ROWS = int(sys.argv[4])
  18. NUM_STEPS = int(sys.argv[5])-1
  19. INIT_IMMUNE = int(sys.argv[6])
  20. print('****THE EPIDEMIC**** nThe Population of the world = '+str(INIT_POP)+'nThe Infected = '+str(INIT_INFECTED)+'nColumns = '+str(NUM_COLS)
  21. +'nrows = '+str(NUM_ROWS)+'nNumber of Steps = '+str(NUM_STEPS)+'nThe Immune = '+str(INIT_IMMUNE))
  22.  
  23. def distribute(grid, num_r, num_c, numpeep):
  24. for i in range(numpeep):
  25. rpos = random.randint(0, num_r-1)
  26. cpos = random.randint(0, num_c-1)
  27. grid[rpos, cpos] += 1
  28. # print("Adding 1 to (", xpos, ",", ypos,")")
  29. ````
  30. def makeScatter(grid, num_r, num_c):
  31. r_values = []
  32. c_values = []
  33. count_values = []
  34. for row in range(num_r):
  35. for col in range(num_c):
  36. if grid[row,col] > 0:
  37. r_values.append(row)
  38. c_values.append(col)
  39. count_values.append(grid[row,col]*100)
  40. # print("Value at (", row, ",", col, ") is ", grid[row, col])
  41. return(r_values, c_values, count_values)
  42. `````
  43. def displayGrid(grid, num_r, num_c):
  44. for row in range(num_r-1, -1, -1):
  45. for col in range(num_c):
  46. print(grid[row,col], end=" ")
  47. print()
  48.  
  49. def plotGrids():
  50. plt.figure(figsize=(20,20))
  51. Irows, Icols, Icount = makeScatter(infected, NUM_ROWS, NUM_COLS)
  52. plt.scatter(Icols, Irows, s=Icount, c="r", alpha=0.5)
  53. Urows, Ucols, Ucount = makeScatter(uninfected, NUM_ROWS, NUM_COLS)
  54. plt.scatter(Ucols, Urows, s=Ucount, c="b", alpha=0.5)
  55.  
  56. Mrows, Mcols, Mcount = makeScatter(immune, NUM_ROWS, NUM_COLS)
  57. plt.scatter(Mrows, Mcols, s=Mcount, c="y", alpha=0.8)
  58.  
  59. plt.show()
  60. ````
  61. def movePeeps(cur, next, r, c):
  62. print("Pos (", r, ",", c, ") has ", cur[r,c], " people")
  63. for peep in range(cur[r,c]):
  64. rMove = random.randint(-1,1)
  65. cMove = random.randint(-1,1)
  66. print("Move from (", r, ",", c, ") to (", r+rMove, "," , c+cMove, ")")
  67. if (r + rMove) > (NUM_ROWS-1) or (r + rMove) < 0:
  68. rMove = 0
  69. if (c + cMove) > (NUM_COLS-1) or (c + cMove) < 0:
  70. cMove = 0
  71. next[r + rMove, c + cMove] +=1
  72. print(" (", r, ",", c, ") to (", r+rMove, "," , c+cMove, ")")
  73.  
  74. `````
  75. def infect(inf, notinf, r, c, prob):
  76. # print("Pos (", r, ",", c, ") has ", inf[r,c], " inf people and ", notinf[r,c], " well people")
  77. prob = prob * inf[r,c]
  78. if prob:
  79. for peep in range(notinf[r,c]):
  80. if random.random() < prob:
  81. inf[r, c] +=1
  82. notinf[r, c] -=1
  83. print("***** New infection (", r, ",", c, ")")
  84. `````
  85. `````
  86. def immune(imm, notimm, r, c, prob):
  87. # print("Pos (", r, ",", c, ") has ", inf[r,c], " inf people and ", notinf[r,c], " well people")
  88. prob = prob * imm[r,c]
  89. if prob:
  90. for peep in range(notinf[r,c]):
  91. if random.random() < prob:
  92. imm[r, c] +=1
  93. notinf[r, c] -=1
  94. `````
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement