Packing Problems
Using Gurobi
What is packing problems
 Packing problems are a class of optimization problems in mathematics that
involve attempting to pack objects together into containers. The goal is to
either pack a single container as densely as possible or pack all objects
using as few containers as possible.
Examples of Packing Problems
 Packing Commercials into station breaks
 Packing files onto floppy disks (Dvds, CDs, etc.)
 Packing telemetry data into fixed size pockets
 Packing News articles onto a news paper
 Packing a suitcase
Formulation of packing rectangles
using MILP
 A MILP general model:
 𝑧 = 𝑚𝑖𝑛 𝑖=1
𝑁
(𝑚𝑖 ∗ 𝑔 ∗ 𝑦𝑖)
Subject to

𝑤 𝑖
2
+ 𝑥𝑖 < 𝑥𝑗 −
𝑤 𝑗
2
i = 1,…,N j = 1,…,N

𝑤 𝑗
2
+ 𝑥𝑗 < 𝑥𝑖 −
𝑤 𝑖
2
i = 1,…,N j = 1,…,N

ℎ 𝑖
2
+ 𝑦𝑖 < 𝑦𝑗 −
ℎ 𝑗
2
i = 1,…,N j = 1,…,N

ℎ 𝑗
2
+ 𝑦𝑗 < 𝑦𝑖 −
ℎ 𝑖
2
i = 1,…,N j = 1,…,N
 𝑎𝑖𝑗 ∗ 𝑥𝑗 ≥ 𝑏𝑖 i = 1,…,N j = 1,…,N
 Coefficients:
 w – width of ith rectangle
 h – height of ith rectangle
 A = [N,N] = {aij}, (𝑁 × 𝑁) matrix
 b = [N] = N vector
 g- constant variable
 Variables:
 x = [N] = N vector of variables
 y = [N] = N vector of variables
 Where 𝑥, 𝑦 = the lower left
coordinate of rectangle i
Why an MILP model
 Integer and continuous variables are both considered
 If i = j, z is a Integer Programming Problem (ILP)
 If i = 0, z is a Linear Programming Problem (LP)
 The constraints and the objective function are modeled using linear
equalities/inequalities
 Effective solution techniques: Branch & Bound, Branch & Cut, Branch &
Price
 Software available (CPLEX, XPRESS, GLPK, etc)
 Huge problems can be easily solved
MILP model explanation
 MILP Constraints
 The resources used in a optimization problems always limited by a set of
constraints
 MILP Variables
 Variables reflect the resources to be allocated
 MILP Objective Function
 The objective function reflects the optimization aspect of the model
What is Gurobi Optimization
 The Gurobi Optimizer is a commercial optimization solver for
 Linear programming (LP),
 Quadratic programming (QP),
 Quadratical constrained programming (QCP),
 Mixed integer linear programming (MILP)
 Etc
Solving MILP using Gurobi solver
 The data associated with an optimization model must be stored in a
MATLAB struct.
 Fields in this struct contain the different parts of the model.
 A few fields are mandatory:
 the constraint matrix (A),
 the objective vector (obj),
 the right-hand side vector (rhs),
 the constraint sense vector (sense).
 A model can also include optional fields (e.g., the objective sense
model.sense).
Modifying Gurobi parameters
 We must create a struct variable that will be used to modify the Gurobi
parameters
 params.outputflag = 0;
 params.resultfile = ’………’;
 The Gurobi OutputFlag parameter is set to 0 in order to shut off Gurobi
output.
 Also the ResultFile parameter is set to request that Gurobi produce a file as
output
Solving the model
 The result is where the actual optimization occurs:
 result = gurobi(model, params);
 We pass the model and the optional list of parameter changes to the
gurobi() function.
 It computes an optimal solution to the specified model and returns the
computed result.
Printing the solution
 The gurobi() function returns a struct as its result
 This struct contains a number of fields, where each field contains
information about the computed solution
 The available fields depend on the result of the optimization, the type of
model that was solved,
 The algorithm used to solve the model.
