From d5ab5be7a4266e9fe6ad15fbe46bf775e9ed9a23 Mon Sep 17 00:00:00 2001
From: MLErik <baerenjesus@gmail.com>
Date: Mon, 30 Sep 2019 20:35:40 -0400
Subject: [PATCH] removing agent when they cannot be faced correctly

---
 examples/flatland_2_0_example.py     | 2 +-
 flatland/envs/schedule_generators.py | 7 +++++++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/examples/flatland_2_0_example.py b/examples/flatland_2_0_example.py
index 2a6d90b0..7916c4e5 100644
--- a/examples/flatland_2_0_example.py
+++ b/examples/flatland_2_0_example.py
@@ -91,7 +91,7 @@ action_dict = dict()
 print("Start episode...")
 # Reset environment and get initial observations for all agents
 obs = env.reset()
-
+print(env.get_num_agents(), )
 # Reset the rendering sytem
 env_renderer.reset()
 
diff --git a/flatland/envs/schedule_generators.py b/flatland/envs/schedule_generators.py
index 85fb380a..1e94ef27 100644
--- a/flatland/envs/schedule_generators.py
+++ b/flatland/envs/schedule_generators.py
@@ -89,10 +89,17 @@ def sparse_schedule_generator(speed_ratio_map: Mapping[float, float] = None) ->
                 track_to_use = 0
             else:
                 track_to_use = 1
+
             for i in range(len(start_slots[current_start_node])):
                 if start_slots[current_start_node][i][1] == track_to_use:
                     start_station_idx = i
                     break
+                else:
+                    start_station_idx = None
+
+            if start_station_idx is None:
+                warnings.warn("No slot available with required start orientation")
+                continue
             start = start_slots[current_start_node][start_station_idx]
             start_slots[current_start_node].pop(start_station_idx)
 
-- 
GitLab