title: 3D bin packing algorithm?
body: <p>I wrote a 3D bin packing algorithm but I am still not sure if it is correct or not.</p>
  
  <p>I did not follow any code or pseudo-code that's why I would like to know if it is an efficient algorithm for the 3D bin packing problem or not. </p>
  
  <p>each container has a length, height and breadth</p>
  
  <p>each item has a length , height and breadth. </p>
  
  <p>This is the code I wrote to pack items one by one without exceeding the container's length, height or breadth: </p>
  
  <pre><code>private double x,y,z=0;
  private double[] remainingLength;
  private double[] remainingHeight;
  private double[] remainingBreadth;
  
     //----initialize the remaining dimensions' arrays
      public void init(int n) {
          remainingLength=new double[n];
          remainingHeight=new double[n];
          remainingBreadth=new double[n];
          for (int i=0; i&lt;n; i++) {
              remainingLength[i]=length;
              remainingHeight[i]=height;
              remainingBreadth[i]=breadth;
          }
      }
  
  public boolean put3D(ItemsUnit item, int p,int n) {
      init(n); 
  
      if(x&lt;length){
          if(putL(item,p)) {
          packedItems.add(item); // if item fits add it to the packedItems into the container
       return true;
      }
      }
  
          if(y&lt;breadth) {
                  if(putB(item,p)){
              packedItems.add(item); // if item fits add it to the packedItems into the container
              return true;
          }
          }
              if(z&lt;height){
                  if(putH(item,p)){
                  packedItems.add(item); // if item fits add it to the packedItems into the container
                  return true;
              }
          }
  
          return false;
      }
  
  public boolean putL(ItemsUnit item, int p) {
      //remaining dimensions arrays already initialized in the optimization algorithm
      double minRemL=remainingLength[0];
      int i=0;
  
      for (int j=0; j&lt;remainingLength.length; j++){
          if ((remainingLength[j]!=0)&amp;&amp;(minRemL&gt;=remainingLength[j])&amp;&amp;(remainingLength[j]&gt;=item.getLength())){
                  i=j; //choosing the item to which we should put the new packed item next to
                  minRemL=remainingLength[j]; //minimum length left
          }else {
              return false;
          }
      }
          remainingLength[p]=remainingLength[i]-item.getLength();
          remainingBreadth[p]-=item.getBreadth();
          remainingHeight[p]-=item.getHeight();
          remainingLength[i]=0;
          x+=item.getLength(); //increment x
          return true;
  }
  
  
  public boolean putB(ItemsUnit item, int p) {
      //remaining dimensions arrays already initialized in the optimization algorithm
      double minRemB=remainingBreadth[0];
      int i=0;
  
      for (int j=0; j&lt;remainingBreadth.length; j++){
          if ((remainingBreadth[j]!=0)&amp;&amp;(minRemB&gt;=remainingBreadth[j])&amp;&amp;(remainingBreadth[j]&gt;=item.getBreadth())){
                  i=j; //choosing the item to which we should put the new packed item next to
                  minRemB=remainingBreadth[j]; //minimum length left
          }
          else {
              return false;
          }
      }
          remainingBreadth[p]=remainingBreadth[i]-item.getBreadth();
          remainingHeight[p]-=item.getHeight();
          remainingLength[p]-=item.getLength();
          remainingBreadth[i]=0;
          y+=item.getBreadth(); //increment y
          return true;
  }
  
  
  public boolean putH(ItemsUnit item, int p) {
      //remaining dimensions arrays already initialized in the optimization algorithm
      double minRemH=remainingHeight[0];
      int i=0;
  
      for (int j=0; j&lt;remainingHeight.length; j++){
          if ((remainingHeight[j]!=0)&amp;&amp;(minRemH&gt;=remainingHeight[j])&amp;&amp;(remainingHeight[j]&gt;=item.getHeight())){
                  i=j; //choosing the item to which we should put the new packed item next to
                  minRemH=remainingHeight[j]; //minimum length left
          }
          else {
              return false;
          }
      }
          remainingHeight[p]=remainingHeight[i]-item.getHeight();
          remainingBreadth[p]-=item.getBreadth();
          remainingLength[p]-=item.getLength();
          remainingHeight[i]=0;
          z+=item.getHeight(); //increment z
          return true;
  }
  </code></pre>
  
  <p>I tested the algorithm and it worked fine without exceeding the dimensions of the container but I am not fully certain if the code is correct. </p>
  
  <p>Can anyone read the code and tell me if it has a problem somewhere or if it is correct? </p>