-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmap_gernator.py
More file actions
36 lines (29 loc) · 1.15 KB
/
map_gernator.py
File metadata and controls
36 lines (29 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from random import randint
from components import Bus,Passenger
def generate_square_grid_map(n,distance,width,height):
def get_adjacenecy_list(i,j):
l = []
steps = [(1,0),(0,1),(-1,0),(0,-1)]
for a,b in steps:
na,nb = i+a,j+b
if(0<=na<=(n-1) and 0<=nb<=(n-1)):
l.append(na*n+nb)
return l
GRID_SPACING = 50
OFFSETX = (width - GRID_SPACING*(n-1))/2
OFFSETY = (height - GRID_SPACING*(n-1))/2
positions = {}
connections =[]
for i in range(n):
for j in range(n):
node = i*n+j
position = (GRID_SPACING*i+OFFSETX,GRID_SPACING*j+OFFSETY)
positions[node] = position
cn = get_adjacenecy_list(i,j)
connections.extend((node,c,distance) for c in cn)
connections.extend((c,node,distance) for c in cn)
return connections,positions
def generate_random_passenger(count,limit):
return [Passenger(randint(0,limit-1),randint(0,limit-1)) for _ in range(count)]
def generate_random_bus_positions(count,limit,speed):
return [Bus(float('inf'),speed,randint(0,limit-1)) for _ in range(count)]