From Ice Shows to Algorithms: Cracking the Truck-Packing Problem

My first full-time programming job was for Holiday on Ice, an international ice show. While I focused mainly on back office systems such as accounting, itinerary, and box office reporting, I knew that one of the biggest technical challenges faced by the show’s crew was efficiently loading trucks for the next city.
“Given the dimensions of a truck and a list of containers (with their dimensions and weight), in what order, position, and orientation should you pack the truck?”
One day, the controller asked me if I could code a system that took, as input, the trucks’ 3D dimensions and the 3D dimensions (and weight) of every object to be packed. Back in the Turbo Pascal era, exploring 3D packing was painful. Today, with Python and AI-assisted scaffolding, it’s surprisingly approachable.
This same problem shows up anywhere people need to fit things into finite 3D spaces:
- Air cargo: Loading Unit Load Devices (ULDs - aircraft pallets and containers)
- Concert tours: Packing road cases into trailers and stage trucks
- E-commerce fulfillment: Fitting cartons onto pallets and into shipping containers
- Furniture / equipment moves: Loading mixed-size items into moving trucks or pods
- Shipping & logistics: Optimizing Less-Than-Truckload (LTL) and Full-Truckload (FTL) loads
- Warehouse slotting: Assigning products to rack/bin locations to balance space use and picking efficiency
The Thought Experiment
Imagine a truck interior sized H × W × D (height, width, depth) and a set of boxes with height, width, depth, and weight. The challenge:
- Maximize space usage while avoiding overlap.
- Respect the truck bounds (no sticking out).
- Optionally consider weight and stacking rules.
Real-world simple? Not really. Computationally, it’s a classic 3D bin-packing problem. On the scale of computational complexity, this problem is extremely difficult (NP-hard), meaning there’s no known fast way to always find the perfect solution. Instead, we rely on heuristics, which are clever shortcuts that deliver good (though not guaranteed optimal) results quickly.
It’s like trying to figure out every possible way to load groceries into your car trunk. You could test every arrangement, but that would take forever, so instead you look for smart tricks to get a good result quickly. Tricks such as loading heavy items first, stacking boxes neatly, and filling gaps with small bags.
Modeling the Packing Problem
To simulate the problem, we make the following simplifications:
Assumptions:
- The truck is a perfect cuboid with fixed dimensions.
- Each box is also a cuboid with (height, width, depth, weight).
- Boxes may only be rotated in axis-aligned orientations (6 total).
- Free space is tracked as rectangular subspaces (split after each placement).
- Goal: maximize volume utilization, while optionally considering stacking rules.
Using AI to Scaffold the Code
I start by prompting an AI model to sketch out a basic packing algorithm:
Write a Python script that, given the dimensions of a truck (height, width, depth) and a dictionary of objects with height, width, depth, and weight, produces a packing order. The script should output 3D positions and orientations for each object.
The model produces a working draft. As with most AI-generated code, it needs refinement so blocks don’t float or extend beyond the truck’s limits. These edits include better variable and function naming, clearer placement logic, and fixing layout issues. Still, this first generation saves me hours of scaffolding and gives me a strong foundation to improve upon. What follows is the refined version.
|
|
Simulation: Packing a Truck
Once the function exists, I test it with a sample truck definition and a dictionary of sample items:
Write example code that defines a truck, provides a dictionary of items with height, width, depth, and weight, and prints the resulting packing plan.
The model produces usable code that I edit for clarity and readability.
|
|
Sample Output:
The packing function produces a sequential plan showing where each crate ends up, including its 3D position, size, and weight. Each line corresponds to one item in the truck, listed in the order it was placed.
|
|
Making the Results Visual

By plotting the packed truck, we move beyond raw placement data and can see whether the packing logic produces a layout that makes sense in three dimensions. A list of coordinates and sizes may be correct mathematically, but it’s not easy to judge efficiency or orientation without a visual check. A 3D plot gives immediate feedback on how the boxes sit within the container: whether they fit, whether they stack as expected, and how well the available space is being used. This makes it much easier to spot mistakes in the algorithm, such as items standing on the wrong axis, overlapping, or leaving gaps that should have been filled.
The plotting function directly supports this goal by turning the abstract placement data into a clear visual model. The prompt I use ensures that the visualization is both accurate and interpretable. By assigning each box its own color and labeling it at its center, the plot highlights how individual items relate to the container and to each other. In this way, the visualization is not just a cosmetic step, but an integral part of validating and improving the packing heuristic.
Write a Python function that takes a truck’s dimensions and the placements list, and plots the packed truck in 3D using Matplotlib. Each box should have a unique color and label.
The plot_truck_packing
function is responsible for visualizing how items are arranged inside the truck. It begins by drawing a wireframe of the container using width, depth, and height as the three axes. It then loops through each placed item, calls _cuboid_faces_mpl_from_internal
to generate the six visible faces of the box in Matplotlib’s coordinate system, and renders them as colored 3D shapes. Labels are added at the center of each item for clarity, and the axes are labeled and scaled so the proportions match the truck’s real dimensions. Finally, the viewing angle, aspect ratio, and title are set to produce a clear, accurate perspective of the packed load.
|
|
What We Learned
So what did we actually learn from tackling this truck-packing problem with AI? First, prompt engineering really does matter. The clearer and more constrained the prompt, the closer the AI’s first draft will be to something usable, saving time on rework.
Second, we should remember that this is an NP-hard problem. No matter how clever we are, we’re not going to get perfect solutions every time. Therefore, the practical goal is heuristics that give us “good enough” answers fast.
Finally, we saw how greedy placement rules and guillotine-style splits can provide practical packing strategies, and how visualization is key to making the results feel intuitive rather than just lines of coordinates.
Exercises for the Reader
The best way to internalize a concept like 3D packing is to get your hands dirty. The following exercises encourage you to tweak the algorithm, adjust the inputs, and even rethink the heuristics. By experimenting, you’ll see firsthand how small changes in assumptions or constraints can dramatically affect the packing efficiency.
Beginner Level: Quick Fixes & Calibration
Add weight limits: don’t allow heavy crates to stack on fragile ones.
Track utilization percentage after each placement.
Intermediate Level: Geometry & Body Modeling
Allow full box rotations (beyond axis-aligned).
Experiment with different scoring heuristics (e.g., minimize height first).
Advanced Level: Environment & Stochasticity
Implement simulated annealing or genetic algorithms to search better packings.
Add real-world rules like axle load balancing or fragile stacking.
Scale up to thousands of boxes with Monte Carlo heuristics.
Final Thoughts
Packing trucks may seem like grunt work, but it’s really a microcosm of optimization problems: finite resources, constraints, tradeoffs. The thrill of solving them, especially with today’s AI scaffolding, is the same thrill that first drew me to programming back at Holiday on Ice.