Questions???????

Packing Problems Using Gurobi

  • 1.
  • 2.
    What is packingproblems  Packing problems are a class of optimization problems in mathematics that involve attempting to pack objects together into containers. The goal is to either pack a single container as densely as possible or pack all objects using as few containers as possible.
  • 3.
    Examples of PackingProblems  Packing Commercials into station breaks  Packing files onto floppy disks (Dvds, CDs, etc.)  Packing telemetry data into fixed size pockets  Packing News articles onto a news paper  Packing a suitcase
  • 4.
    Formulation of packingrectangles using MILP  A MILP general model:  𝑧 = 𝑚𝑖𝑛 𝑖=1 𝑁 (𝑚𝑖 ∗ 𝑔 ∗ 𝑦𝑖) Subject to  𝑤 𝑖 2 + 𝑥𝑖 < 𝑥𝑗 − 𝑤 𝑗 2 i = 1,…,N j = 1,…,N  𝑤 𝑗 2 + 𝑥𝑗 < 𝑥𝑖 − 𝑤 𝑖 2 i = 1,…,N j = 1,…,N  ℎ 𝑖 2 + 𝑦𝑖 < 𝑦𝑗 − ℎ 𝑗 2 i = 1,…,N j = 1,…,N  ℎ 𝑗 2 + 𝑦𝑗 < 𝑦𝑖 − ℎ 𝑖 2 i = 1,…,N j = 1,…,N  𝑎𝑖𝑗 ∗ 𝑥𝑗 ≥ 𝑏𝑖 i = 1,…,N j = 1,…,N  Coefficients:  w – width of ith rectangle  h – height of ith rectangle  A = [N,N] = {aij}, (𝑁 × 𝑁) matrix  b = [N] = N vector  g- constant variable  Variables:  x = [N] = N vector of variables  y = [N] = N vector of variables  Where 𝑥, 𝑦 = the lower left coordinate of rectangle i
  • 5.
    Why an MILPmodel  Integer and continuous variables are both considered  If i = j, z is a Integer Programming Problem (ILP)  If i = 0, z is a Linear Programming Problem (LP)  The constraints and the objective function are modeled using linear equalities/inequalities  Effective solution techniques: Branch & Bound, Branch & Cut, Branch & Price  Software available (CPLEX, XPRESS, GLPK, etc)  Huge problems can be easily solved
  • 6.
    MILP model explanation MILP Constraints  The resources used in a optimization problems always limited by a set of constraints  MILP Variables  Variables reflect the resources to be allocated  MILP Objective Function  The objective function reflects the optimization aspect of the model
  • 7.
    What is GurobiOptimization  The Gurobi Optimizer is a commercial optimization solver for  Linear programming (LP),  Quadratic programming (QP),  Quadratical constrained programming (QCP),  Mixed integer linear programming (MILP)  Etc
  • 8.
    Solving MILP usingGurobi solver  The data associated with an optimization model must be stored in a MATLAB struct.  Fields in this struct contain the different parts of the model.  A few fields are mandatory:  the constraint matrix (A),  the objective vector (obj),  the right-hand side vector (rhs),  the constraint sense vector (sense).  A model can also include optional fields (e.g., the objective sense model.sense).
  • 9.
    Modifying Gurobi parameters We must create a struct variable that will be used to modify the Gurobi parameters  params.outputflag = 0;  params.resultfile = ’………’;  The Gurobi OutputFlag parameter is set to 0 in order to shut off Gurobi output.  Also the ResultFile parameter is set to request that Gurobi produce a file as output
  • 10.
    Solving the model The result is where the actual optimization occurs:  result = gurobi(model, params);  We pass the model and the optional list of parameter changes to the gurobi() function.  It computes an optimal solution to the specified model and returns the computed result.
  • 11.
    Printing the solution The gurobi() function returns a struct as its result  This struct contains a number of fields, where each field contains information about the computed solution  The available fields depend on the result of the optimization, the type of model that was solved,  The algorithm used to solve the model.
  • 12.