This commit is contained in:
Sandro Zimmermann 2025-12-05 17:03:11 +01:00
parent 014df61e4f
commit b60cd485fc
2 changed files with 17 additions and 14 deletions

View File

@ -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)

View File

@ -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)