finalize personenstromsimulation
This commit is contained in:
parent
14b94f9016
commit
4999ed0096
@ -15,8 +15,8 @@ CELL_OBS = -1 # cell state: obstacle
|
||||
EXIT_X = GRIDSIZE_X+1 # x-coordinate of exit
|
||||
EXIT_Y = int(GRIDSIZE_Y/2) # y-coordinate of exit
|
||||
|
||||
VIS_PAUSE = 2 # time [s] between two visual updates
|
||||
VIS_STEPS = 1 # stride [steps] between two visual updates
|
||||
VIS_PAUSE = 0.2 # time [s] between two visual updates
|
||||
VIS_STEPS = 2 # stride [steps] between two visual updates
|
||||
|
||||
# count pedestrians left in domain
|
||||
def count_peds(grid):
|
||||
@ -46,8 +46,6 @@ def comp_density(grid):
|
||||
|
||||
# state transition t -> t + dt
|
||||
def update(old, new):
|
||||
|
||||
#print(count_peds(old))
|
||||
for x in range(1, GRIDSIZE_X+1):
|
||||
for y in range(1, GRIDSIZE_Y+1):
|
||||
#
|
||||
@ -57,49 +55,43 @@ def update(old, new):
|
||||
delta_x = EXIT_X - x
|
||||
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)
|
||||
#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["SE"]["x"], terrain["SE"]["y"], terrain["SE"]["cell"], terrain["SE"]["vector"] = set_terrain(old, x+1, y-1)
|
||||
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["W"]["x"], terrain["W"]["y"], terrain["W"]["cell"], terrain["W"]["vector"] = set_terrain(old, x-1, y)
|
||||
#terrain["NW"]["x"], terrain["NW"]["y"], terrain["NW"]["cell"], terrain["NW"]["vector"] = set_terrain(old, x-1, y+1)
|
||||
'''print(terrain["N"]["cell"])
|
||||
print(terrain["E"]["cell"])
|
||||
print(terrain["S"]["cell"])
|
||||
print(terrain["W"]["cell"])'''
|
||||
min = np.inf
|
||||
jump_to = None
|
||||
|
||||
min = np.inf
|
||||
move_to = None
|
||||
|
||||
# Alternative move_to when optimal move_to is blocked
|
||||
for key in terrain:
|
||||
if terrain[key]["cell"] == CELL_EMP:
|
||||
if terrain[key]["vector"] < min:
|
||||
min = terrain[key]["vector"]
|
||||
jump_to = terrain[key]
|
||||
'''for key in terrain:
|
||||
if terrain[key]["vector"] < min:
|
||||
min = terrain[key]["vector"]
|
||||
jump_to = terrain[key]'''
|
||||
print(jump_to)
|
||||
if jump_to != None:
|
||||
new[jump_to["x"], jump_to["y"]] = CELL_PED
|
||||
move_to = terrain[key]
|
||||
|
||||
if move_to != None:
|
||||
new[move_to["x"], move_to["y"]] = CELL_PED
|
||||
old[move_to["x"], move_to["y"]] = CELL_OBS
|
||||
old[x,y] = CELL_OBS
|
||||
else:
|
||||
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("")'''
|
||||
|
||||
# Stay still when optimal move_to is blocked
|
||||
'''for key in terrain:
|
||||
if terrain[key]["vector"] < min:
|
||||
min = terrain[key]["vector"]
|
||||
move_to = terrain[key]
|
||||
|
||||
if move_to != None and move_to["cell"] == CELL_EMP:
|
||||
new[move_to["x"], move_to["y"]] = CELL_PED
|
||||
old[move_to["x"], move_to["y"]] = CELL_OBS
|
||||
old[x,y] = CELL_OBS
|
||||
else:
|
||||
new[x,y] = old[x,y]'''
|
||||
|
||||
|
||||
def set_terrain(grid, x, y):
|
||||
cell = grid[x,y]
|
||||
@ -136,9 +128,9 @@ plt.pause(VIS_PAUSE)
|
||||
while count_peds(old) > 0 and time < MAX_TIME:
|
||||
new[1:GRIDSIZE_X+1,1:GRIDSIZE_Y+1] = CELL_EMP
|
||||
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+1] = CELL_OBS # clear exit
|
||||
new[EXIT_X,EXIT_Y+1] = CELL_EMP # clear exit
|
||||
old = new.copy()
|
||||
numpeds = count_peds(old)
|
||||
dens.append(comp_density(old))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user