0
$\begingroup$

Is it possible to solve a 2d bin packing problem or nesting problem with Cplex? The solution should present the $x$ and $y$ coordinates of each item.

$\endgroup$
2
  • 1
    $\begingroup$ please accept the answer that solved your problem rather than changing the question to "solved". $\endgroup$
    – EhsanK
    Feb 3 at 16:49
  • $\begingroup$ @Mathew, beside of the interested answer of Alex, you might want to take a look into the ABS models to solve floor layout problems. :) $\endgroup$
    – A.Omidi
    Feb 4 at 8:14
3
$\begingroup$

you could start with

//using CP;

int n=25; // nb of rectangles
 

 
 int sizeBigSquare=10000;
 
 int l[i in 1..n]=rand(100);
 int w[i in 1..n]=rand(100);
 
 dvar int x[i in 1..n]in 0..sizeBigSquare;
 dvar int y[i in 1..n] in 0..sizeBigSquare;
 dvar boolean rota[i in 1..n]; // do we rotate?
 
 dexpr int x2[i in 1..n]=x[i]+(rota[i]==1)*w[i]+(rota[i]==0)*l[i];
 dexpr int y2[i in 1..n]=y[i]+(rota[i]==1)*l[i]+(rota[i]==0)*w[i];
 
 dexpr int Mx=max(i in 1..n) x2[i];
 dexpr int My=max(i in 1..n) y2[i];
 
 minimize My;
 
 subject to
 {
   
   Mx<=1000;
   forall(ordered i,j in 1..n)
     (x2[i]<=x[j]) || (x2[j]<=x[i]) || (y2[i]<=y[j]) || (y2[j]<=y[i]);
 }  
 
 float rate=sum(i in 1..n) w[i]*l[i]/My/Mx; 
 
 execute
 {
  writeln("Rate=",rate); 
 }   

that is relying on MIP within CPLEX

And if you comment // in //using CP; then this model will use constraint programming

$\endgroup$
1
  • $\begingroup$ Thanks for your interesting solution. Would you please, add some details in your answer to clarify decision variables and constraints notation? $\endgroup$
    – A.Omidi
    Feb 4 at 8:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.