Skip to content
Snippets Groups Projects
Commit 14034cfa authored by Egli Adrian (IT-SCI-API-PFI)'s avatar Egli Adrian (IT-SCI-API-PFI)
Browse files

new method for generating switches at stations

parent 4b64873a
No related branches found
No related tags found
No related merge requests found
...@@ -174,22 +174,26 @@ def realistic_rail_generator(num_cities=5, ...@@ -174,22 +174,26 @@ def realistic_rail_generator(num_cities=5,
return nodes_added, station_slots, start_nodes_added, end_nodes_added, station_tracks return nodes_added, station_slots, start_nodes_added, end_nodes_added, station_tracks
def create_switches_at_stations(width, height, grid_map, station_tracks, nodes_added, def create_switches_at_stations(rail_trans, rail_array, width, height, grid_map, station_tracks, nodes_added,
intern_nbr_of_switches_per_station_track): intern_nbr_of_switches_per_station_track):
# generate switch based on switch slot list and connect them
for city_loop in range(len(station_tracks)): for city_loop in range(len(station_tracks)):
datas = station_tracks[city_loop] datas = station_tracks[city_loop]
for data_loop in range(len(datas) - 1): if len(datas)>1:
data = datas[data_loop] a = datas[0]
data1 = datas[data_loop + 1] b = []
if len(data) > 2 and len(data1) > 2: for i in range(len(datas)):
for i in np.random.choice(min(len(data1), len(data)) - 2, tmp = datas[i]
intern_nbr_of_switches_per_station_track): if len(tmp)>0:
GripMapOp.add_rail(width, height, grid_map, data[i + 1], data1[i + 1], data1[i + 2], True) b = tmp
nodes_added.append(data[i + 1]) start_node = a[min(2,len(a))]
nodes_added.append(data1[i + 1]) end_node = b[len(b)-1]
nodes_added.append(data1[i + 2]) rail_array[start_node] = 0
rail_array[end_node] = 0
connection = connect_from_nodes(rail_trans, rail_array, start_node, end_node)
if len(connection) > 0:
nodes_added.append(start_node)
nodes_added.append(end_node)
return nodes_added return nodes_added
def calc_nbr_of_graphs(graph): def calc_nbr_of_graphs(graph):
...@@ -392,13 +396,15 @@ def realistic_rail_generator(num_cities=5, ...@@ -392,13 +396,15 @@ def realistic_rail_generator(num_cities=5,
generate_city_locations, generate_city_locations,
intern_max_number_of_station_tracks) intern_max_number_of_station_tracks)
# build switches # build switches
# TODO remove true/false block
if True: if True:
create_switches_at_stations(width, height, grid_map, station_tracks, nodes_added, create_switches_at_stations(rail_trans, rail_array, width, height, grid_map, station_tracks, nodes_added,
intern_nbr_of_switches_per_station_track) intern_nbr_of_switches_per_station_track)
# ---------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------
# connect stations # connect stations
if True: # TODO remove true/false block
if False:
if do_random_connect_stations: if do_random_connect_stations:
connect_random_stations(rail_trans, rail_array, s_nodes, e_nodes, nodes_added, connect_random_stations(rail_trans, rail_array, s_nodes, e_nodes, nodes_added,
inter_connect_max_nbr_of_shortes_city) inter_connect_max_nbr_of_shortes_city)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment