Extra material: Strip packing
Strip packing (SP) refers to the problem of packing rectangles onto a 2-dimensional strip of fixed width.
Many variants of this problem have been studied, the most basic is the pack a set of rectangles onto the shortest possible strip without rotation. Other variants allow rotation of the rectangles, require a packing that allows cutting the rectangles out of the strip with edge-to-edge cuts (guillotine packing), extends the strip to three dimensions, or extends the packing to non-rectangular shapes.
The extensive study of strip packing problems is motivated by their many industrial applications including
placement of macro cells in semiconductor layouts,
wood and textile cutting operations,
laying out workstations in manufacturing facilities,
allocating communications bandwidth between two endpoints,
planning and scheduling utilization for enhanced oil recovery,
scheduling allocations of a common resource.
Finding optimal solutions to strip packing problems is combinatorially difficult. Strip packing belongs to a class of problems called "NP-hard" for which known solution algorithms require effort that grows exponentially with problem size. For that reason much research on strip packing has been directed towards practical heuristic algorithms for finding good, though not optimal, for industrial applications.
In this notebook, we illustrate Pyomo models to find optimal solutions to smaller but economically relevant problems. We use the problem of packing boxes onto the shortest possible shelf of fixed depth.
Preamble: Install Pyomo and a solver
The following cell sets and verifies a global SOLVER for the notebook. If run on Google Colab, the cell installs Pyomo and the HiGHS solver, while, if run elsewhere, it assumes Pyomo and HiGHS have been previously installed. It then sets to use HiGHS as solver via the appsi module and a test is performed to verify that it is available. The solver interface is stored in a global object SOLVER for later use.
Problem Statment
Assume you are given a collection of boxes, whose dimensions are for . These boxes are to placed on shelf of depth . The boxes can be rotated, if needed, to fit on the shelf. How wide of a shelf is needed?
We will start by creating a function to generate a table of boxes. For concreteness, we assume the dimensions are in millimeters.
A lower and upper bounds on shelf width
A lower bound on the shelf width can be obtained by dividing the total area required to place all boxes on the shelf by the shelf depth. The area of box is , therefore the lower bound is given by
An upper bound on the shelf width can be obtained aligning the boxes along the front of the shelf without rotation. To set the stage for later calculations, the position of box on the shelf is defined by the coordinates and , corresponding to the lower left corner and the upper right corner, respectively.
The two set of coordinates of box are linked to the width and depth by the following equations:
An additional binary variable designates whether the rectangle has been rotated, with denoting no rotation and denoting a 90 degree rotation (all other rotations yield one of these two configurations).
The following cell create and display a data frame showing the bounding boxes and performs calculations to obtain the trivial box arrangement, as well as the lower and upper bounds.
Modeling Strategy
At this point, one may have some ideas on how to efficiently pack boxes on the shelf. For example, one might start by placing the larger boxes to left edge of the shelf, then rotating and placing the smaller boxes with a goal of minimized the occupied with of the shelf.
Optimization takes a different, less algorithmic approach. The strategy is to describe constraints that must be satisfied for any solution to the problem, then let the solver find the values of the decision variables that minimizes the shelf width. The constraints include:
The bounding boxes must fit within the boundaries of the shelf, and to the left of vertical line drawn at , where the shelf width is a decision variable.
The boxes can be rotated 90 degrees.
The boxes must not overlap in either the or dimensions.
Version 1: A Pyomo model to line up the boxes
For this first Pyomo model we look to reproduce a lineup of the boxes on the shelf. In the case the problem is to minimize where
This first model does not consider rotation or placement of the boxes in the dimension, so those decisions are not included.
The disjunctive constraints specify relationships between and to prevent overlapping positions of boxes on the shelf. The disjunctions require that either that box is to the left of box or that box is the left of box . This is specified as an exclusive or disjunction because both conditions can be true at the same time. This disjunctive relationship must hold for every pair of boxes that are different from each other, but specifying doesn't overlap with assures doesn't overlap . So it is only necessary to specify disjunctions for all pairs where .
The corresponding Pyomo model is a direct implementation of this model. One feature of the implementation is the use of a set m.PAIRS to identify the disjunctions. Defining this set simplifies coding for the corresponding disjunction.
The solution that we found is not better than the upper bound. This is not surprising, since we did not consider rotation of the boxes.
Version 2: Rotating boxes
Rotating the boxes is an option for packing the boxes more tightly on the shelf. The boxes can be placed either in their original orientation or in a rotated orientation. This introduces a second exclusive OR disjunction to the model that determines the orientation of the bounding box. A binary indicator variable tracks which boxes were rotated which is used in the show_boxes function to show which boxes have been rotated.
In this version of the model, the boxes will be lined up against the edge of the shelf with . Decision variables are now included in the model for rotation to the dimension of the bounding boxes.
Version 3: Placing and Rotating boxes in two dimensions
Obviously the packages can be packed closer together by allowing boxes to be stacked deeper into the shelf. New constraints are needed to maintain the bounding boxes within the shelf depth, and to avoid overlaps in the dimension.
Advanced Topic: Symmetry Breaking
One of the issues in combinatorial problem is the challenge of symmetries. A symmetry is a situation where a change in solution configuration leaves the objective unchanged. Strip packing problems are especially susceptible to symmetries. Symmetries can significantly increase the effort needed to find and verify an optimal solution. In [1], Trespalacios and Grossmann introduced a modification to the strip packing problem to reduce the number of symmetries. We implement this new model formulation in Pyomo in the following cell.
[1] Trespalacios, F., & Grossmann, I. E. (2017). Symmetry breaking for generalized disjunctive programming formulation of the strip packing problem. Annals of Operations Research, 258(2), 747-759. DOI 10.1007/s10479-016-2112-9