Compare commits

...

2 Commits

Author SHA1 Message Date
Sandro Zimmermann
14b94f9016 pedestiran updated 2025-12-18 10:23:01 +01:00
Sandro Zimmermann
37471e04b2 personensimulation updated 2025-12-18 01:08:41 +01:00

View File

@ -2,7 +2,6 @@
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
@ -16,7 +15,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 = 0.2 # time [s] between two visual updates VIS_PAUSE = 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
@ -47,19 +46,17 @@ 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
if delta_x != 0 and delta_y != 0:
#terrain = dict(N = {}, NE = {}, E = {}, SE = {}, S = {}, SW = {}, W = {}, NW = {}) #terrain = dict(N = {}, NE = {}, E = {}, SE = {}, S = {}, SW = {}, W = {}, NW = {})
terrain = dict(N = {}, E = {}, S = {}, W = {}) terrain = dict(N = {}, E = {}, S = {}, W = {})
@ -83,10 +80,26 @@ def update(old, new):
if terrain[key]["vector"] < min: if terrain[key]["vector"] < min:
min = terrain[key]["vector"] min = terrain[key]["vector"]
jump_to = terrain[key] 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: if jump_to != None:
new[jump_to["x"], jump_to["y"]] = CELL_PED new[jump_to["x"], jump_to["y"]] = CELL_PED
old[x,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("")'''
def set_terrain(grid, x, y): def set_terrain(grid, x, y):
cell = grid[x,y] cell = grid[x,y]
@ -123,9 +136,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_EMP # clear exit new[EXIT_X,EXIT_Y-1] = CELL_OBS # 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_EMP # clear exit new[EXIT_X,EXIT_Y+1] = CELL_OBS # 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))