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

performance boost

parent 5d3477f8
No related branches found
No related tags found
No related merge requests found
...@@ -896,25 +896,20 @@ def sparse_rail_generator(num_cities=5, grid_mode=False, max_inter_city_rails=4, ...@@ -896,25 +896,20 @@ def sparse_rail_generator(num_cities=5, grid_mode=False, max_inter_city_rails=4,
Function to fix all transition elements in environment Function to fix all transition elements in environment
""" """
# Fix all nodes with illegal transition maps # Fix all nodes with illegal transition maps
empty_to_fix = [] rails_to_fix = np.zeros(2 * grid_map.height * grid_map.width * 2, dtype='int')
rails_to_fix = [] rails_to_fix_cnt = 0
for cell in city_cells: for cell in city_cells:
check = grid_map.cell_neighbours_valid(cell, True) check = grid_map.cell_neighbours_valid(cell, True)
if grid_map.grid[cell] == int('1000010000100001', 2): if grid_map.grid[cell] == int('1000010000100001', 2):
grid_map.fix_transitions(cell) grid_map.fix_transitions(cell)
if not check: if not check:
if grid_map.grid[cell] == 0: rails_to_fix[2 * rails_to_fix_cnt] = cell[0]
empty_to_fix.append(cell) rails_to_fix[2 * rails_to_fix_cnt + 1] = cell[1]
else: rails_to_fix_cnt += 1
rails_to_fix.append(cell)
# Fix empty cells first to avoid cutting the network
for cell in empty_to_fix:
grid_map.fix_transitions(cell)
# Fix all other cells # Fix all other cells
for cell in rails_to_fix: for cell in range(rails_to_fix_cnt):
grid_map.fix_transitions(cell) grid_map.fix_transitions((rails_to_fix[2 * cell], rails_to_fix[2 * cell + 1]))
def _closest_neigh_in_direction(current_node, node_positions): def _closest_neigh_in_direction(current_node, node_positions):
""" """
......
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