Skip to content

How do I pack parts on a pallet and unpack them later?

Parts travel together on a pallet and are handled one by one at the end. BATCH makes the pallet and SEPARATE unpacks it. The script packs 60 parts five to a pallet and sends the pallets on a 15-minute trip.

from nagasim import build as nb

# Sixty parts are packed five to a pallet, the pallet travels for 15 minutes, and SEPARATE turns it
# back into its five parts, which then pass one unpacker a minute each. Parts wait in the pallet
# while it fills, so their time in the model is longer than the 15-minute trip.
m = nb.Model(time_limit=500, warmup=0)
m.add_resource(name="Unpacker")
parts = m.create(distribution=nb.Constant(value=2), max_arrivals=60)
pack = m.batch(batch_size=5, batched_entity_type="PALLET")
trip = m.delay(distribution=nb.Constant(value=15))
unpack = m.separate()
parts >> pack >> trip >> unpack >> m.process(resource_name="Unpacker", distribution=nb.Constant(value=1)) >> m.dispose()

summary = m.run(seed=1)["entity_summary"]
print(summary[["Entity Type", "Total Created", "Total Completed", "Avg Time"]].round(1).to_string(index=False))

Save it as recipe-unpack-pallet.py and run it with python. The script seeds itself, so the numbers below are the same on your machine.

Entity Type  Total Created  Total Completed  Avg Time
    DEFAULT             60               60      22.0
     PALLET             12               12      15.0

How it works

  1. m.batch(batch_size=5, batched_entity_type="PALLET") holds parts until five are there, then sends one pallet.
  2. m.separate() releases the five parts again, so 12 pallets give back all 60 parts.
  3. A part waits in the pallet while it fills, so its time in the model is 22 minutes and not 15.

Elements used

Back to all recipes.