BinPack
Bases: Environment[State, MultiDiscreteArray, Observation]
Problem of 3D bin packing, where a set of items have to be placed in a 3D container with the goal of maximizing its volume utilization. This environment only supports 1 bin, meaning it is equivalent to the 3D-knapsack problem. We use the Empty Maximal Space (EMS) formulation of this problem. An EMS is a 3D-rectangular space that lives inside the container and has the following properties: - It does not intersect any items, and it is not fully included into any other EMSs. - It is defined by 2 3D-points, hence 6 coordinates (x1, x2, y1, y2, z1, z2), the first point corresponding to its bottom-left location while the second defining its top-right corner.
-
observation:
Observation
- ems:
EMS
tree of jax arrays (float ifnormalize_dimensions
else int32) each of shape (obs_num_ems,), coordinates of all EMSs at the current timestep. - ems_mask: jax array (bool) of shape (obs_num_ems,) indicates the EMSs that are valid.
- items:
Item
tree of jax arrays (float ifnormalize_dimensions
else int32) each of shape (max_num_items,), characteristics of all items for this instance. - items_mask: jax array (bool) of shape (max_num_items,) indicates the items that are valid.
- items_placed: jax array (bool) of shape (max_num_items,) indicates the items that have been placed so far.
- action_mask: jax array (bool) of shape (obs_num_ems, max_num_items)
mask of the joint action space:
True
if the action (ems_id, item_id) is valid.
- ems:
-
action:
MultiDiscreteArray
(int32) of shape (obs_num_ems, max_num_items).- ems_id: int between 0 and obs_num_ems - 1 (included).
- item_id: int between 0 and max_num_items - 1 (included).
-
reward: jax array (float) of shape (), could be either:
- dense: increase in volume utilization of the container due to packing the chosen item.
- sparse: volume utilization of the container at the end of the episode.
-
episode termination:
- if no action can be performed, i.e. no items fit in any EMSs, or all items have been packed.
- if an invalid action is taken, i.e. an item that does not fit in an EMS or one that is already packed.
-
state:
State
- container: space defined by 2 points, i.e. 6 coordinates.
- ems: empty maximal spaces (EMSs) in the container, each defined by 2 points (6 coordinates).
- ems_mask: array of booleans that indicate the EMSs that are valid.
- items: defined by 3 attributes (x, y, z).
- items_mask: array of booleans that indicate the items that can be packed.
- items_placed: array of booleans that indicate the items that have been placed so far.
- items_location: locations of items in the container, defined by 3 coordinates (x, y, x).
- action_mask: array of booleans that indicate the valid actions, i.e. EMSs and items that can be chosen.
- sorted_ems_indexes: EMS indexes that are sorted by decreasing volume order.
- key: random key used for auto-reset.
1 2 3 4 5 6 7 8 |
|
Instantiates a BinPack
environment.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
generator
|
Optional[Generator]
|
|
None
|
obs_num_ems
|
int
|
number of EMSs (possible spaces in which to place an item) to show to the
agent. If |
40
|
reward_fn
|
Optional[RewardFn]
|
compute the reward based on the current state, the chosen action, the next
state, whether the transition is valid and if it is terminal. Implemented options
are [ |
None
|
normalize_dimensions
|
bool
|
if True, the observation is normalized (float) along each dimension into a unit cubic container. If False, the observation is returned in millimeters, i.e. integers (for both items and EMSs). Default to True. |
True
|
debug
|
bool
|
if True, will add to timestep.extras an |
False
|
viewer
|
Optional[Viewer[State]]
|
|
None
|
Source code in jumanji/environments/packing/bin_pack/env.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
|
action_spec: specs.MultiDiscreteArray
cached
property
#
Specifications of the action expected by the BinPack
environment.
Returns:
Type | Description |
---|---|
MultiDiscreteArray
|
MultiDiscreteArray (int32) of shape (obs_num_ems, max_num_items). |
MultiDiscreteArray
|
|
MultiDiscreteArray
|
|
observation_spec: specs.Spec[Observation]
cached
property
#
Specifications of the observation of the BinPack
environment.
Returns:
Type | Description |
---|---|
Spec[Observation]
|
Spec for the |
Spec[Observation]
|
|
Spec[Observation]
|
|
Spec[Observation]
|
|
Spec[Observation]
|
|
Spec[Observation]
|
|
Spec[Observation]
|
|
animate(states, interval=200, save_path=None)
#
Creates an animated gif of the BinPack
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/packing/bin_pack/env.py
358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 |
|
close()
#
Perform any necessary cleanup.
Environments will automatically :meth:close()
themselves when
garbage collected or when the program exits.
Source code in jumanji/environments/packing/bin_pack/env.py
377 378 379 380 381 382 383 |
|
render(state)
#
Render the given state of the environment.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
state
|
State
|
State object containing the current dynamics of the environment. |
required |
Source code in jumanji/environments/packing/bin_pack/env.py
350 351 352 353 354 355 356 |
|
reset(key)
#
Resets the environment by calling the instance generator for a new instance.
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/packing/bin_pack/env.py
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 |
|
step(state, action)
#
Run one timestep of the environment's dynamics. If the action is invalid, the state is not updated, i.e. the action is not taken, and the episode terminates.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
state
|
State
|
|
required |
action
|
Array
|
jax array (int32) of shape (2,): (ems_id, item_id). This means placing the given
item at the location of the given EMS. If the action is not valid, the flag
|
required |
Returns:
Name | Type | Description |
---|---|---|
state |
State
|
|
timestep |
TimeStep[Observation]
|
|
Source code in jumanji/environments/packing/bin_pack/env.py
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 |
|