JobShop
Bases: Environment[State, MultiDiscreteArray, Observation]
The Job Shop Scheduling Problem, as described in [1], is one of the best known
combinatorial optimization problems. We are given num_jobs
jobs, each consisting
of at most max_num_ops
ops, which need to be processed on num_machines
machines.
Each operation (op) has a specific machine that it needs to be processed on and a
duration (which must be less than or equal to max_duration_op
). The goal is to
minimise the total length of the schedule, also known as the makespan.
[1] https://developers.google.com/optimization/scheduling/job_shop.
-
observation:
Observation
- ops_machine_ids: jax array (int32) of (num_jobs, max_num_ops) id of the machine each operation must be processed on.
- ops_durations: jax array (int32) of (num_jobs, max_num_ops) processing time of each operation.
- ops_mask: jax array (bool) of (num_jobs, max_num_ops) indicating which operations have yet to be scheduled.
- machines_job_ids: jax array (int32) of shape (num_machines,) id of the job (or no-op) that each machine is processing.
- machines_remaining_times: jax array (int32) of shape (num_machines,) specifying, for each machine, the number of time steps until available.
- action_mask: jax array (bool) of shape (num_machines, num_jobs + 1) indicates which job(s) (or no-op) can legally be scheduled on each machine.
-
action: jax array (int32) of shape (num_machines,).
-
reward: jax array (float) of shape (). A reward of
-1
is given each time step. If all machines are simultaneously idle or the agent selects an invalid action, the agent is given a large penalty of-num_jobs * max_num_ops * max_op_duration
which is an upper bound on the makespan. -
episode termination:
- Finished schedule: all operations (and thus all jobs) every job have been processed.
- Illegal action: the agent ignores the action mask and takes an illegal action.
- Simultaneously idle: all machines are inactive at the same time.
-
state:
State
- ops_machine_ids: same as observation.
- ops_durations: same as observation.
- ops_mask: same as observation.
- machines_job_ids: same as observation.
- machines_remaining_times: same as observation.
- action_mask: same as observation.
- step_count: jax array (int32) of shape (), the number of time steps in the episode so far.
- scheduled_times: jax array (int32) of shape (num_jobs, max_num_ops), specifying the timestep at which every op (scheduled so far) was scheduled.
1 2 3 4 5 6 7 8 |
|
Instantiate a JobShop
environment.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
generator
|
Optional[Generator]
|
|
None
|
viewer
|
Optional[Viewer[State]]
|
|
None
|
Source code in jumanji/environments/packing/job_shop/env.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
|
action_spec: specs.MultiDiscreteArray
cached
property
#
Specifications of the action in the JobShop
environment. The action gives each
machine a job id ranging from 0, 1, ..., num_jobs where the last value corresponds
to a no-op.
Returns:
Name | Type | Description |
---|---|---|
action_spec |
MultiDiscreteArray
|
a |
observation_spec: specs.Spec[Observation]
cached
property
#
Specifications of the observation of the JobShop
environment.
Returns:
Type | Description |
---|---|
Spec[Observation]
|
Spec containing the specifications for all 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 Jobshop 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/job_shop/env.py
451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 |
|
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/job_shop/env.py
443 444 445 446 447 448 449 |
|
render(state)
#
Render the given state of the environment. This rendering shows which job (or no-op) is running on each machine for the current time step and previous time steps.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
state
|
State
|
|
required |
Source code in jumanji/environments/packing/job_shop/env.py
434 435 436 437 438 439 440 441 |
|
reset(key)
#
Resets the environment by creating a new problem instance and initialising the state and timestep.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
PRNGKey
|
random key used to reset the environment. |
required |
Returns:
Name | Type | Description |
---|---|---|
state |
State
|
the environment state after the reset. |
timestep |
TimeStep[Observation]
|
the first timestep returned by the environment after the reset. |
Source code in jumanji/environments/packing/job_shop/env.py
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
|
step(state, action)
#
Updates the status of all machines, the status of the operations, and increments the time step. It updates the environment state and the timestep (which contains the new observation). It calculates the reward based on the three terminal conditions: - The action provided by the agent is invalid. - The schedule has finished. - All machines do a no-op that leads to all machines being simultaneously idle.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
state
|
State
|
the environment state. |
required |
action
|
Array
|
the action to take. |
required |
Returns:
Name | Type | Description |
---|---|---|
state |
State
|
the updated environment state. |
timestep |
TimeStep[Observation]
|
the updated timestep. |
Source code in jumanji/environments/packing/job_shop/env.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 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 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
|