I’m trying to build a Python script to return the optimal packing of different values into a set value sum. The end goal is to make a tool that can take the wholesale Length of a building material (e.g. Rebar (sold in 20′ sections) or Aluminum Extrusion (sold in 16′ sections)) and input specific pieces specified by a design (e.g. the design calls for 2 x 4-1/4″ sections, 5 x 48-1/2″, and 4 x 24-3/8″ pieces). The goal is to reduce wastage by varying the arrangement and how many plans are built (e.g., multiple houses, cabinets, or picture frames). I’m trying to find out what the optimal bulk quantity of the plan to offer to reduce material wastage.
Here’s a simple example of a picture frame:
The picture frame is a rectangle and needs only 4 pieces (1 per side). The left and right pieces are 5″ long, and the top and bottom pieces are 3″ long. If the material used is sold in 8′ sections, what would the optimal organization and number of picture-frames be to reduce wastage (below 100 pieces, to put an upper limit on it)?
2 x 5″ Pieces
2 x 3″ Pieces
Sold in 8″ (96″) Lengths
piecelens = [5, 5, 3, 3] wholesalelen = 96
Solve for layout of pieces on 8′ sections
FOR AN optimal number of picture frames to make
WITH THE GOAL OF Reducing wasted material (unused)
AND Keeping number of picture frames below 100
Real usages would include more than just two different lengths and fractional(or decimal equiv.) lengths, like this:
A metal enclosure made of aluminum extrusion needs an upper and lower frame that fit into each other. The bottom frame is a smaller rectangle where the left and right pieces are 48-1/8″ long, and the top and bottom pieces are 24-1/8″ long. The top frame is a larger rectangle where the left and right pieces are 48-3/16″ long, and the top and bottom pieces are 24-3/16″ long. The box also needs braces for each corner made of the same material that end up being 1-7/16″ long. If the extrusion is sold in 16′ sections, what would the optimal organization and number of enclosures to build at a time to minimize material wastage (below a quantity of 20) and (below a quantity of 200).
2 x 48-1/8″ pieces
2 x 24-1/8″ pieces
2 x 48-3/16″ pieces
2 x 24-3/16″ pieces
4 x 1-7/16″ pieces
Sold in 16′ (192″) Lengths
piecelens = [48.125, 48.125, 24.125, 24.125, 48.1875, 48.1875, 24.1875, 24.1875, 1.4375, 1.4375, 1.4375, 1.4375] wholesalelen = 192
Solve for layout of pieces on 16′ sections
FOR AN optimal number of enclosures to make
WITH THE GOAL OF Reducing wasted material (unused)
AND Keeping number of enclosures below 20
REPEAT for a number of enclosures below 200
I have a fairly good grasp of python, but not enough math background to even know where to start. I looked up similar examples of packing problems, but all the answers I found were well above my math understanding and seemed to be for 2d or 3d applications, where I only need a 1d application (length of material only). I was hoping there was a simpler model for 1d applications, although I’m not sure. My research into Bin-Packing problem (which seemed similar) was interesting, but I don’t understand it enough to implement it for my scenario (in 1 dimension and where the set of pieces is variable by a discrete factor). Any help would be greatly appreciated!
Sean Pragmatic is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.