diff --git a/flatland/core/env.py b/flatland/core/env.py index 32691f507f4cb5586f10b5645cc22ece718edc21..3618d965a39b5a71fd1cf24aa81f2f876d5c6365 100644 --- a/flatland/core/env.py +++ b/flatland/core/env.py @@ -99,12 +99,6 @@ class Environment: """ raise NotImplementedError() - def render(self): - """ - Perform rendering of the environment. - """ - raise NotImplementedError() - def get_agent_handles(self): """ Returns a list of agents' handles to be used as keys in the step() diff --git a/flatland/core/env_observation_builder.py b/flatland/core/env_observation_builder.py index b30c2b1f5ddab079c9b6c41e35f03c69ed4162c3..53e7a068b73f9907217777251bce0fdd704603be 100644 --- a/flatland/core/env_observation_builder.py +++ b/flatland/core/env_observation_builder.py @@ -30,6 +30,27 @@ class ObservationBuilder: """ raise NotImplementedError() + def get_many(self, handles=[]): + """ + Called whenever an observation has to be computed for the `env' environment, for each agent with handle + in the `handles' list. + + Parameters + ------- + handles : list of handles (optional) + List with the handles of the agents for which to compute the observation vector. + + Returns + ------- + function + A dictionary of observation structures, specific to the corresponding environment, with handles from + `handles' as keys. + """ + observations = {} + for h in handles: + observations[h] = self.get(h) + return observations + def get(self, handle=0): """ Called whenever an observation has to be computed for the `env' environment, possibly diff --git a/flatland/envs/observations.py b/flatland/envs/observations.py index 676051d8338534c704ef98c90bee08a2836d4cfb..f3c0a7c3c06ff27ecd956e1734a6fa33fd1236b3 100644 --- a/flatland/envs/observations.py +++ b/flatland/envs/observations.py @@ -167,6 +167,19 @@ class TreeObsForRailEnv(ObservationBuilder): elif movement == 3: # WEST return (position[0], position[1] - 1) + def get_many(self, handles=[]): + """ + Called whenever an observation has to be computed for the `env' environment, for each agent with handle + in the `handles' list. + """ + + # TODO: @Erik this is where the predictions should be computed, storing any temporary data inside this object. + + observations = {} + for h in handles: + observations[h] = self.get(h) + return observations + def get(self, handle): """ Computes the current observation for agent `handle' in env diff --git a/flatland/envs/rail_env.py b/flatland/envs/rail_env.py index 6cd645147a1a870c760c3bc60dd364903a2065d2..44ed3f770600ba1aae1745926109deb1fa7398ef 100644 --- a/flatland/envs/rail_env.py +++ b/flatland/envs/rail_env.py @@ -330,10 +330,7 @@ class RailEnv(Environment): return new_direction, transition_isValid def _get_observations(self): - self.obs_dict = {} - self.debug_obs_dict = {} - for iAgent in range(self.get_num_agents()): - self.obs_dict[iAgent] = self.obs_builder.get(iAgent) + self.obs_dict = self.obs_builder.get_many(list(range(self.get_num_agents()))) return self.obs_dict def _get_predictions(self): @@ -341,10 +338,6 @@ class RailEnv(Environment): return {} return {} - def render(self): - # TODO: - pass - def get_full_state_msg(self): grid_data = self.rail.grid.tolist() agent_static_data = [agent.to_list() for agent in self.agents_static]