diff --git a/examples/training_example.py b/examples/training_example.py index ad8396a57c705dd99ab679c0cb76b688c9e99c75..218f133efe4e79064ae94b24c61aa2d6f2ce2d09 100644 --- a/examples/training_example.py +++ b/examples/training_example.py @@ -16,7 +16,7 @@ env = RailEnv(width=20, height=20, rail_generator=complex_rail_generator(nr_start_goal=10, nr_extra=1, min_dist=8, max_dist=99999, seed=0), obs_builder_object=TreeObservation, - number_of_agents=1) + number_of_agents=2) # Import your own Agent or use RLlib to train agents on Flatland diff --git a/flatland/envs/observations.py b/flatland/envs/observations.py index b4925024c7717e7673b52a593f9a735fc9f001e1..931fabc7c9e9b4f42b659490c8b3cbd43cb11596 100644 --- a/flatland/envs/observations.py +++ b/flatland/envs/observations.py @@ -334,18 +334,24 @@ class TreeObsForRailEnv(ObservationBuilder): int_position = coordinate_to_position(self.env.width, [position]) pre_step = max(0, num_steps - 1) post_step = min(self.max_prediction_depth - 1, num_steps + 1) + # Look for opposing paths at distance num_step if int_position in np.delete(self.predicted_pos[num_steps], handle): - conflicting_agent = np.where(np.delete(self.predicted_pos[num_steps], handle) == int_position)[0][0] - if direction != self.predicted_dir[num_steps][conflicting_agent]: - potential_conflict = 1 + conflicting_agent = np.where(np.delete(self.predicted_pos[num_steps], handle) == int_position) + for ca in conflicting_agent: + if direction != self.predicted_dir[num_steps][ca[0]]: + potential_conflict = 1 + # Look for opposing paths at distance num_step-1 elif int_position in np.delete(self.predicted_pos[pre_step], handle): - conflicting_agent = np.where(np.delete(self.predicted_pos[pre_step], handle) == int_position)[0][0] - if direction != self.predicted_dir[pre_step][conflicting_agent]: - potential_conflict = 1 + conflicting_agent = np.where(self.predicted_pos[pre_step] == int_position) + for ca in conflicting_agent: + if direction != self.predicted_dir[pre_step][ca[0]]: + potential_conflict = 1 + # Look for opposing paths at distance num_step+1 elif int_position in np.delete(self.predicted_pos[post_step], handle): - conflicting_agent = np.where(np.delete(self.predicted_pos[post_step], handle) == int_position)[0][0] - if direction != self.predicted_dir[post_step][conflicting_agent]: - potential_conflict = 1 + conflicting_agent = np.where(np.delete(self.predicted_pos[post_step], handle) == int_position) + for ca in conflicting_agent: + if direction != self.predicted_dir[post_step][ca[0]]: + potential_conflict = 1 if position in self.location_has_target and position != agent.target: if num_steps < other_target_encountered: