From 324a397e3af66bb4b54d48e5052e8698499de407 Mon Sep 17 00:00:00 2001 From: MLErik <baerenjesus@gmail.com> Date: Fri, 25 Oct 2019 17:28:50 -0400 Subject: [PATCH] updated agent fixed behavior --- flatland/envs/agent_utils.py | 3 ++- flatland/envs/rail_env.py | 11 +++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/flatland/envs/agent_utils.py b/flatland/envs/agent_utils.py index 6a0e595b..975bfe70 100644 --- a/flatland/envs/agent_utils.py +++ b/flatland/envs/agent_utils.py @@ -64,7 +64,8 @@ class EnvAgentStatic(object): malfunction_datas.append({'malfunction': 0, 'malfunction_rate': schedule.agent_malfunction_rates[i] if schedule.agent_malfunction_rates is not None else 0., 'next_malfunction': 0, - 'nr_malfunctions': 0}) + 'nr_malfunctions': 0, + 'fixed':False}) return list(starmap(EnvAgentStatic, zip(schedule.agent_positions, schedule.agent_directions, diff --git a/flatland/envs/rail_env.py b/flatland/envs/rail_env.py index 32135f11..fa2301b8 100644 --- a/flatland/envs/rail_env.py +++ b/flatland/envs/rail_env.py @@ -407,13 +407,16 @@ class RailEnv(Environment): return True # Restart fixed agents - - - if agent.malfunction_data['malfunction'] < 1 and agent.malfunction_data['next_malfunction'] > 0: + if agent.malfunction_data['malfunction'] < 1 and agent.malfunction_data['next_malfunction'] > 0 and not agent.malfunction_data['fixed']: agent.malfunction_data['next_malfunction'] -= 1 + agent.malfunction_data['fixed'] = True if 'moving_before_malfunction' in agent.malfunction_data: self.agents[i_agent].moving = agent.malfunction_data['moving_before_malfunction'] return False + # Agent has been running smoothly + elif agent.malfunction_data['malfunction'] < 1 and agent.malfunction_data['next_malfunction'] > 0: + agent.malfunction_data['next_malfunction'] -= 1 + return False # Break agents that have next_malfunction if agent.malfunction_data['malfunction'] < 1 and agent.malfunction_data['next_malfunction'] < 1: @@ -436,7 +439,7 @@ class RailEnv(Environment): if agent.malfunction_data['next_malfunction'] > 0 and agent.malfunction_data['malfunction'] < 1: agent.malfunction_data['next_malfunction'] -= 1 - return False + def step(self, action_dict_: Dict[int, RailEnvActions]): """ -- GitLab