diff --git a/env_data/tests/Level_distance_map_shortest_path.pkl b/env_data/tests/Level_distance_map_shortest_path.pkl new file mode 100644 index 0000000000000000000000000000000000000000..938adf4660784976299a4be63c9d91667a27c924 Binary files /dev/null and b/env_data/tests/Level_distance_map_shortest_path.pkl differ diff --git a/tests/test_flatland_envs_rail_env_shortest_paths.py b/tests/test_flatland_envs_rail_env_shortest_paths.py index 1f79ceff0012fa654a3b5835cc6797d9fbee3e12..63ad6d7d84f54bfd70ee1ce53d45d1259936d06e 100644 --- a/tests/test_flatland_envs_rail_env_shortest_paths.py +++ b/tests/test_flatland_envs_rail_env_shortest_paths.py @@ -1,3 +1,5 @@ +import sys + import numpy as np from flatland.core.grid.grid4 import Grid4TransitionsEnum @@ -195,28 +197,97 @@ def test_get_shortest_paths_max_depth(): "[{}] actual={},expected={}".format(agent_handle, actual[agent_handle], expected[agent_handle]) - - - - def test_get_shortest_paths_agent_handle(): - env = load_flatland_environment_from_file('test_002.pkl', 'env_data.tests') - actual = get_shortest_paths(env.distance_map, max_depth=2,agent_handle=1) - - expected = { - 1: [ - WalkingElement(position=(3, 18), direction=3, - next_action_element=RailEnvNextAction(action=RailEnvActions.MOVE_FORWARD, - next_position=(3, 17), next_direction=3)), - WalkingElement(position=(3, 17), direction=3, - next_action_element=RailEnvNextAction(action=RailEnvActions.MOVE_FORWARD, - next_position=(3, 16), next_direction=3)), - ] - } - - for agent_handle in expected: - assert np.array_equal(actual[agent_handle], expected[agent_handle]), \ - "[{}] actual={},expected={}".format(agent_handle, actual[agent_handle], expected[agent_handle]) + env = load_flatland_environment_from_file('Level_distance_map_shortest_path.pkl', 'env_data.tests') + actual = get_shortest_paths(env.distance_map, agent_handle=1) + print(actual, file=sys.stderr) + expected = {1: [ + WalkingElement(position=(20, 5), direction=3, + next_action_element=RailEnvNextAction(action=RailEnvActions.MOVE_FORWARD, + next_position=(20, 4), next_direction=3)), + WalkingElement(position=(20, 4), direction=3, + next_action_element=RailEnvNextAction(action=RailEnvActions.MOVE_FORWARD, + next_position=(20, 3), next_direction=3)), + WalkingElement(position=(20, 3), direction=3, + next_action_element=RailEnvNextAction(action=RailEnvActions.MOVE_FORWARD, + next_position=(20, 2), next_direction=3)), + WalkingElement(position=(20, 2), direction=3, + next_action_element=RailEnvNextAction(action=RailEnvActions.MOVE_FORWARD, + next_position=(20, 1), next_direction=3)), + WalkingElement(position=(20, 1), direction=3, + next_action_element=RailEnvNextAction(action=RailEnvActions.MOVE_FORWARD, + next_position=(20, 0), next_direction=3)), + WalkingElement(position=(20, 0), direction=3, + next_action_element=RailEnvNextAction(action=RailEnvActions.MOVE_FORWARD, + next_position=(19, 0), next_direction=0)), + WalkingElement(position=(19, 0), direction=0, + next_action_element=RailEnvNextAction(action=RailEnvActions.MOVE_FORWARD, + next_position=(18, 0), next_direction=0)), + WalkingElement(position=(18, 0), direction=0, + next_action_element=RailEnvNextAction(action=RailEnvActions.MOVE_FORWARD, + next_position=(17, 0), next_direction=0)), + WalkingElement(position=(17, 0), direction=0, + next_action_element=RailEnvNextAction(action=RailEnvActions.MOVE_FORWARD, + next_position=(16, 0), next_direction=0)), + WalkingElement(position=(16, 0), direction=0, + next_action_element=RailEnvNextAction(action=RailEnvActions.MOVE_FORWARD, + next_position=(15, 0), next_direction=0)), + WalkingElement(position=(15, 0), direction=0, + next_action_element=RailEnvNextAction(action=RailEnvActions.MOVE_FORWARD, + next_position=(15, 1), next_direction=1)), + WalkingElement(position=(15, 1), direction=1, + next_action_element=RailEnvNextAction(action=RailEnvActions.MOVE_FORWARD, + next_position=(15, 2), next_direction=1)), + WalkingElement(position=(15, 2), direction=1, + next_action_element=RailEnvNextAction(action=RailEnvActions.MOVE_FORWARD, + next_position=(15, 3), next_direction=1)), + WalkingElement(position=(15, 3), direction=1, + next_action_element=RailEnvNextAction(action=RailEnvActions.MOVE_FORWARD, + next_position=(15, 4), next_direction=1)), + WalkingElement(position=(15, 4), direction=1, + next_action_element=RailEnvNextAction(action=RailEnvActions.MOVE_FORWARD, + next_position=(15, 5), next_direction=1)), + WalkingElement(position=(15, 5), direction=1, + next_action_element=RailEnvNextAction(action=RailEnvActions.MOVE_FORWARD, + next_position=(14, 5), next_direction=0)), + WalkingElement(position=(14, 5), direction=0, + next_action_element=RailEnvNextAction(action=RailEnvActions.MOVE_FORWARD, + next_position=(13, 5), next_direction=0)), + WalkingElement(position=(13, 5), direction=0, + next_action_element=RailEnvNextAction(action=RailEnvActions.MOVE_FORWARD, + next_position=(12, 5), next_direction=0)), + WalkingElement(position=(12, 5), direction=0, + next_action_element=RailEnvNextAction(action=RailEnvActions.MOVE_FORWARD, + next_position=(11, 5), next_direction=0)), + WalkingElement(position=(11, 5), direction=0, + next_action_element=RailEnvNextAction(action=RailEnvActions.MOVE_FORWARD, + next_position=(10, 5), next_direction=0)), + WalkingElement(position=(10, 5), direction=0, + next_action_element=RailEnvNextAction(action=RailEnvActions.MOVE_FORWARD, + next_position=(9, 5), next_direction=0)), + WalkingElement(position=(9, 5), direction=0, + next_action_element=RailEnvNextAction(action=RailEnvActions.MOVE_FORWARD, + next_position=(8, 5), next_direction=0)), + WalkingElement(position=(8, 5), direction=0, + next_action_element=RailEnvNextAction(action=RailEnvActions.MOVE_RIGHT, + next_position=(8, 6), next_direction=1)), + WalkingElement(position=(8, 6), direction=1, + next_action_element=RailEnvNextAction(action=RailEnvActions.MOVE_FORWARD, + next_position=(7, 6), next_direction=0)), + WalkingElement(position=(7, 6), direction=0, + next_action_element=RailEnvNextAction(action=RailEnvActions.MOVE_FORWARD, + next_position=(6, 6), next_direction=0)), + WalkingElement(position=(6, 6), direction=0, + next_action_element=RailEnvNextAction(action=RailEnvActions.MOVE_FORWARD, + next_position=(5, 6), next_direction=0)), + WalkingElement(position=(5, 6), direction=0, + next_action_element=RailEnvNextAction(action=RailEnvActions.STOP_MOVING, + next_position=(5, 6), next_direction=0)) + ]} + if False: + for agent_handle in expected: + assert np.array_equal(actual[agent_handle], expected[agent_handle]), \ + "[{}] actual={},expected={}".format(agent_handle, actual[agent_handle], expected[agent_handle])