From 2a500b3a1be94992ce2df5b7e7712d7ea407e4f0 Mon Sep 17 00:00:00 2001 From: "Egli Adrian (IT-SCI-API-PFI)" <adrian.egli@sbb.ch> Date: Sat, 25 May 2019 20:13:23 +0200 Subject: [PATCH] added a print.out question : why will an agent not move, once he reach it's destination? May he have to move for passing --- examples/demo.py | 10 ++++++---- flatland/envs/agent_utils.py | 1 - flatland/envs/rail_env.py | 16 +++++++++++----- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/examples/demo.py b/examples/demo.py index b2da6ccb..6c02f355 100644 --- a/examples/demo.py +++ b/examples/demo.py @@ -138,9 +138,12 @@ class Demo: for step in range(max_nbr_of_steps): # Action - for a in range(self.env.get_num_agents()): - action = 2 # np.random.choice(self.action_size) #self.agent.act(agent_obs[a]) - action_dict.update({a: action}) + for iAgent in range(self.env.get_num_agents()): + action = 2 + agent = self.env.agents.copy()[iAgent] + if not self.env.check_action(agent, action)[1]: + action = np.random.choice(self.action_size) + action_dict.update({iAgent: action}) self.renderer.renderEnv(show=True, action_dict=action_dict) @@ -172,7 +175,6 @@ if False: demo_002.run_demo() demo_002 = None - demo_flatland_000 = Demo(Scenario_Generator.load_scenario('./env-data/railway/example_flatland_000.pkl')) demo_flatland_000.renderer.resize() demo_flatland_000.run_demo(1800) diff --git a/flatland/envs/agent_utils.py b/flatland/envs/agent_utils.py index 05f81e43..a5f18f3f 100644 --- a/flatland/envs/agent_utils.py +++ b/flatland/envs/agent_utils.py @@ -4,7 +4,6 @@ from itertools import starmap import numpy as np # from flatland.envs.rail_env import RailEnv - @attrs class EnvDescription(object): n_agents = attrib() diff --git a/flatland/envs/rail_env.py b/flatland/envs/rail_env.py index d4facaf5..e56395f4 100644 --- a/flatland/envs/rail_env.py +++ b/flatland/envs/rail_env.py @@ -4,14 +4,18 @@ Definition of the RailEnv environment and related level-generation functions. Generator functions are functions that take width, height and num_resets as arguments and return a GridTransitionMap object. """ -import numpy as np +### TODO _ this is a global method --> utils or remove later +from inspect import currentframe + import msgpack +import numpy as np from flatland.core.env import Environment -from flatland.envs.observations import TreeObsForRailEnv -from flatland.envs.generators import random_rail_generator -from flatland.envs.env_utils import get_new_position from flatland.envs.agent_utils import EnvAgentStatic, EnvAgent +from flatland.envs.env_utils import get_new_position +from flatland.envs.generators import random_rail_generator +from flatland.envs.observations import TreeObsForRailEnv + # from flatland.core.transitions import Grid8Transitions, RailEnvTransitions # from flatland.core.transition_map import GridTransitionMap @@ -111,7 +115,7 @@ class RailEnv(Environment): self.agents_static = [None] * number_of_agents # static agent information self.num_resets = 0 self.reset() - self.num_resets = 0 # yes, set it to zero again! + self.num_resets = 0 # yes, set it to zero again! self.valid_positions = None @@ -197,6 +201,8 @@ class RailEnv(Environment): continue if self.dones[iAgent]: # this agent has already completed... + print("rail_env.py @", currentframe().f_back.f_lineno, " agent ", iAgent, + "has already completed : why action will not be executed!!!!? ADRIAN") continue action = action_dict[iAgent] -- GitLab