From c85e08ee8de55b3e2071983b84c7b61525a1a89b Mon Sep 17 00:00:00 2001
From: MLErik <baerenjesus@gmail.com>
Date: Wed, 30 Oct 2019 14:58:38 -0400
Subject: [PATCH] Refactoring: Intdocued fix_agents function. At each step we
 first check for possible malfunctions. THen we apply them and do all the
 agent steps At the end we look at what agents should be fixed. This lead so
 to:

Current malfunction value says how many step calls are necessary till agent can move again

e.g. malfunction = 2, we have to call step() twice untill the agent can move again.

Code cleanup
---
 examples/introduction_flatland_2_1.py | 4 ++--
 flatland/envs/rail_env.py             | 1 -
 tests/test_utils.py                   | 2 +-
 3 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/examples/introduction_flatland_2_1.py b/examples/introduction_flatland_2_1.py
index 214f0c54..87451ece 100644
--- a/examples/introduction_flatland_2_1.py
+++ b/examples/introduction_flatland_2_1.py
@@ -27,7 +27,7 @@ from flatland.utils.rendertools import RenderTool, AgentRenderVariant
 
 width = 16*7  # With of map
 height = 9*7  # Height of map
-nr_trains = 10  # Number of trains that have an assigned task in the env
+nr_trains = 20  # Number of trains that have an assigned task in the env
 cities_in_map = 20  # Number of cities where agents can start or end
 seed = 14  # Random seed
 grid_distribution_of_cities = False  # Type of city distribution, if False cities are randomly placed
@@ -58,7 +58,7 @@ schedule_generator = sparse_schedule_generator(speed_ration_map)
 # We can furthermore pass stochastic data to the RailEnv constructor which will allow for stochastic malfunctions
 # during an episode.
 
-stochastic_data = {'malfunction_rate': 1000,  # Rate of malfunction occurence of single agent
+stochastic_data = {'malfunction_rate': 5,  # Rate of malfunction occurence of single agent
                    'min_duration': 3,  # Minimal duration of malfunction
                    'max_duration': 20  # Max duration of malfunction
                    }
diff --git a/flatland/envs/rail_env.py b/flatland/envs/rail_env.py
index e1124304..8090cff6 100644
--- a/flatland/envs/rail_env.py
+++ b/flatland/envs/rail_env.py
@@ -427,7 +427,6 @@ class RailEnv(Environment):
 
         """
         if self.np_random.rand() < self._malfunction_prob(rate, len(self.active_agents)):
-            print("Malfunction")
             # Select only from agents that are not done yet
             breaking_agent_idx = self.np_random.choice(self.active_agents)
             breaking_agent = self.agents[breaking_agent_idx]
diff --git a/tests/test_utils.py b/tests/test_utils.py
index ff4948d6..6dfc6239 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -121,7 +121,7 @@ def run_replay_config(env: RailEnv, test_configs: List[ReplayConfig], rendering:
                 agent.malfunction_data['moving_before_malfunction'] = agent.moving
                 agent.malfunction_data['fixed'] = False
             _assert(a, agent.malfunction_data['malfunction'], replay.malfunction, 'malfunction')
-        print(step, agent.moving, agent.malfunction_data['fixed'], agent.malfunction_data['malfunction'])
+        print(step)
         _, rewards_dict, _, info_dict = env.step(action_dict)
         if rendering:
             renderer.render_env(show=True, show_observations=True)
-- 
GitLab