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

get shortestpath return type changed

parent d56a44fe
No related branches found
No related tags found
No related merge requests found
import math
from typing import Tuple, Set, Dict, List
from typing import Tuple, Set, Dict, List, NamedTuple
import numpy as np
......@@ -14,6 +14,10 @@ from flatland.envs.rail_generators import rail_from_file
from flatland.envs.schedule_generators import schedule_from_file
from flatland.utils.ordered_set import OrderedSet
ShortestPathElement = \
NamedTuple('Path_Element',
[('position', Tuple[int, int]), ('direction', int), ('next_action_element', RailEnvNextAction)])
def load_flatland_environment_from_file(file_name, load_from_package=None, obs_builder_object=None):
if obs_builder_object is None:
......@@ -83,7 +87,7 @@ def get_valid_move_actions_(agent_direction: Grid4TransitionsEnum,
return valid_actions
def get_shortest_paths(distance_map: DistanceMap) -> Dict[int, List[RailEnvNextAction]]:
def get_shortest_paths(distance_map: DistanceMap) -> Dict[int, List[ShortestPathElement]]:
# TODO: do we need to support unreachable targets?
# TODO refactoring: unify with predictor (support agent.moving and max_depth)
shortest_paths = dict()
......@@ -97,12 +101,15 @@ def get_shortest_paths(distance_map: DistanceMap) -> Dict[int, List[RailEnvNextA
best_next_action = None
for next_action in next_actions:
next_action_distance = distance_map.get()[a.handle, next_action.next_position[0], next_action.next_position[1], next_action.next_direction]
next_action_distance = distance_map.get()[
a.handle, next_action.next_position[0], next_action.next_position[1], next_action.next_direction]
if next_action_distance < distance:
best_next_action = next_action
distance = next_action_distance
shortest_paths[a.handle].append(ShortestPathElement(position, direction, best_next_action))
position = best_next_action.next_position
direction = best_next_action.next_direction
shortest_paths[a.handle].append(best_next_action)
return shortest_paths
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