Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # COMMAND LINE ARGUMENTS
- if (len(sys.argv)<7):
- INIT_POP = 100
- INIT_INFECTED = 5
- NUM_COLS = 10
- NUM_ROWS = 10
- NUM_STEPS = 10
- INIT_IMMUNE = 5
- print('***Default*** nInitial Population = '+str(INIT_POP)+'nInitial Infected = '+str(INIT_INFECTED)+'nNumber of Columns = '+str(NUM_COLS)
- +'nNumber of rows = '+str(NUM_ROWS)+'nNumber of Steps = '+str(NUM_STEPS)+'nNumber Immune = '+str(INIT_IMMUNE))
- else:
- INIT_POP = int(sys.argv[1])
- INIT_INFECTED = int(sys.argv[2])
- NUM_COLS = int(sys.argv[3])
- NUM_ROWS = int(sys.argv[4])
- NUM_STEPS = int(sys.argv[5])-1
- INIT_IMMUNE = int(sys.argv[6])
- print('****THE EPIDEMIC**** nThe Population of the world = '+str(INIT_POP)+'nThe Infected = '+str(INIT_INFECTED)+'nColumns = '+str(NUM_COLS)
- +'nrows = '+str(NUM_ROWS)+'nNumber of Steps = '+str(NUM_STEPS)+'nThe Immune = '+str(INIT_IMMUNE))
- def distribute(grid, num_r, num_c, numpeep):
- for i in range(numpeep):
- rpos = random.randint(0, num_r-1)
- cpos = random.randint(0, num_c-1)
- grid[rpos, cpos] += 1
- # print("Adding 1 to (", xpos, ",", ypos,")")
- ````
- def makeScatter(grid, num_r, num_c):
- r_values = []
- c_values = []
- count_values = []
- for row in range(num_r):
- for col in range(num_c):
- if grid[row,col] > 0:
- r_values.append(row)
- c_values.append(col)
- count_values.append(grid[row,col]*100)
- # print("Value at (", row, ",", col, ") is ", grid[row, col])
- return(r_values, c_values, count_values)
- `````
- def displayGrid(grid, num_r, num_c):
- for row in range(num_r-1, -1, -1):
- for col in range(num_c):
- print(grid[row,col], end=" ")
- print()
- def plotGrids():
- plt.figure(figsize=(20,20))
- Irows, Icols, Icount = makeScatter(infected, NUM_ROWS, NUM_COLS)
- plt.scatter(Icols, Irows, s=Icount, c="r", alpha=0.5)
- Urows, Ucols, Ucount = makeScatter(uninfected, NUM_ROWS, NUM_COLS)
- plt.scatter(Ucols, Urows, s=Ucount, c="b", alpha=0.5)
- Mrows, Mcols, Mcount = makeScatter(immune, NUM_ROWS, NUM_COLS)
- plt.scatter(Mrows, Mcols, s=Mcount, c="y", alpha=0.8)
- plt.show()
- ````
- def movePeeps(cur, next, r, c):
- print("Pos (", r, ",", c, ") has ", cur[r,c], " people")
- for peep in range(cur[r,c]):
- rMove = random.randint(-1,1)
- cMove = random.randint(-1,1)
- print("Move from (", r, ",", c, ") to (", r+rMove, "," , c+cMove, ")")
- if (r + rMove) > (NUM_ROWS-1) or (r + rMove) < 0:
- rMove = 0
- if (c + cMove) > (NUM_COLS-1) or (c + cMove) < 0:
- cMove = 0
- next[r + rMove, c + cMove] +=1
- print(" (", r, ",", c, ") to (", r+rMove, "," , c+cMove, ")")
- `````
- def infect(inf, notinf, r, c, prob):
- # print("Pos (", r, ",", c, ") has ", inf[r,c], " inf people and ", notinf[r,c], " well people")
- prob = prob * inf[r,c]
- if prob:
- for peep in range(notinf[r,c]):
- if random.random() < prob:
- inf[r, c] +=1
- notinf[r, c] -=1
- print("***** New infection (", r, ",", c, ")")
- `````
- `````
- def immune(imm, notimm, r, c, prob):
- # print("Pos (", r, ",", c, ") has ", inf[r,c], " inf people and ", notinf[r,c], " well people")
- prob = prob * imm[r,c]
- if prob:
- for peep in range(notinf[r,c]):
- if random.random() < prob:
- imm[r, c] +=1
- notinf[r, c] -=1
- `````
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement