From b60cd485fc13d95a23b696932f8fd661892b8c76 Mon Sep 17 00:00:00 2001 From: Sandro Zimmermann Date: Fri, 5 Dec 2025 17:03:11 +0100 Subject: [PATCH] updated --- verkehrssimulation/verkehr.py | 6 +++++- verkehrssimulation/verkehr_sk.py | 25 ++++++++++++------------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/verkehrssimulation/verkehr.py b/verkehrssimulation/verkehr.py index b801d3b..d1c8378 100644 --- a/verkehrssimulation/verkehr.py +++ b/verkehrssimulation/verkehr.py @@ -4,7 +4,7 @@ import numpy as np import matplotlib.pyplot as plt GRIDSIZE = 300 -INIT_CELLS = int(GRIDSIZE*0.3) +INIT_CELLS = int(GRIDSIZE*0.2) MAX_TIME = 300 EMPTY_CELL = -1 DALLY_LIMIT = 0.2 @@ -13,6 +13,7 @@ DALLY_LIMIT = 0.2 # query distance between two cars def get_distance(grid, i): dist = 0 + print(grid) while grid[(i+dist+1)%GRIDSIZE] == EMPTY_CELL and dist < 5: dist = dist + 1 return dist @@ -24,6 +25,9 @@ def update(grid_old, grid_new): if grid_old[i] != EMPTY_CELL: v = np.min((grid_old[i]+1, 5)) # accelerate dist = get_distance(grid_old, i) + if i == 295: + print(grid_old[i], " ", dist) + quit() if v > dist: v = dist # break p = np.random.random() if p == DALLY_LIMIT: v = max(grid_old[i-1], 0) diff --git a/verkehrssimulation/verkehr_sk.py b/verkehrssimulation/verkehr_sk.py index c6b79bd..02b2d1b 100644 --- a/verkehrssimulation/verkehr_sk.py +++ b/verkehrssimulation/verkehr_sk.py @@ -10,28 +10,27 @@ MAX_TIME = 300 EMPTY_CELL = -1 # query distance between two cars -def get_distance(grid, i): - dist = 0 +def get_distance(grid): """ Compute distance between current position and next car """ """ Insert your code here """ - - for n in range(1, (grid[i]+1)&GRIDSIZE): - if grid[i + n] != -1: + for n in grid: + if grid[n] != EMPTY_CELL: return n - return -1 + return 5 # state transition t -> t + dt def update(grid_old, grid_new): for i in range(GRIDSIZE): - dist = get_distance(grid_old, i) - """ Update cars according rules using value 'dist' """ - """ - Insert your code here - """ - if dist != -1: - print(dist) + if grid_old[i] != EMPTY_CELL: + dist = get_distance(grid_old[i+1:i+6]) + """ Update cars according rules using value 'dist' """ + """ + Insert your code here + """ + if dist != -1: + print(dist) # allocate memory and initialise grids grid_old = np.full((GRIDSIZE), EMPTY_CELL, dtype=np.int32)