From 08c4911b660a5689000ee4da870d737e7f6a9986 Mon Sep 17 00:00:00 2001 From: Sandro Zimmermann Date: Thu, 18 Dec 2025 00:05:07 +0100 Subject: [PATCH] persononstomsimulation updated --- personenstromsimulation/pedestrian_sk.py | 45 ++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/personenstromsimulation/pedestrian_sk.py b/personenstromsimulation/pedestrian_sk.py index d94c3a0..a049437 100644 --- a/personenstromsimulation/pedestrian_sk.py +++ b/personenstromsimulation/pedestrian_sk.py @@ -2,11 +2,12 @@ import numpy as np import matplotlib.pyplot as plt +import time as tiime GRIDSIZE_X = 35 GRIDSIZE_Y = 35 MAX_TIME = 500 -NUM_PEDS = 1 +NUM_PEDS = 200 CELL_PED = 1 # cell state: pedestrian CELL_EMP = 0 # cell state: empty @@ -16,7 +17,7 @@ EXIT_X = GRIDSIZE_X+1 # x-coordinate of exit EXIT_Y = int(GRIDSIZE_Y/2) # y-coordinate of exit VIS_PAUSE = 0.2 # time [s] between two visual updates -VIS_STEPS = 2 # stride [steps] between two visual updates +VIS_STEPS = 1 # stride [steps] between two visual updates # count pedestrians left in domain def count_peds(grid): @@ -46,11 +47,51 @@ 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): # # transition functions # + + if old[x, y] == CELL_PED: + delta_x = EXIT_X - x + 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 = {}, 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 + + for key in terrain: + if terrain[key]["cell"] == CELL_EMP: + if terrain[key]["vector"] < min: + min = terrain[key]["vector"] + jump_to = terrain[key] + + if jump_to != None: + new[jump_to["x"], jump_to["y"]] = CELL_PED + old[x,y] = CELL_OBS + +def set_terrain(grid, x, y): + cell = grid[x,y] + vector = np.sqrt((EXIT_X - x)**2 + (EXIT_Y - y)**2) + return x, y, cell, vector # allocate memory and initialise grids old = np.zeros((GRIDSIZE_X+2, GRIDSIZE_Y+2), dtype=np.int32)