Cleaner
Bases: Environment[State, MultiDiscreteArray, Observation]
A JAX implementation of the 'Cleaner' game where multiple agents have to clean all tiles of a maze.
-
observation:
Observation
- grid: jax array (int8) of shape (num_rows, num_cols) contains the state of the board: 0 for dirty tile, 1 for clean tile, 2 for wall.
- agents_locations: jax array (int32) of shape (num_agents, 2) contains the location of each agent on the board.
- action_mask: jax array (bool) of shape (num_agents, 4) indicates for each agent if each of the four actions (up, right, down, left) is allowed.
- step_count: (int32) the number of step since the beginning of the episode.
-
action: jax array (int32) of shape (num_agents,) the action for each agent: (0: up, 1: right, 2: down, 3: left)
-
reward: jax array (float) of shape () +1 every time a tile is cleaned and a configurable penalty (-0.5 by default) for each timestep.
-
episode termination:
- All tiles are clean.
- The number of steps is greater than the limit.
- An invalid action is selected for any of the agents.
-
state:
State
- grid: jax array (int8) of shape (num_rows, num_cols) contains the current state of the board: 0 for dirty tile, 1 for clean tile, 2 for wall.
- agents_locations: jax array (int32) of shape (num_agents, 2) contains the location of each agent on the board.
- action_mask: jax array (bool) of shape (num_agents, 4) indicates for each agent if each of the four actions (up, right, down, left) is allowed.
- step_count: jax array (int32) of shape () the number of steps since the beginning of the episode.
- key: jax array (uint) of shape (2,) jax random generation key. Ignored since the environment is deterministic.
1 2 3 4 5 6 7 8 |
|
Instantiates a Cleaner
environment.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
generator
|
Optional[Generator]
|
|
None
|
time_limit
|
Optional[int]
|
max number of steps in an episode. Defaults to |
None
|
penalty_per_timestep
|
float
|
the penalty returned at each timestep in the reward. |
0.5
|
viewer
|
Optional[Viewer[State]]
|
|
None
|
Source code in jumanji/environments/routing/cleaner/env.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
|
action_spec: specs.MultiDiscreteArray
cached
property
#
Specification of the action for the Cleaner
environment.
Returns:
Name | Type | Description |
---|---|---|
action_spec |
MultiDiscreteArray
|
a |
observation_spec: specs.Spec[Observation]
cached
property
#
Specification of the observation of the Cleaner
environment.
Returns:
Type | Description |
---|---|
Spec[Observation]
|
Spec for the |
animate(states, interval=200, save_path=None)
#
Creates an animated gif of the Cleaner
environment based on the sequence of states.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
states
|
Sequence[State]
|
sequence of environment states corresponding to consecutive timesteps. |
required |
interval
|
int
|
delay between frames in milliseconds, default to 200. |
200
|
save_path
|
Optional[str]
|
the path where the animation file should be saved. If it is None, the plot will not be saved. |
None
|
Returns:
Type | Description |
---|---|
FuncAnimation
|
animation.FuncAnimation: the animation object that was created. |
Source code in jumanji/environments/routing/cleaner/env.py
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 |
|
close()
#
Perform any necessary cleanup.
Environments will automatically :meth:close()
themselves when
garbage collected or when the program exits.
Source code in jumanji/environments/routing/cleaner/env.py
282 283 284 285 286 287 288 |
|
render(state)
#
Render the given state of the environment.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
state
|
State
|
|
required |
Source code in jumanji/environments/routing/cleaner/env.py
255 256 257 258 259 260 261 |
|
reset(key)
#
Reset the environment to its initial state.
All the tiles except upper left are dirty, and the agents start in the upper left corner of the grid.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
PRNGKey
|
random key used to reset the environment. |
required |
Returns:
Name | Type | Description |
---|---|---|
state |
State
|
|
timestep |
TimeStep[Observation]
|
|
Source code in jumanji/environments/routing/cleaner/env.py
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
|
step(state, action)
#
Run one timestep of the environment's dynamics.
If an action is invalid, the corresponding agent does not move and the episode terminates.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
state
|
State
|
current environment state. |
required |
action
|
Array
|
Jax array of shape (num_agents,). Each agent moves one step in the specified direction (0: up, 1: right, 2: down, 3: left). |
required |
Returns:
Name | Type | Description |
---|---|---|
state |
State
|
|
timestep |
TimeStep[Observation]
|
|
Source code in jumanji/environments/routing/cleaner/env.py
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
|