Ejemplo n.º 1
0
        public void Run(BoxItem[] listBoxItem, decimal palletLength, decimal palletWidth, decimal palletHeight, ref SolutionArray solArray)
        {
            packing = true;

            // boxes
            foreach (BoxItem bi in listBoxItem)
            {
                for (int i = 0; i < bi.N; ++i)
                {
                    boxList.Add(new BoxInfo()
                    {
                        ID = bi.ID, Dim1 = bi.Boxx, Dim2 = bi.Boxy, Dim3 = bi.Boxz, N = bi.N
                    });
                }
            }
            // pallet
            pallet = new PalletInfo(palletLength, palletWidth, palletHeight);
            // output file
            if (string.IsNullOrEmpty(OutputFilePath))
            {
                fso = null;
            }
            else
            {
                fso = new StreamWriter(OutputFilePath, true);
            }

            TimeStart = DateTime.Now;
            Initialize();
            Execute_iterations();
            TimeStop = DateTime.Now;
            Report_results2(ref solArray);
        }
Ejemplo n.º 2
0
        ///----------------------------------------------------------------------------
        /// FINDS THE MOST PROPER LAYER HEIGHT BY LOOKING AT THE UNPACKED BOXES AND THE
        /// REMAINING EMPTY SPACE AVAILABLE
        ///----------------------------------------------------------------------------
        private int Find_layer(decimal thickness, PalletInfo p)
        {
            decimal exdim = 0, dimdif = 0, dimen2 = 0, dimen3 = 0;
            decimal layereval = 0, eval = decimal.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);
        }