3DContainerPacking intersected objects

28 Views Asked by At

I'm trying to make the best use of a pallet, having boxes of various sizes but always in the shape of a rectangular parallelepiped. I'm using the methodology developed in this project: https://github.com/davidmchapman/3DContainerPacking

The method of utilisation and calling is quite simple and is perfectly exemplified on the project page, however, the results fall short, as I detect lots of intersections of various objects.

As an example, if I indicate that the pallet on which the algorithm should place the boxes is 120 x 100 x 210 (width x length x height), the output result is as follows:

cuboid(pallet_location_x | pallet_location_y | pallet_location_z box_x | box_y | box_z)

cuboid(0|0|0 62|53|66)
cuboid(66|0|0 62|53|66)
cuboid(0|0|53 62|53|66)
cuboid(66|0|66 62|53|66)
cuboid(0|0|106 62|53|66)
cuboid(66|0|132 62|53|66)
cuboid(11|0|159 55|48|61)
cuboid(0|62|0 60|38|55)
cuboid(60|62|0 60|38|55)
cuboid(0|62|55 60|38|55)
cuboid(60|62|55 60|38|55)
cuboid(0|62|110 60|38|55)
cuboid(60|62|110 60|38|55)
cuboid(0|62|165 56|31|45)
cuboid(56|62|165 56|31|45)

Inserting this result into https://www.matheretter.de/geoservant/en, we conclude that the algorithm returns boxes intersected with other boxes.

The method call is quite simple and doesn't allow for many options, so I'm wondering if anyone is aware of this type of bug, or if I've missed any details.

string nrpack = "232091";

            List<Container> paletes_ = new List<Container>();
            using (DataTable dt = new DataTable())
            using (SqlConnection cn = new SqlConnection(cn_))
            using (SqlCommand cmd = new SqlCommand("SELECT description,width,length,height", cn))
            using (SqlDataAdapter da = new SqlDataAdapter(cmd))
            {
                if (cn.State == ConnectionState.Closed) cn.Open();
                da.Fill(dt);

                for (int i = 0; i < dt.Rows.Count; i++) paletes_.Add(new Container(i, Convert.ToInt32(dt.Rows[i]["width"]), Convert.ToInt32(dt.Rows[i]["height"]), Convert.ToInt32(dt.Rows[i]["length"])));
            }

            List<Item> tarifas_ = new List<Item>();
            using (DataTable dt = new DataTable())
            using (SqlConnection cn = new SqlConnection(cn_))
            using (SqlCommand cmd = new SqlCommand("SELECT NRPACK,LNPACK,te_.COMP,te_.LARG,te_.ALT", cn))
            using (SqlDataAdapter da = new SqlDataAdapter(cmd))
            {
                if (cn.State == ConnectionState.Closed) cn.Open();
                cmd.Parameters.AddWithValue("@nrpack", nrpack);
                da.Fill(dt);

                foreach (DataRow dr in dt.Rows) tarifas_.Add(new Item(Convert.ToInt32(dr["LNPACK"]), Convert.ToInt32(dr["LARG"]), Convert.ToInt32(dr["COMP"]), Convert.ToInt32(dr["ALT"]), 1));
            }

            long palletprocessingid_ = System.DateTime.Now.Subtract(new DateTime(2020, 1, 1, 0, 0, 1)).Ticks;

            foreach (Container palete_ in paletes_)
            {
                List<Item> tarifas_pendentes_ = tarifas_;
                while (tarifas_pendentes_.Count > 0)
                {
                    long palletid_ = System.DateTime.Now.Subtract(new DateTime(2020, 1, 1, 0, 0, 1)).Ticks;
                    foreach (ContainerPackingResult r_ in PackingService.Pack(new List<Container>() { palete_ }, tarifas_pendentes_, new List<int> { (int)AlgorithmType.EB_AFIT }))
                    {
                        foreach (AlgorithmPackingResult a_ in r_.AlgorithmPackingResults)
                        {
                            foreach (Item tarifa_embalada_ in a_.PackedItems)
                            {
                                using (SqlConnection cn = new SqlConnection(cn_))
                                using (SqlCommand cmd = new SqlCommand("INSERT INTO tabPackingPalletizationProcessing VALUES (@palletprocessingid,@palletid,@box_tag,@nrpack,@lnpack,@pallet_width,@pallet_length,@pallet_height,@size_x,@size_y,@size_z,@pallet_position_x,@pallet_position_y,@pallet_position_z)", cn))
                                {
                                    if (cn.State == ConnectionState.Closed) cn.Open();
                                    cmd.Parameters.AddWithValue("@palletprocessingid", palletprocessingid_);
                                    cmd.Parameters.AddWithValue("@palletid", palletid_);
                                    cmd.Parameters.AddWithValue("@box_tag", "box" + tarifa_embalada_.ID);
                                    cmd.Parameters.AddWithValue("@nrpack", nrpack);
                                    cmd.Parameters.AddWithValue("@lnpack", tarifa_embalada_.ID);
                                    cmd.Parameters.AddWithValue("@pallet_width", palete_.Width);
                                    cmd.Parameters.AddWithValue("@pallet_length", palete_.Length);
                                    cmd.Parameters.AddWithValue("@pallet_height", palete_.Height);
                                    cmd.Parameters.AddWithValue("@size_x", tarifa_embalada_.Dim1);
                                    cmd.Parameters.AddWithValue("@size_y", tarifa_embalada_.Dim2);
                                    cmd.Parameters.AddWithValue("@size_z", tarifa_embalada_.Dim3);
                                    cmd.Parameters.AddWithValue("@pallet_position_x", tarifa_embalada_.CoordX);
                                    cmd.Parameters.AddWithValue("@pallet_position_y", tarifa_embalada_.CoordY);
                                    cmd.Parameters.AddWithValue("@pallet_position_z", tarifa_embalada_.CoordZ);
                                    //cmd.ExecuteNonQuery();

                                    Console.WriteLine("cuboid(" + tarifa_embalada_.CoordX + "|" + tarifa_embalada_.CoordY + "|" + tarifa_embalada_.CoordZ + " " + tarifa_embalada_.Dim2 + "|" + tarifa_embalada_.Dim1 + "|" + tarifa_embalada_.Dim3 + ")");
                                }
                            }
                            tarifas_pendentes_ = a_.UnpackedItems;
                        }
                    }
                }
            }

I've already tried changing all the coordinates, fearing that I've misplaced the data, but I always detect intersections in the output results.

I'm wondering if anyone has stumbled across the same problem using this project?

0

There are 0 best solutions below