updated verkehr_sk.py but dosn't work at all
This commit is contained in:
parent
bf442c94bf
commit
424a7ced87
@ -9,6 +9,11 @@ INIT_CELLS = int(GRIDSIZE*0.1)
|
||||
MAX_TIME = 300
|
||||
EMPTY_CELL = -1
|
||||
|
||||
def unit_distance(grid, v):
|
||||
for i in range(1, v):
|
||||
if grid[i] != -1:
|
||||
return i
|
||||
return -1
|
||||
|
||||
# query distance between two cars
|
||||
def get_distance(grid, i):
|
||||
@ -18,28 +23,32 @@ def get_distance(grid, i):
|
||||
Insert your code here
|
||||
"""
|
||||
|
||||
if i == GRIDSIZE-1:
|
||||
dist = (grid[i], grid[0])
|
||||
else:
|
||||
dist = (grid[i], grid[i+1])
|
||||
print(i % 300)
|
||||
quit()
|
||||
|
||||
return dist
|
||||
for n in range(1, grid[i]+1):
|
||||
if grid[i + n] != -1:
|
||||
return n
|
||||
return -1
|
||||
|
||||
# state transition t -> t + dt
|
||||
def update(grid_old, grid_new):
|
||||
for i in range(GRIDSIZE):
|
||||
dist = get_distance(grid_old, i)
|
||||
|
||||
if not -1 in dist:
|
||||
dist = dist[1] - dist[0]
|
||||
|
||||
print(dist)
|
||||
time.sleep(0.5)
|
||||
|
||||
""" Update cars according rules using value 'dist' """
|
||||
"""
|
||||
Insert your code here
|
||||
"""
|
||||
if dist != -1:
|
||||
if dist == 0:
|
||||
grid_new[i] = 0
|
||||
elif dist - grid_old[i] < 0:
|
||||
grid_new[i] = dist - 1
|
||||
else:
|
||||
if grid_old[i] != 5:
|
||||
grid_new[i] += 1
|
||||
else:
|
||||
grid_new[i] = grid_old[i]
|
||||
|
||||
# allocate memory and initialise grids
|
||||
grid_old = np.full((GRIDSIZE), EMPTY_CELL, dtype=np.int32)
|
||||
@ -65,3 +74,4 @@ plt.xlabel('Cells')
|
||||
plt.ylabel('Timesteps')
|
||||
plt.imshow(traffic, cmap='Blues')
|
||||
plt.show()
|
||||
time.sleep(0.1)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user