Skip to content
Snippets Groups Projects
Commit e9ad2eec authored by u229589's avatar u229589
Browse files

remove variable observation_space since it is not really used anywhere and...

remove variable observation_space since it is not really used anywhere and adjust examples in doc to match the code
parent 2afe31b9
No related branches found
No related tags found
No related merge requests found
......@@ -160,7 +160,7 @@ Once we are set with the environment we can load our preferred agent from either
.. code-block:: python
agent = RandomAgent(env.action_space, env.observation_space)
agent = RandomAgent(state_size, action_size)
We start every trial by resetting the environment
......
......@@ -18,7 +18,7 @@ base class and must implement two methods, :code:`reset(self)` and :code:`get(se
.. _`flatland.core.env_observation_builder.ObservationBuilder` : https://gitlab.aicrowd.com/flatland/flatland/blob/master/flatland/core/env_observation_builder.py#L13
Below is a simple example that returns observation vectors of size :code:`observation_space = 5` featuring only the ID (handle) of the agent whose
Below is a simple example that returns observation vectors of size 5 featuring only the ID (handle) of the agent whose
observation vector is being computed:
.. code-block:: python
......@@ -28,14 +28,12 @@ observation vector is being computed:
Simplest observation builder. The object returns observation vectors with 5 identical components,
all equal to the ID of the respective agent.
"""
def __init__(self):
self.observation_space = [5]
def reset(self):
return
def get(self, handle):
observation = handle * np.ones((self.observation_space[0],))
observation = handle * np.ones(5)
return observation
We can pass an instance of our custom observation builder :code:`SimpleObs` to the :code:`RailEnv` creator as follows:
......@@ -85,7 +83,6 @@ Note that this simple strategy fails when multiple agents are present, as each a
super().__init__(max_depth=0)
# We set max_depth=0 in because we only need to look at the current
# position of the agent to decide what direction is shortest.
self.observation_space = [3]
def reset(self):
# Recompute the distance map, if the environment has changed.
......@@ -189,7 +186,6 @@ In contrast to the previous examples we also implement the :code:`def get_many(s
def __init__(self, predictor):
super().__init__(max_depth=0)
self.observation_space = [10]
self.predictor = predictor
def reset(self):
......
......@@ -18,7 +18,6 @@ class SimpleObs(ObservationBuilder):
def __init__(self):
super().__init__()
self.observation_space = [5]
def reset(self):
return
......
......@@ -28,7 +28,6 @@ class SingleAgentNavigationObs(ObservationBuilder):
def __init__(self):
super().__init__()
self.observation_space = [3]
def reset(self):
pass
......
......@@ -28,7 +28,6 @@ class ObservePredictions(ObservationBuilder):
def __init__(self, predictor):
super().__init__()
self.observation_space = [10]
self.predictor = predictor
def reset(self):
......
......@@ -25,7 +25,6 @@ class SingleAgentNavigationObs(ObservationBuilder):
def __init__(self):
super().__init__()
self.observation_space = [3]
def reset(self):
pass
......
......@@ -11,7 +11,6 @@ class Environment:
Derived environments should implement the following attributes:
action_space: tuple with the dimensions of the actions to be passed to the step method
observation_space: tuple with the dimensions of the observations returned by reset and step
Agents are identified by agent ids (handles).
Examples:
......@@ -46,7 +45,6 @@ class Environment:
def __init__(self):
self.action_space = ()
self.observation_space = ()
pass
def reset(self):
......
......@@ -18,13 +18,9 @@ from flatland.core.env import Environment
class ObservationBuilder:
"""
ObservationBuilder base class.
Derived objects must implement and `observation_space` attribute as a tuple with the dimensions of the returned
observations.
"""
def __init__(self):
self.observation_space = ()
self.env = None
def set_env(self, env: Environment):
......
......@@ -42,13 +42,6 @@ class TreeObsForRailEnv(ObservationBuilder):
super().__init__()
self.max_depth = max_depth
self.observation_dim = 11
# Compute the size of the returned observation vector
size = 0
pow4 = 1
for i in range(self.max_depth + 1):
size += pow4
pow4 *= 4
self.observation_space = [size * self.observation_dim]
self.location_has_agent = {}
self.location_has_agent_direction = {}
self.predictor = predictor
......@@ -508,12 +501,10 @@ class GlobalObsForRailEnv(ObservationBuilder):
"""
def __init__(self):
self.observation_space = ()
super(GlobalObsForRailEnv, self).__init__()
def set_env(self, env: Environment):
super().set_env(env)
self.observation_space = [4, self.env.height, self.env.width]
def reset(self):
self.rail_obs = np.zeros((self.env.height, self.env.width, 16))
......
......@@ -178,7 +178,6 @@ class RailEnv(Environment):
self.distance_map = DistanceMap(self.agents, self.height, self.width)
self.action_space = [1]
self.observation_space = self.obs_builder.observation_space # updated on resets?
# Stochastic train malfunctioning parameters
if stochastic_data is not None:
......@@ -288,7 +287,6 @@ class RailEnv(Environment):
# Reset the state of the observation builder with the new environment
self.obs_builder.reset()
self.observation_space = self.obs_builder.observation_space # <-- change on reset?
self.distance_map.reset(self.agents, self.rail)
# Return the new observation vectors for each agent
......
......@@ -22,7 +22,6 @@ class SingleAgentNavigationObs(ObservationBuilder):
def __init__(self):
super().__init__()
self.observation_space = [3]
def reset(self):
pass
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment