updated
This commit is contained in:
parent
014df61e4f
commit
b60cd485fc
@ -4,7 +4,7 @@ import numpy as np
|
|||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
GRIDSIZE = 300
|
GRIDSIZE = 300
|
||||||
INIT_CELLS = int(GRIDSIZE*0.3)
|
INIT_CELLS = int(GRIDSIZE*0.2)
|
||||||
MAX_TIME = 300
|
MAX_TIME = 300
|
||||||
EMPTY_CELL = -1
|
EMPTY_CELL = -1
|
||||||
DALLY_LIMIT = 0.2
|
DALLY_LIMIT = 0.2
|
||||||
@ -13,6 +13,7 @@ DALLY_LIMIT = 0.2
|
|||||||
# query distance between two cars
|
# query distance between two cars
|
||||||
def get_distance(grid, i):
|
def get_distance(grid, i):
|
||||||
dist = 0
|
dist = 0
|
||||||
|
print(grid)
|
||||||
while grid[(i+dist+1)%GRIDSIZE] == EMPTY_CELL and dist < 5:
|
while grid[(i+dist+1)%GRIDSIZE] == EMPTY_CELL and dist < 5:
|
||||||
dist = dist + 1
|
dist = dist + 1
|
||||||
return dist
|
return dist
|
||||||
@ -24,6 +25,9 @@ def update(grid_old, grid_new):
|
|||||||
if grid_old[i] != EMPTY_CELL:
|
if grid_old[i] != EMPTY_CELL:
|
||||||
v = np.min((grid_old[i]+1, 5)) # accelerate
|
v = np.min((grid_old[i]+1, 5)) # accelerate
|
||||||
dist = get_distance(grid_old, i)
|
dist = get_distance(grid_old, i)
|
||||||
|
if i == 295:
|
||||||
|
print(grid_old[i], " ", dist)
|
||||||
|
quit()
|
||||||
if v > dist: v = dist # break
|
if v > dist: v = dist # break
|
||||||
p = np.random.random()
|
p = np.random.random()
|
||||||
if p == DALLY_LIMIT: v = max(grid_old[i-1], 0)
|
if p == DALLY_LIMIT: v = max(grid_old[i-1], 0)
|
||||||
|
|||||||
@ -10,28 +10,27 @@ MAX_TIME = 300
|
|||||||
EMPTY_CELL = -1
|
EMPTY_CELL = -1
|
||||||
|
|
||||||
# query distance between two cars
|
# query distance between two cars
|
||||||
def get_distance(grid, i):
|
def get_distance(grid):
|
||||||
dist = 0
|
|
||||||
""" Compute distance between current position and next car """
|
""" Compute distance between current position and next car """
|
||||||
"""
|
"""
|
||||||
Insert your code here
|
Insert your code here
|
||||||
"""
|
"""
|
||||||
|
for n in grid:
|
||||||
for n in range(1, (grid[i]+1)&GRIDSIZE):
|
if grid[n] != EMPTY_CELL:
|
||||||
if grid[i + n] != -1:
|
|
||||||
return n
|
return n
|
||||||
return -1
|
return 5
|
||||||
|
|
||||||
# state transition t -> t + dt
|
# state transition t -> t + dt
|
||||||
def update(grid_old, grid_new):
|
def update(grid_old, grid_new):
|
||||||
for i in range(GRIDSIZE):
|
for i in range(GRIDSIZE):
|
||||||
dist = get_distance(grid_old, i)
|
if grid_old[i] != EMPTY_CELL:
|
||||||
""" Update cars according rules using value 'dist' """
|
dist = get_distance(grid_old[i+1:i+6])
|
||||||
"""
|
""" Update cars according rules using value 'dist' """
|
||||||
Insert your code here
|
"""
|
||||||
"""
|
Insert your code here
|
||||||
if dist != -1:
|
"""
|
||||||
print(dist)
|
if dist != -1:
|
||||||
|
print(dist)
|
||||||
|
|
||||||
# allocate memory and initialise grids
|
# allocate memory and initialise grids
|
||||||
grid_old = np.full((GRIDSIZE), EMPTY_CELL, dtype=np.int32)
|
grid_old = np.full((GRIDSIZE), EMPTY_CELL, dtype=np.int32)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user