Sets
i /1*20/
alias(i,j);
Parameters
pi(i) "Profit of item i"
W "Width of the container"
H "Height of the container"
D "Depth of the container"
wi(i) "Width of item i"
hi(i) "Height of item i"
di(i) "Depth of item i";
Variables
z "Objective: total profit"
si(i) "1 if item i is selected, 0 otherwise"
xi(i) "X-coordinate of item i"
yi(i) "Y-coordinate of item i"
zi(i) "Z-coordinate of item i"
lij(i,j) "1 if item i is to the left of item j"
uij(i,j) "1 if item i is below item j"
bij(i,j) "1 if item i is behind item j";
Binary Variables si, lij, uij, bij;
Positive Variables xi, yi, zi;
Equations
obj "Objective function"
packing1(i,j) "Non-overlapping constraint for x"
packing2(i,j) "Non-overlapping constraint for y"
packing3(i,j) "Non-overlapping constraint for z"
bound_x(i) "X-bound constraint"
bound_y(i) "Y-bound constraint"
bound_z(i) "Z-bound constraint";
* Objective: maximize total profit
obj ..
z =e= sum(i, pi(i) * si(i));
* Non-overlapping constraints
packing1(i,j) $ (i <> j) ..
xi(i) + wi(i) * si(i) + W * lij(i,j) =l= xi(j) + W * (1 - si(i));
packing2(i,j) $ (i <> j) ..
yi(i) + hi(i) * si(i) + H * uij(i,j) =l= yi(j) + H * (1 - si(i));
packing3(i,j) $ (i <> j) ..
zi(i) + di(i) * si(i) + D * bij(i,j) =l= zi(j) + D * (1 - si(i));
* Boundary constraints
bound_x(i) ..
xi(i) + wi(i) * si(i) =l= W;
bound_y(i) ..
yi(i) + hi(i) * si(i) =l= H;
bound_z(i) ..
zi(i) + di(i) * si(i) =l= D;
Model BinPacking /all/;
Solve BinPacking using mip maximizing z;
I’m trying to run this code on GAMS. However, it’s giving me “Dimension different – The symbol is referenced with more/less indices as declared” error in packing1(i,j) $ (i <> j)
.. I’m trying to create model for 3D bin packing for rolls. If you know better way, please write it on the comments.
ibrahimtugar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
You should do this instead (same for the following errors):
* Non-overlapping constraints
packing1(i,j) $ (ord(i) <> ord(j)) ..
xi(i) + wi(i) * si(i) + W * lij(i,j) =l= xi(j) + W * (1 - si(i));
Ord
returns the relative position of an element in a set.