public void Run(BoxItem[] listBoxItem, int palletLength, int palletWidth, int palletHeight) { packing = true; // boxes foreach (BoxItem bi in listBoxItem) { for (int i = 0; i < bi.N; ++i) { boxList.Add(new BoxInfo() { Dim1 = bi.Boxx, Dim2 = bi.Boxy, Dim3 = bi.Boxz, N = bi.N }); } } // pallet pallet = new PalletInfo(palletLength, palletWidth, palletHeight); // output file fso = new StreamWriter(OutputFilePath, true); _timeStart = DateTime.Now; Initialize(); Execute_iterations(); _timeStop = DateTime.Now; Report_results(); }
///---------------------------------------------------------------------------- /// FINDS THE MOST PROPER LAYER HEIGHT BY LOOKING AT THE UNPACKED BOXES AND THE /// REMAINING EMPTY SPACE AVAILABLE ///---------------------------------------------------------------------------- private int Find_layer(int thickness, PalletInfo p) { int exdim = 0, dimdif = 0, dimen2 = 0, dimen3 = 0; int layereval = 0, eval = int.MaxValue; layerThickness = 0; for (int x = 0; x < boxList.Count; x++) { BoxInfo bi = boxList[x]; if (bi.Is_packed) { continue; } for (int y = 1; y <= 3; y++) { switch (y) { case 1: exdim = bi.Dim1; dimen2 = bi.Dim2; dimen3 = bi.Dim3; break; case 2: exdim = bi.Dim2; dimen2 = bi.Dim1; dimen3 = bi.Dim3; break; case 3: exdim = bi.Dim3; dimen2 = bi.Dim1; dimen3 = bi.Dim2; break; default: break; } layereval = 0; if ((exdim <= thickness) && (((dimen2 <= p.Pallet_x) && (dimen3 <= p.Pallet_z)) || ((dimen3 <= p.Pallet_x) && (dimen2 <= p.Pallet_z)))) { for (int z = 0; z < boxList.Count; z++) { if (!(x == z) && !(boxList[z].Is_packed)) { dimdif = Math.Abs(exdim - boxList[z].Dim1); if (Math.Abs(exdim - boxList[z].Dim2) < dimdif) { dimdif = Math.Abs(exdim - boxList[z].Dim2); } if (Math.Abs(exdim - boxList[z].Dim3) < dimdif) { dimdif = Math.Abs(exdim - boxList[z].Dim3); } layereval = layereval + dimdif; } } if (layereval < eval) { eval = layereval; layerThickness = exdim; } } } } if (layerThickness == 0 || layerThickness > remainpy) { packing = false; } return(0); }