Skip to content
Snippets Groups Projects
Commit 5f8a5de1 authored by Dipam Chakraborty's avatar Dipam Chakraborty
Browse files

update calculation of speed normalized path lengths

parent 2bf8a326
No related branches found
No related tags found
No related merge requests found
...@@ -33,7 +33,7 @@ def load_flatland_environment_from_file(file_name: str, ...@@ -33,7 +33,7 @@ def load_flatland_environment_from_file(file_name: str,
max_depth=2, max_depth=2,
predictor=ShortestPathPredictorForRailEnv(max_depth=10)) predictor=ShortestPathPredictorForRailEnv(max_depth=10))
environment = RailEnv(width=1, height=1, rail_generator=rail_from_file(file_name, load_from_package), environment = RailEnv(width=1, height=1, rail_generator=rail_from_file(file_name, load_from_package),
schedule_generator=line_from_file(file_name, load_from_package), line_generator=line_from_file(file_name, load_from_package),
number_of_agents=1, number_of_agents=1,
obs_builder_object=obs_builder_object, obs_builder_object=obs_builder_object,
record_steps=record_steps, record_steps=record_steps,
......
...@@ -32,6 +32,7 @@ def schedule_generator(agents: List[EnvAgent], config_speeds: List[float], dist ...@@ -32,6 +32,7 @@ def schedule_generator(agents: List[EnvAgent], config_speeds: List[float], dist
old_max_episode_steps_multiplier = 3.0 old_max_episode_steps_multiplier = 3.0
new_max_episode_steps_multiplier = 1.5 new_max_episode_steps_multiplier = 1.5
travel_buffer_multiplier = 1.3 # must be strictly lesser than new_max_episode_steps_multiplier travel_buffer_multiplier = 1.3 # must be strictly lesser than new_max_episode_steps_multiplier
assert new_max_episode_steps_multiplier > travel_buffer_multiplier
end_buffer_multiplier = 0.05 end_buffer_multiplier = 0.05
mean_shortest_path_multiplier = 0.2 mean_shortest_path_multiplier = 0.2
...@@ -39,20 +40,14 @@ def schedule_generator(agents: List[EnvAgent], config_speeds: List[float], dist ...@@ -39,20 +40,14 @@ def schedule_generator(agents: List[EnvAgent], config_speeds: List[float], dist
shortest_paths_lengths = [len(v) for k,v in shortest_paths.items()] shortest_paths_lengths = [len(v) for k,v in shortest_paths.items()]
# Find mean_shortest_path_time # Find mean_shortest_path_time
agent_shortest_path_times = [] agent_speeds = [agent.speed_data['speed'] for agent in agents]
for agent in agents: agent_shortest_path_times = np.array(shortest_paths_lengths)/ np.array(agent_speeds)
speed = agent.speed_data['speed']
distance = shortest_paths_lengths[agent.handle]
agent_shortest_path_times.append(int(np.ceil(distance / speed)))
mean_shortest_path_time = np.mean(agent_shortest_path_times) mean_shortest_path_time = np.mean(agent_shortest_path_times)
# Deciding on a suitable max_episode_steps # Deciding on a suitable max_episode_steps
max_sp_len = max(shortest_paths_lengths) # longest path longest_speed_normalized_time = np.max(agent_shortest_path_times)
min_speed = min(config_speeds) # slowest possible speed in config mean_path_delay = mean_shortest_path_time * mean_shortest_path_multiplier
max_episode_steps_new = int(np.ceil(longest_speed_normalized_time * new_max_episode_steps_multiplier) + mean_path_delay)
longest_sp_time = max_sp_len / min_speed
max_episode_steps_new = int(np.ceil(longest_sp_time * new_max_episode_steps_multiplier))
max_episode_steps_old = int(max_episode_steps * old_max_episode_steps_multiplier) max_episode_steps_old = int(max_episode_steps * old_max_episode_steps_multiplier)
...@@ -67,8 +62,7 @@ def schedule_generator(agents: List[EnvAgent], config_speeds: List[float], dist ...@@ -67,8 +62,7 @@ def schedule_generator(agents: List[EnvAgent], config_speeds: List[float], dist
for agent in agents: for agent in agents:
agent_shortest_path_time = agent_shortest_path_times[agent.handle] agent_shortest_path_time = agent_shortest_path_times[agent.handle]
agent_travel_time_max = int(np.ceil((agent_shortest_path_time * travel_buffer_multiplier) \ agent_travel_time_max = int(np.ceil((agent_shortest_path_time * travel_buffer_multiplier) + mean_path_delay))
+ (mean_shortest_path_time * mean_shortest_path_multiplier)))
departure_window_max = max(latest_arrival_max - agent_travel_time_max, 1) departure_window_max = max(latest_arrival_max - agent_travel_time_max, 1)
......
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