Compare commits

..

No commits in common. "14b94f9016aa65700fedfa6b15016c8e922d1845" and "08c4911b660a5689000ee4da870d737e7f6a9986" have entirely different histories.

View File

@ -2,6 +2,7 @@
import numpy as np import numpy as np
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import time as tiime
GRIDSIZE_X = 35 GRIDSIZE_X = 35
GRIDSIZE_Y = 35 GRIDSIZE_Y = 35
@ -15,7 +16,7 @@ CELL_OBS = -1 # cell state: obstacle
EXIT_X = GRIDSIZE_X+1 # x-coordinate of exit EXIT_X = GRIDSIZE_X+1 # x-coordinate of exit
EXIT_Y = int(GRIDSIZE_Y/2) # y-coordinate of exit EXIT_Y = int(GRIDSIZE_Y/2) # y-coordinate of exit
VIS_PAUSE = 2 # time [s] between two visual updates VIS_PAUSE = 0.2 # time [s] between two visual updates
VIS_STEPS = 1 # stride [steps] between two visual updates VIS_STEPS = 1 # stride [steps] between two visual updates
# count pedestrians left in domain # count pedestrians left in domain
@ -46,60 +47,46 @@ def comp_density(grid):
# state transition t -> t + dt # state transition t -> t + dt
def update(old, new): def update(old, new):
print(count_peds(old))
#print(count_peds(old))
for x in range(1, GRIDSIZE_X+1): for x in range(1, GRIDSIZE_X+1):
for y in range(1, GRIDSIZE_Y+1): for y in range(1, GRIDSIZE_Y+1):
# #
# transition functions # transition functions
# #
if old[x,y] == CELL_PED:
if old[x, y] == CELL_PED:
delta_x = EXIT_X - x delta_x = EXIT_X - x
delta_y = EXIT_Y - y delta_y = EXIT_Y - y
#terrain = dict(N = {}, NE = {}, E = {}, SE = {}, S = {}, SW = {}, W = {}, NW = {})
terrain = dict(N = {}, E = {}, S = {}, W = {})
terrain["N"]["x"], terrain["N"]["y"], terrain["N"]["cell"], terrain["N"]["vector"] = set_terrain(old, x, y+1) if delta_x != 0 and delta_y != 0:
#terrain["NE"]["x"], terrain["NE"]["y"], terrain["NE"]["cell"], terrain["NE"]["vector"] = set_terrain(old, x+1, y+1)
terrain["E"]["x"], terrain["E"]["y"], terrain["E"]["cell"], terrain["E"]["vector"] = set_terrain(old, x+1, y) #terrain = dict(N = {}, NE = {}, E = {}, SE = {}, S = {}, SW = {}, W = {}, NW = {})
#terrain["SE"]["x"], terrain["SE"]["y"], terrain["SE"]["cell"], terrain["SE"]["vector"] = set_terrain(old, x+1, y-1) terrain = dict(N = {}, E = {}, S = {}, W = {})
terrain["S"]["x"], terrain["S"]["y"], terrain["S"]["cell"], terrain["S"]["vector"] = set_terrain(old, x, y-1)
#terrain["SW"]["x"], terrain["SW"]["y"], terrain["SW"]["cell"], terrain["SW"]["vector"] = set_terrain(old, x-1, y-1) terrain["N"]["x"], terrain["N"]["y"], terrain["N"]["cell"], terrain["N"]["vector"] = set_terrain(old, x, y+1)
terrain["W"]["x"], terrain["W"]["y"], terrain["W"]["cell"], terrain["W"]["vector"] = set_terrain(old, x-1, y) #terrain["NE"]["x"], terrain["NE"]["y"], terrain["NE"]["cell"], terrain["NE"]["vector"] = set_terrain(old, x+1, y+1)
#terrain["NW"]["x"], terrain["NW"]["y"], terrain["NW"]["cell"], terrain["NW"]["vector"] = set_terrain(old, x-1, y+1) terrain["E"]["x"], terrain["E"]["y"], terrain["E"]["cell"], terrain["E"]["vector"] = set_terrain(old, x+1, y)
'''print(terrain["N"]["cell"]) #terrain["SE"]["x"], terrain["SE"]["y"], terrain["SE"]["cell"], terrain["SE"]["vector"] = set_terrain(old, x+1, y-1)
print(terrain["E"]["cell"]) terrain["S"]["x"], terrain["S"]["y"], terrain["S"]["cell"], terrain["S"]["vector"] = set_terrain(old, x, y-1)
print(terrain["S"]["cell"]) #terrain["SW"]["x"], terrain["SW"]["y"], terrain["SW"]["cell"], terrain["SW"]["vector"] = set_terrain(old, x-1, y-1)
print(terrain["W"]["cell"])''' terrain["W"]["x"], terrain["W"]["y"], terrain["W"]["cell"], terrain["W"]["vector"] = set_terrain(old, x-1, y)
min = np.inf #terrain["NW"]["x"], terrain["NW"]["y"], terrain["NW"]["cell"], terrain["NW"]["vector"] = set_terrain(old, x-1, y+1)
jump_to = None '''print(terrain["N"]["cell"])
print(terrain["E"]["cell"])
for key in terrain: print(terrain["S"]["cell"])
if terrain[key]["cell"] == CELL_EMP: print(terrain["W"]["cell"])'''
if terrain[key]["vector"] < min: min = np.inf
min = terrain[key]["vector"] jump_to = None
jump_to = terrain[key]
'''for key in terrain: for key in terrain:
if terrain[key]["vector"] < min: if terrain[key]["cell"] == CELL_EMP:
min = terrain[key]["vector"] if terrain[key]["vector"] < min:
jump_to = terrain[key]''' min = terrain[key]["vector"]
print(jump_to) jump_to = terrain[key]
if jump_to != None:
new[jump_to["x"], jump_to["y"]] = CELL_PED if jump_to != None:
old[x,y] = CELL_OBS new[jump_to["x"], jump_to["y"]] = CELL_PED
else: old[x,y] = CELL_OBS
new[x,y] = old[x,y]
else:
'''old[x,y] = CELL_OBS
print(delta_x)
print(delta_y)
print("")
print(x)
print(y)
print(old[x,y])
print(new[x,y])
print("")'''
def set_terrain(grid, x, y): def set_terrain(grid, x, y):
cell = grid[x,y] cell = grid[x,y]
@ -113,9 +100,9 @@ old[:,0] = CELL_OBS # boundary: south
old[:,-1] = CELL_OBS # boundary: north old[:,-1] = CELL_OBS # boundary: north
old[0,:] = CELL_OBS # boundary: west old[0,:] = CELL_OBS # boundary: west
old[-1,:] = CELL_OBS # boundary: east old[-1,:] = CELL_OBS # boundary: east
old[EXIT_X,EXIT_Y-1] = CELL_EMP # exit old[EXIT_X,EXIT_Y-1] = CELL_EMP # exit
old[EXIT_X,EXIT_Y] = CELL_EMP # exit old[EXIT_X,EXIT_Y] = CELL_EMP # exit
old[EXIT_X,EXIT_Y+1] = CELL_EMP # exit old[EXIT_X,EXIT_Y+1] = CELL_EMP # exit
new = old.copy() new = old.copy()
# set random starting points for pedestrians # set random starting points for pedestrians
@ -136,9 +123,9 @@ plt.pause(VIS_PAUSE)
while count_peds(old) > 0 and time < MAX_TIME: while count_peds(old) > 0 and time < MAX_TIME:
new[1:GRIDSIZE_X+1,1:GRIDSIZE_Y+1] = CELL_EMP new[1:GRIDSIZE_X+1,1:GRIDSIZE_Y+1] = CELL_EMP
update(old, new) update(old, new)
new[EXIT_X,EXIT_Y-1] = CELL_OBS # clear exit new[EXIT_X,EXIT_Y-1] = CELL_EMP # clear exit
new[EXIT_X,EXIT_Y] = CELL_EMP # clear exit new[EXIT_X,EXIT_Y] = CELL_EMP # clear exit
new[EXIT_X,EXIT_Y+1] = CELL_OBS # clear exit new[EXIT_X,EXIT_Y+1] = CELL_EMP # clear exit
old = new.copy() old = new.copy()
numpeds = count_peds(old) numpeds = count_peds(old)
dens.append(comp_density(old)) dens.append(comp_density(old))