Commit 214b08a1 by Erik Nygren 🚅

code cleanup and added city cells in order to avoid drawing paths through cities

parent 3504c01f
Pipeline #2207 failed with stages
in 60 minutes
 ... ... @@ -33,7 +33,7 @@ speed_ration_map = {1.: 0.25, # Fast passenger train env = RailEnv(width=50, height=50, rail_generator=sparse_rail_generator(num_cities=9, # Number of cities in map (where train stations are) num_trainstations=0, # Number of possible start/targets on map num_trainstations=50, # Number of possible start/targets on map min_node_dist=8, # Minimal distance of nodes node_radius=3, # Proximity of stations to city center seed=15, # Random seed ... ...
 ... ... @@ -37,7 +37,8 @@ class AStarNode: def a_star(grid_map: GridTransitionMap, start: IntVector2D, end: IntVector2D, a_star_distance_function: IntVector2DDistance = Vec2d.get_manhattan_distance, nice=True) -> IntVector2DArray: a_star_distance_function: IntVector2DDistance = Vec2d.get_manhattan_distance, nice=True, forbidden_cells=None) -> IntVector2DArray: """ Returns a list of tuples as a path from the given start to end. If no path is found, returns path to closest point to end. ... ... @@ -90,11 +91,15 @@ def a_star(grid_map: GridTransitionMap, if node_pos[0] >= rail_shape[0] or node_pos[0] < 0 or node_pos[1] >= rail_shape[1] or node_pos[1] < 0: continue # Skip paths through forbidden regions. if forbidden_cells is not None: if node_pos in forbidden_cells and node_pos != start_node and node_pos != end_node: continue # validate positions # if not grid_map.validate_new_transition(prev_pos, current_node.pos, node_pos, end_node.pos) and nice: continue # create new node new_node = AStarNode(node_pos, current_node) children.append(new_node) ... ...
 ... ... @@ -20,13 +20,15 @@ def connect_basic_operation( flip_start_node_trans=False, flip_end_node_trans=False, nice=True, a_star_distance_function: IntVector2DDistance = Vec2d.get_manhattan_distance) -> IntVector2DArray: a_star_distance_function: IntVector2DDistance = Vec2d.get_manhattan_distance, forbidden_cells=None ) -> IntVector2DArray: """ Creates a new path [start,end] in `grid_map.grid`, based on rail_trans, and returns the path created as a list of positions. """ # in the worst case we will need to do a A* search, so we might as well set that up path: IntVector2DArray = a_star(grid_map, start, end, a_star_distance_function, nice) path: IntVector2DArray = a_star(grid_map, start, end, a_star_distance_function, nice, forbidden_cells) if len(path) < 2: print("No path found", path) return [] ... ... @@ -87,6 +89,12 @@ def connect_nodes(rail_trans: RailEnvTransitions, grid_map: GridTransitionMap, return connect_basic_operation(rail_trans, grid_map, start, end, False, False, False, a_star_distance_function) def connect_cities(rail_trans: RailEnvTransitions, grid_map: GridTransitionMap, start: IntVector2D, end: IntVector2D, forbidden_cells, a_star_distance_function: IntVector2DDistance = Vec2d.get_manhattan_distance) -> IntVector2DArray: return connect_basic_operation(rail_trans, grid_map, start, end, False, False, False, a_star_distance_function, forbidden_cells) def connect_from_nodes(rail_trans: RailEnvTransitions, grid_map: GridTransitionMap, start: IntVector2D, end: IntVector2D, a_star_distance_function: IntVector2DDistance = Vec2d.get_manhattan_distance ... ...