From f3cfd61bb4b54e357afb1328a44bb0c2b4f4cf18 Mon Sep 17 00:00:00 2001 From: "S.P. Mohanty" <spmohanty91@gmail.com> Date: Tue, 8 Oct 2019 04:03:15 +0200 Subject: [PATCH] Move random seeding of RailEnv to the reset function --- flatland/envs/rail_env.py | 13 ++++--------- requirements_dev.txt | 1 + 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/flatland/envs/rail_env.py b/flatland/envs/rail_env.py index 2c5f4be2..bf438a56 100644 --- a/flatland/envs/rail_env.py +++ b/flatland/envs/rail_env.py @@ -119,8 +119,7 @@ class RailEnv(Environment): obs_builder_object: ObservationBuilder = TreeObsForRailEnv(max_depth=2), max_episode_steps=None, stochastic_data=None, - remove_agents_at_target=False, - random_seed=None + remove_agents_at_target=False ): """ Environment init. @@ -154,9 +153,6 @@ class RailEnv(Environment): remove_agents_at_target : bool If remove_agents_at_target is set to true then the agents will be removed by placing to RailEnv.DEPOT_POSITION when the agent has reach it's target position. - random_seed : int or None - if None, then its ignored, else the random generators are seeded with this number to ensure - that stochastic operations are replicable across multiple operations """ super().__init__() @@ -192,9 +188,6 @@ class RailEnv(Environment): self.action_space = [1] self._seed() - self.random_seed = random_seed - if self.random_seed: - self._seed(seed=random_seed) # Stochastic train malfunctioning parameters if stochastic_data is not None: @@ -255,11 +248,13 @@ class RailEnv(Environment): """ self.agents = EnvAgent.list_from_static(self.agents_static) - def reset(self, regen_rail=True, replace_agents=True, activate_agents=False): + def reset(self, regen_rail=True, replace_agents=True, activate_agents=False, random_seed=None): """ if regen_rail then regenerate the rails. if replace_agents then regenerate the agents static. Relies on the rail_generator returning agent_static lists (pos, dir, target) """ + if random_seed: + self._seed(random_seed) # TODO https://gitlab.aicrowd.com/flatland/flatland/issues/172 # can we not put 'self.rail_generator(..)' into 'if regen_rail or self.rail is None' condition? diff --git a/requirements_dev.txt b/requirements_dev.txt index e02da216..b71ad949 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -20,3 +20,4 @@ six>=1.12.0 timeout-decorator>=0.4.1 attrs ushlex +gym==0.14.0 -- GitLab