bourdux Posted September 9, 2012 Share Posted September 9, 2012 I am currently developing a carrier module for Kuroneko which is a door-to-door Japanese delivery company. This carrier, along with the weight, takes the size of the box into consideration. But it doe not use the volume, it would be too easy. It uses the sum of the three dimensions (height, weight and depth). If you've got only one product to box, it's still easy but what happens when you need to box 2 products? Let's say you have two products of dimensions (x1,y1,z1) and (x2,y2,z2), how do you calculate the final box size X,Y,Z in a way you keep X+Y+Z minimal? Here is my provisional solution, but tell me if there's a better way to calculate: let m1 be the minimal dimension of the first product, min(x1,y1,z1) and m2 for the second. You have to account for rotations of the products in the box to fit them in the best way and thus define new dimensions nx,ny,nz for both products. Let's suppose that nx = m. If m = x then ny = y, nz = z, else if m=y then, ny= x, nz = z, else if m=z, ny = y, nz= x. The total box size thus become 2*nx,max(ny1,ny2),max(nz1,nz2). But as far as I see, I don't think this method will work for more than 2 products. Any idea? Link to comment Share on other sites More sharing options...
bourdux Posted September 11, 2012 Author Share Posted September 11, 2012 I solved the problem by using a basic brute-force algorithm. Since artworks should be put in the box by respecting the down and top, it became really easy. It's not optimal but the cost is cheaper that packing each box separately. Here is my test code: function getPerimeter($boxes){ $bigBoxX = 0; $bigBoxY = 0; $bigBoxZ = 0; foreach ($boxes as $box) { if ($box[2] > $bigBoxZ) $bigBoxZ = $box[2]; if ($box[0] > $box[1]){ $bigBoxX += $box[0]; $bigBoxY = max(array($bigBoxY,$box[1])); } else { $bigBoxX += $box[1]; $bigBoxY = max(array($bigBoxY,$box[0])); } } echo "Big Box: ($bigBoxX,$bigBoxY,$bigBoxZ)"; return $bigBoxX + $bigBoxY + $bigBoxZ; } $cup = array(7,7,13.5); $ashtray = array(12,12,3); $tobacco = array(5,1.7,10); $goods= array($cup,$ashtray,$tobacco); $perimeter = getPerimeter($goods); echo"<br/><br/>"; echo $perimeter; The problem is that I have difficulties to integrate the code into the module and I created another topic to get some answers. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now