Ejemplo n.º 1
0
        private void Initialize()
        {
            total_box_volume = 0;
            foreach (BoxInfo bi in boxList)
            {
                total_box_volume += bi.Vol;
            }

            scrapfirst           = new Scrappad();
            best_solution_volume = 0;
            number_of_iterations = 0;
        }
Ejemplo n.º 2
0
        //----------------------------------------------------------------------------
        // FINDS THE FIRST TO BE PACKED GAP IN THE LAYER EDGE
        //----------------------------------------------------------------------------
        private Scrappad Find_smallest_z()
        {
            Scrappad scrapmemb = scrapfirst;
            Scrappad sz        = scrapfirst;

            while (null != scrapmemb.Next)
            {
                if (scrapmemb.Next.Cumz < sz.Cumz)
                {
                    sz = scrapmemb.Next;
                }
                scrapmemb = scrapmemb.Next;
            }
            return(sz);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// AFTER FINDING EACH BOX, THE CANDIDATE BOXES AND THE CONDITION OF THE LAYER
 /// ARE EXAMINED
 /// </summary>
 private void CheckFound(
     ref decimal cboxi, ref decimal cboxx, ref decimal cboxy, ref decimal cboxz
     , decimal boxi, decimal boxx, decimal boxy, decimal boxz
     , decimal bboxi, decimal bboxx, decimal bboxy, decimal bboxz)
 {
     evened = false;
     if (boxi >= 0 && 0 != boxx * boxy * boxz)
     {
         cboxi = boxi;
         cboxx = boxx;
         cboxy = boxy;
         cboxz = boxz;
     }
     else
     {
         if ((bboxi >= 0 && 0 != bboxx * bboxy * bboxz) && (layerinlayer > 0 || (null == smallestz.Prev && null == smallestz.Next)))
         {
             if (layerinlayer == 0.0M)
             {
                 prelayer = layerThickness;
                 lilz     = smallestz.Cumz;
             }
             cboxi          = bboxi;
             cboxx          = bboxx;
             cboxy          = bboxy;
             cboxz          = bboxz;
             layerinlayer   = layerinlayer + bboxy - layerThickness;
             layerThickness = bboxy;
         }
         else
         {
             if (null == smallestz.Prev && null == smallestz.Next)
             {
                 layerdone = true;
             }
             else
             {
                 evened = true;
                 if (null == smallestz.Prev)
                 {
                     trash          = smallestz.Next;
                     smallestz.Cumx = smallestz.Next.Cumx;
                     smallestz.Cumz = smallestz.Next.Cumz;
                     smallestz.Next = smallestz.Next.Next;
                     if (null != smallestz.Next)
                     {
                         smallestz.Next.Prev = smallestz;
                     }
                     trash = null;
                 }
                 else if (null == smallestz.Next)
                 {
                     smallestz.Prev.Next = null;
                     smallestz.Prev.Cumx = smallestz.Cumx;
                     smallestz           = null;
                 }
                 else
                 {
                     if (smallestz.Prev.Cumz == smallestz.Next.Cumz)
                     {
                         smallestz.Prev.Next = smallestz.Next.Next;
                         if (null != smallestz.Next.Next)
                         {
                             smallestz.Next.Next.Prev = smallestz.Prev;
                         }
                         smallestz.Prev.Cumx = smallestz.Next.Cumx;
                         smallestz.Next      = null;
                         smallestz           = null;
                     }
                     else
                     {
                         smallestz.Prev.Next = smallestz.Next;
                         smallestz.Next.Prev = smallestz.Prev;
                         if (smallestz.Prev.Cumz < smallestz.Next.Cumz)
                         {
                             smallestz.Prev.Cumx = smallestz.Cumx;
                         }
                         smallestz = null;
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 4
0
        ///----------------------------------------------------------------------------
        /// PACKS THE BOXES FOUND AND ARRANGES ALL VARIABLES AND RECORDS PROPERLY
        ///----------------------------------------------------------------------------
        private bool Pack_layer(bool packingbest, ref bool hundredpercent)
        {
            if (0 == layerThickness)
            {
                packing = false;
                return(false);
            }

            scrapfirst = new Scrappad()
            {
                Cumx = pallet.Pallet_x,
                Cumz = 0
            };
            decimal cboxi = 0, cboxx = 0, cboxy = 0, cboxz = 0;

            while (true)
            {
                smallestz = Find_smallest_z();

                if (null == smallestz.Prev && null == smallestz.Next)
                {
                    //*** SITUATION-1: NO BOXES ON THE RIGHT AND LEFT SIDES ***
                    decimal lenx = smallestz.Cumx;
                    decimal lpz  = remainpz - smallestz.Cumz;
                    Find_box(lenx, layerThickness, remainpy, lpz, lpz,
                             ref cboxi, ref cboxx, ref cboxy, ref cboxz);

                    if (layerdone)
                    {
                        break;
                    }
                    if (evened)
                    {
                        continue;
                    }

                    BoxInfo bi = boxList[(int)cboxi];
                    boxList[(int)cboxi].Cox = 0;
                    boxList[(int)cboxi].Coy = packedy;
                    boxList[(int)cboxi].Coz = smallestz.Cumz;
                    if (cboxx == smallestz.Cumx)
                    {
                        smallestz.Cumz = smallestz.Cumz + cboxz;
                    }
                    else
                    {
                        smallestz.Next = new Scrappad
                        {
                            Prev = smallestz,
                            Cumx = smallestz.Cumx,
                            Cumz = smallestz.Cumz
                        };
                        smallestz.Cumx = cboxx;
                        smallestz.Cumz = smallestz.Cumz + cboxz;
                    }
                    VolumeCheck((int)cboxi, cboxx, cboxy, cboxz, packingbest, ref hundredpercent);
                }
                else if (null == smallestz.Prev)
                {
                    //*** SITUATION-2: NO BOXES ON THE LEFT SIDE ***
                    decimal lenx = smallestz.Cumx;
                    decimal lenz = smallestz.Next.Cumz - smallestz.Cumz;
                    decimal lpz  = remainpz - smallestz.Cumz;
                    Find_box(lenx, layerThickness, remainpy, lenz, lpz
                             , ref cboxi, ref cboxx, ref cboxy, ref cboxz);

                    if (layerdone)
                    {
                        break;
                    }
                    if (evened)
                    {
                        continue;
                    }

                    BoxInfo bi = boxList[(int)cboxi];
                    bi.Coy = packedy;
                    bi.Coz = smallestz.Cumz;
                    if (cboxx == smallestz.Cumx)
                    {
                        bi.Cox = 0;
                        if (smallestz.Cumz + cboxz == smallestz.Next.Cumz)
                        {
                            smallestz.Cumz = smallestz.Next.Cumz;
                            smallestz.Cumx = smallestz.Next.Cumx;
                            trash          = smallestz.Next;
                            smallestz.Next = smallestz.Next.Next;
                            if (null != smallestz.Next)
                            {
                                smallestz.Next.Prev = smallestz;
                            }
                        }
                        else
                        {
                            smallestz.Cumz = smallestz.Cumz + cboxz;
                        }
                    }
                    else
                    {
                        bi     = boxList[(int)cboxi];
                        bi.Cox = smallestz.Cumx - cboxx;
                        if (smallestz.Cumz + cboxz == smallestz.Next.Cumz)
                        {
                            smallestz.Cumx = smallestz.Cumx - cboxx;
                        }
                        else
                        {
                            smallestz.Next.Prev = new Scrappad
                            {
                                Next = smallestz.Next,
                                Prev = smallestz
                            };
                            smallestz.Next      = smallestz.Next.Prev;
                            smallestz.Next.Cumx = smallestz.Cumx;
                            smallestz.Cumx      = smallestz.Cumx - cboxx;
                            smallestz.Next.Cumz = smallestz.Cumz + cboxz;
                        }
                    }
                    VolumeCheck((int)cboxi, cboxx, cboxy, cboxz, packingbest, ref hundredpercent);
                }
                else if (null == smallestz.Next)
                {
                    //*** SITUATION-3: NO BOXES ON THE RIGHT SIDE ***
                    decimal lenx = smallestz.Cumx - smallestz.Prev.Cumx;
                    decimal lenz = smallestz.Prev.Cumz - smallestz.Cumz;
                    decimal lpz  = remainpz - smallestz.Cumz;
                    Find_box(lenx, layerThickness, remainpy, lenz, lpz
                             , ref cboxi, ref cboxx, ref cboxy, ref cboxz);

                    if (layerdone)
                    {
                        break;
                    }
                    if (evened)
                    {
                        continue;
                    }

                    BoxInfo bi = boxList[(int)cboxi];
                    bi.Coy = packedy;
                    bi.Coz = smallestz.Cumz;
                    bi.Cox = smallestz.Prev.Cumx;

                    if (cboxx == smallestz.Cumx - smallestz.Prev.Cumx)
                    {
                        if (smallestz.Cumz + cboxz == smallestz.Prev.Cumz)
                        {
                            smallestz.Prev.Cumx = smallestz.Cumx;
                            smallestz.Prev.Next = null;
                        }
                        else
                        {
                            smallestz.Cumz = smallestz.Cumz + cboxz;
                        }
                    }
                    else
                    {
                        if (smallestz.Cumz + cboxz == smallestz.Prev.Cumz)
                        {
                            smallestz.Prev.Cumx = smallestz.Prev.Cumx + cboxx;
                        }
                        else
                        {
                            smallestz.Prev.Next = new Scrappad
                            {
                                Prev = smallestz.Prev,
                                Next = smallestz
                            };
                            smallestz.Prev      = smallestz.Prev.Next;
                            smallestz.Prev.Cumx = smallestz.Prev.Prev.Cumx + cboxx;
                            smallestz.Prev.Cumz = smallestz.Cumz + cboxz;
                        }
                    }
                    VolumeCheck((int)cboxi, cboxx, cboxy, cboxz, packingbest, ref hundredpercent);
                }
                else if (smallestz.Prev.Cumz == smallestz.Next.Cumz)
                {
                    //*** SITUATION-4: THERE ARE BOXES ON BOTH OF THE SIDES ***
                    //*** SUBSITUATION-4A: SIDES ARE EQUAL TO EACH OTHER ***
                    decimal lenx = smallestz.Cumx - smallestz.Prev.Cumx;
                    decimal lenz = smallestz.Prev.Cumz - smallestz.Cumz;
                    decimal lpz  = remainpz - smallestz.Cumz;
                    Find_box(lenx, layerThickness, remainpy, lenz, lpz
                             , ref cboxi, ref cboxx, ref cboxy, ref cboxz);

                    if (layerdone)
                    {
                        break;
                    }
                    if (evened)
                    {
                        continue;
                    }

                    boxList[(int)cboxi].Coy = packedy;
                    boxList[(int)cboxi].Coz = smallestz.Cumz;
                    if (cboxx == smallestz.Cumx - smallestz.Prev.Cumx)
                    {
                        boxList[(int)cboxi].Cox = smallestz.Prev.Cumx;
                        if (smallestz.Cumz + cboxz == smallestz.Next.Cumz)
                        {
                            smallestz.Prev.Cumx = smallestz.Next.Cumx;
                            if (null != smallestz.Next.Next)
                            {
                                smallestz.Prev.Next      = smallestz.Next.Next;
                                smallestz.Next.Next.Prev = smallestz.Prev;
                            }
                            else
                            {
                                smallestz.Prev.Next = null;
                            }
                        }
                        else
                        {
                            smallestz.Cumz = smallestz.Cumz + cboxz;
                        }
                    }
                    else if (smallestz.Prev.Cumx < pallet.Pallet_x - smallestz.Cumx)
                    {
                        if (smallestz.Cumz + cboxz == smallestz.Prev.Cumz)
                        {
                            smallestz.Cumx          = smallestz.Cumx - cboxx;
                            boxList[(int)cboxi].Cox = smallestz.Cumx - cboxx;
                        }
                        else
                        {
                            boxList[(int)cboxi].Cox = smallestz.Prev.Cumx;
                            smallestz.Prev.Next     = new Scrappad
                            {
                                Prev = smallestz.Prev,
                                Next = smallestz
                            };
                            smallestz.Prev      = smallestz.Prev.Next;
                            smallestz.Prev.Cumx = smallestz.Prev.Prev.Cumx + cboxx;
                            smallestz.Prev.Cumz = smallestz.Cumz + cboxz;
                        }
                    }
                    else
                    {
                        if (smallestz.Cumz + cboxz == smallestz.Prev.Cumz)
                        {
                            smallestz.Prev.Cumx     = smallestz.Prev.Cumx + cboxx;
                            boxList[(int)cboxi].Cox = smallestz.Prev.Cumx;
                        }
                        else
                        {
                            boxList[(int)cboxi].Cox = smallestz.Cumx - cboxx;
                            smallestz.Next.Prev     = new Scrappad
                            {
                                Next = smallestz.Next,
                                Prev = smallestz
                            };
                            smallestz.Next      = smallestz.Next.Prev;
                            smallestz.Next.Cumx = smallestz.Cumx;
                            smallestz.Next.Cumz = smallestz.Cumz + cboxz;
                            smallestz.Cumx      = smallestz.Cumx - cboxx;
                        }
                    }
                    VolumeCheck((int)cboxi, cboxx, cboxy, cboxz, packingbest, ref hundredpercent);
                }
                else
                {
                    //*** SUBSITUATION-4B: SIDES ARE NOT EQUAL TO EACH OTHER ***
                    //*** SUBSITUATION-4B: SIDES ARE NOT EQUAL TO EACH OTHER ***
                    decimal lenx = smallestz.Cumx - smallestz.Prev.Cumx;
                    decimal lenz = smallestz.Prev.Cumz - smallestz.Cumz;
                    decimal lpz  = remainpz - smallestz.Cumz;
                    Find_box(lenx, layerThickness, remainpy, lenz, lpz
                             , ref cboxi, ref cboxx, ref cboxy, ref cboxz);

                    if (layerdone)
                    {
                        break;
                    }
                    if (evened)
                    {
                        continue;
                    }

                    boxList[(int)cboxi].Coy = packedy;
                    boxList[(int)cboxi].Coz = smallestz.Cumz;
                    boxList[(int)cboxi].Cox = smallestz.Prev.Cumx;
                    if (cboxx == smallestz.Cumx - smallestz.Prev.Cumx)
                    {
                        if (smallestz.Cumz + cboxz == smallestz.Prev.Cumz)
                        {
                            smallestz.Prev.Cumx = smallestz.Cumx;
                            smallestz.Prev.Next = smallestz.Next;
                            smallestz.Next.Prev = smallestz.Prev;
                        }
                        else
                        {
                            smallestz.Cumz = smallestz.Cumz + cboxz;
                        }
                    }
                    else
                    {
                        if (smallestz.Cumz + cboxz == smallestz.Prev.Cumz)
                        {
                            smallestz.Prev.Cumx = smallestz.Prev.Cumx + cboxx;
                        }
                        else if (smallestz.Cumz + cboxz == smallestz.Next.Cumz)
                        {
                            boxList[(int)cboxi].Cox = smallestz.Cumx - cboxx;
                            smallestz.Cumx          = smallestz.Cumx - cboxx;
                        }
                        else
                        {
                            smallestz.Prev.Next = new Scrappad
                            {
                                Prev = smallestz.Prev,
                                Next = smallestz
                            };
                            smallestz.Prev      = smallestz.Prev.Next;
                            smallestz.Prev.Cumx = smallestz.Prev.Prev.Cumx + cboxx;
                            smallestz.Prev.Cumz = smallestz.Cumz + cboxz;
                        }
                    }
                    VolumeCheck((int)cboxi, cboxx, cboxy, cboxz, packingbest, ref hundredpercent);
                }
            }
            return(true);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// AFTER FINDING EACH BOX, THE CANDIDATE BOXES AND THE CONDITION OF THE LAYER
 /// ARE EXAMINED
 /// </summary>
 private void CheckFound(
     ref long cboxi, ref long cboxx, ref long cboxy, ref long cboxz
     , long boxi, long boxx, long boxy, long boxz
     , long bboxi, long bboxx, long bboxy, long bboxz)
 {
     evened = false;
     if (boxi > 0)
     {
         cboxi = boxi;
         cboxx = boxx;
         cboxy = boxy;
         cboxz = boxz;
     }
     else
     {
         if ((bboxi > 0) && (layerinlayer > 0 || (null == smallestz.prev && null == smallestz.next)))
         {
             if (layerinlayer == 0.0)
             {
                 prelayer = layerThickness;
                 lilz     = smallestz.Cumz;
             }
             cboxi          = bboxi;
             cboxx          = bboxx;
             cboxy          = bboxy;
             cboxz          = bboxz;
             layerinlayer   = layerinlayer + bboxy - layerThickness;
             layerThickness = bboxy;
         }
         else
         {
             if (null == smallestz.prev && null == smallestz.next)
             {
                 layerdone = true;
             }
             else
             {
                 evened = true;
                 if (null == smallestz.prev)
                 {
                     trash          = smallestz.next;
                     smallestz.Cumx = smallestz.next.Cumx;
                     smallestz.Cumz = smallestz.next.Cumz;
                     smallestz.next = smallestz.next.next;
                     if (null != smallestz.next)
                     {
                         smallestz.next.prev = smallestz;
                     }
                     trash = null;
                 }
                 else if (null == smallestz.next)
                 {
                     smallestz.prev.next = null;
                     smallestz.prev.Cumx = smallestz.Cumx;
                     smallestz           = null;
                 }
                 else
                 {
                     if (smallestz.prev.Cumz == smallestz.next.Cumz)
                     {
                         smallestz.prev.next = smallestz.next.next;
                         if (null != smallestz.next.next)
                         {
                             smallestz.next.next.prev = smallestz.prev;
                         }
                         smallestz.prev.Cumx = smallestz.next.Cumx;
                         smallestz.next      = null;
                         smallestz           = null;
                     }
                     else
                     {
                         smallestz.prev.next = smallestz.next;
                         smallestz.next.prev = smallestz.prev;
                         if (smallestz.prev.Cumz < smallestz.next.Cumz)
                         {
                             smallestz.prev.Cumx = smallestz.Cumx;
                         }
                         smallestz = null;
                     }
                 }
             }
         }
     }
 }