Ejemplo n.º 1
0
        public void Init(Int32 width, Int32 length, Int32 height, Boolean rotations = true)
        {
            boxWidth       = width;
            boxHeight      = height;
            allowRotations = rotations;

            Containers n = new Containers();

            n.Origin.X = 0;
            n.Origin.Y = 0;
            n.Origin.Z = 0;

            n.Width  = width;
            n.Height = height;
            n.Length = length;

            usedContainers.Clear();
            freeContainers.Clear();
            freeContainers.Add(n);
        }
Ejemplo n.º 2
0
        void Split_Container(String Container_Key, Int32 index, Int32 orientation_case, Box box, Point3D point, Boolean RotationX, Boolean RotationY, Boolean RotationZ)
        {
            Containers old_container  = Split_Container_open_list[Container_Key].ElementAt(index);
            Containers new_container1 = new Containers();
            Containers new_container2 = new Containers();
            Containers new_container3 = new Containers();

            //no-rotation
            if (orientation_case == 0)
            {
                new_container1.Length = old_container.Length;
                new_container1.Width  = old_container.Width - box.Width;
                new_container1.Height = old_container.Height;

                if (new_container1.Length > 0 && new_container1.Width > 0 && new_container1.Height > 0)
                {
                    new_container1.Origin.X      = point.X;
                    new_container1.Origin.Y      = point.Y + box.Width;
                    new_container1.Origin.Z      = point.Z;
                    new_container1.Still_to_Open = true;
                    Split_Container_open_list[Container_Key].Add(new_container1);
                }

                new_container2.Length = old_container.Length - box.Length;
                new_container2.Width  = old_container.Width;
                new_container2.Height = old_container.Height;

                if (new_container2.Length > 0 && new_container2.Width > 0 && new_container2.Height > 0)
                {
                    new_container2.Origin.X      = point.X + box.Length;
                    new_container2.Origin.Y      = point.Y;
                    new_container2.Origin.Z      = point.Z;
                    new_container2.Still_to_Open = true;
                    Split_Container_open_list[Container_Key].Add(new_container2);
                }

                new_container3.Length = old_container.Length;
                new_container3.Width  = old_container.Width;
                new_container3.Height = old_container.Height - box.Height;

                if (new_container3.Length > 0 && new_container3.Width > 0 && new_container3.Height > 0)
                {
                    new_container3.Origin.X      = point.X;
                    new_container3.Origin.Y      = point.Y;
                    new_container3.Origin.Z      = point.Z + box.Height;
                    new_container3.Still_to_Open = true;
                    Split_Container_open_list[Container_Key].Add(new_container3);
                }
                Split_Container_open_list[Container_Key].RemoveAt(index);

                /*
                 *  foreach Free Container F in Split_Container_open_list
                 *  {
                 *      Compute F\Box and subdivide the result into at most six
                 *      new containers C1, C2, C3...C6 and add them to
                 *      Split_Container_open_list;
                 *      and Delete F from Split_Containers_open_list.
                 *   }
                 */
                Int32 tindex = 0;
                foreach (Containers F in Split_Container_open_list[Container_Key])
                {
                    //if the container is intersected by the container.
                    if (box_intersect_container(box, box.Length, box.Width, box.Height, F))
                    {//New node at the top side of the used node.
                        if (box.Origin.X < F.Origin.X + F.Length && box.Origin.X + box.Length > F.Origin.X)
                        {
                            if (box.Origin.Y > F.Origin.Y && box.Origin.Y < F.Origin.Y + F.Width)
                            {
                                // make new container
                            }
                        }
                    }
                    +tindex;
                }
            }

            //rotation along X-axis
            else if (orientation_case == 1)
            {
                new_container1.Length = old_container.Length;
                new_container1.Width  = old_container.Width - box.Height;
                new_container1.Height = old_container.Height;

                if (new_container1.Length > 0 && new_container1.Width > 0 && new_container1.Height > 0)
                {
                    new_container1.Origin.X      = point.X;
                    new_container1.Origin.Y      = point.Y + box.Height;
                    new_container1.Origin.Z      = point.Z;
                    new_container1.Still_to_Open = true;
                    Split_Container_open_list[Container_Key].Add(new_container1);
                }

                new_container2.Length = old_container.Length - box.Length;
                new_container2.Width  = old_container.Width;
                new_container2.Height = old_container.Height;

                if (new_container2.Length > 0 && new_container2.Width > 0 && new_container2.Height > 0)
                {
                    new_container2.Origin.X      = point.X + box.Length;
                    new_container2.Origin.Y      = point.Y;
                    new_container2.Origin.Z      = point.Z;
                    new_container2.Still_to_Open = true;
                    Split_Container_open_list[Container_Key].Add(new_container2);
                }

                new_container3.Length = old_container.Length;
                new_container3.Width  = old_container.Width;
                new_container3.Height = old_container.Height - box.Width;

                if (new_container3.Length > 0 && new_container3.Width > 0 && new_container3.Height > 0)
                {
                    new_container3.Origin.X      = point.X;
                    new_container3.Origin.Y      = point.Y;
                    new_container3.Origin.Z      = point.Z + box.Width;
                    new_container3.Still_to_Open = true;
                    Split_Container_open_list[Container_Key].Add(new_container3);
                }
                Split_Container_open_list[Container_Key].RemoveAt(index);
            }

            //rotation along Y-axis
            else if (orientation_case == 2)
            {
                new_container1.Length = old_container.Length;
                new_container1.Width  = old_container.Width - box.Width;
                new_container1.Height = old_container.Height;

                if (new_container1.Length > 0 && new_container1.Width > 0 && new_container1.Height > 0)
                {
                    new_container1.Origin.X      = point.X;
                    new_container1.Origin.Y      = point.Y + box.Width;
                    new_container1.Origin.Z      = point.Z;
                    new_container1.Still_to_Open = true;
                    Split_Container_open_list[Container_Key].Add(new_container1);
                }

                new_container2.Length = old_container.Length - box.Height;
                new_container2.Width  = old_container.Width;
                new_container2.Height = old_container.Height;

                if (new_container2.Length > 0 && new_container2.Width > 0 && new_container2.Height > 0)
                {
                    new_container2.Origin.X      = point.X + box.Height;
                    new_container2.Origin.Y      = point.Y;
                    new_container2.Origin.Z      = point.Z;
                    new_container2.Still_to_Open = true;
                    Split_Container_open_list[Container_Key].Add(new_container2);
                }

                new_container3.Length = old_container.Length;
                new_container3.Width  = old_container.Width;
                new_container3.Height = old_container.Height - box.Length;

                if (new_container3.Length > 0 && new_container3.Width > 0 && new_container3.Height > 0)
                {
                    new_container3.Origin.X      = point.X;
                    new_container3.Origin.Y      = point.Y;
                    new_container3.Origin.Z      = point.Z + box.Length;
                    new_container3.Still_to_Open = true;
                    Split_Container_open_list[Container_Key].Add(new_container3);
                }
                Split_Container_open_list[Container_Key].RemoveAt(index);
            }

            //rotation along z-axis
            else if (orientation_case == 3)
            {
                new_container1.Length = old_container.Length;
                new_container1.Width  = old_container.Width - box.Length;
                new_container1.Height = old_container.Height;

                if (new_container1.Length > 0 && new_container1.Width > 0 && new_container1.Height > 0)
                {
                    new_container1.Origin.X      = point.X;
                    new_container1.Origin.Y      = point.Y + box.Length;
                    new_container1.Origin.Z      = point.Z;
                    new_container1.Still_to_Open = true;
                    Split_Container_open_list[Container_Key].Add(new_container1);
                }

                new_container2.Length = old_container.Length - box.Width;
                new_container2.Width  = old_container.Width;
                new_container2.Height = old_container.Height;

                if (new_container2.Length > 0 && new_container2.Width > 0 && new_container2.Height > 0)
                {
                    new_container2.Origin.X      = point.X + box.Width;
                    new_container2.Origin.Y      = point.Y;
                    new_container2.Origin.Z      = point.Z;
                    new_container2.Still_to_Open = true;
                    Split_Container_open_list[Container_Key].Add(new_container2);
                }

                new_container3.Length = old_container.Length;
                new_container3.Width  = old_container.Width;
                new_container3.Height = old_container.Height - box.Height;

                if (new_container3.Length > 0 && new_container3.Width > 0 && new_container3.Height > 0)
                {
                    new_container3.Origin.X      = point.X;
                    new_container3.Origin.Y      = point.Y;
                    new_container3.Origin.Z      = point.Z + box.Height;
                    new_container3.Still_to_Open = true;
                    Split_Container_open_list[Container_Key].Add(new_container3);
                }
                Split_Container_open_list[Container_Key].RemoveAt(index);
            }

            else if (orientation_case == 4)
            {
                new_container1.Length = old_container.Length;
                new_container1.Width  = old_container.Width - box.Length;
                new_container1.Height = old_container.Height;

                if (new_container1.Length > 0 && new_container1.Width > 0 && new_container1.Height > 0)
                {
                    new_container1.Origin.X      = point.X;
                    new_container1.Origin.Y      = point.Y + box.Length;
                    new_container1.Origin.Z      = point.Z;
                    new_container1.Still_to_Open = true;
                    Split_Container_open_list[Container_Key].Add(new_container1);
                }

                new_container2.Length = old_container.Length - box.Height;
                new_container2.Width  = old_container.Width;
                new_container2.Height = old_container.Height;

                if (new_container2.Length > 0 && new_container2.Width > 0 && new_container2.Height > 0)
                {
                    new_container2.Origin.X      = point.X + box.Height;
                    new_container2.Origin.Y      = point.Y;
                    new_container2.Origin.Z      = point.Z;
                    new_container2.Still_to_Open = true;
                    Split_Container_open_list[Container_Key].Add(new_container2);
                }

                new_container3.Length = old_container.Length;
                new_container3.Width  = old_container.Width;
                new_container3.Height = old_container.Height - box.Width;

                if (new_container3.Length > 0 && new_container3.Width > 0 && new_container3.Height > 0)
                {
                    new_container3.Origin.X      = point.X;
                    new_container3.Origin.Y      = point.Y;
                    new_container3.Origin.Z      = point.Z + box.Width;
                    new_container3.Still_to_Open = true;
                    Split_Container_open_list[Container_Key].Add(new_container3);
                }
                Split_Container_open_list[Container_Key].RemoveAt(index);
            }

            //no-rotation
            else if (orientation_case == 5)
            {
                new_container1.Length = old_container.Length;
                new_container1.Width  = old_container.Width - box.Height;
                new_container1.Height = old_container.Height;

                if (new_container1.Length > 0 && new_container1.Width > 0 && new_container1.Height > 0)
                {
                    new_container1.Origin.X      = point.X;
                    new_container1.Origin.Y      = point.Y + box.Height;
                    new_container1.Origin.Z      = point.Z;
                    new_container1.Still_to_Open = true;
                    Split_Container_open_list[Container_Key].Add(new_container1);
                }

                new_container2.Length = old_container.Length - box.Width;
                new_container2.Width  = old_container.Width;
                new_container2.Height = old_container.Height;

                if (new_container2.Length > 0 && new_container2.Width > 0 && new_container2.Height > 0)
                {
                    new_container2.Origin.X      = point.X + box.Width;
                    new_container2.Origin.Y      = point.Y;
                    new_container2.Origin.Z      = point.Z;
                    new_container2.Still_to_Open = true;
                    Split_Container_open_list[Container_Key].Add(new_container2);
                }

                new_container3.Length = old_container.Length;
                new_container3.Width  = old_container.Width;
                new_container3.Height = old_container.Height - box.Length;

                if (new_container3.Length > 0 && new_container3.Width > 0 && new_container3.Height > 0)
                {
                    new_container3.Origin.X      = point.X;
                    new_container3.Origin.Y      = point.Y;
                    new_container3.Origin.Z      = point.Z + box.Length;
                    new_container3.Still_to_Open = true;
                    Split_Container_open_list[Container_Key].Add(new_container3);
                }
                Split_Container_open_list[Container_Key].RemoveAt(index);
            }
        }
Ejemplo n.º 3
0
 Boolean box_intersect_container(Box b, Int32 box_length, Int32 box_width, Int32 box_height, Containers c)
 {
     if (b.Origin.X >= c.Origin.X + c.Length || b.Origin.X + box_length <= c.Origin.X ||
         b.Origin.Y >= c.Origin.Y + c.Width || b.Origin.Y + box_width <= c.Origin.Y ||
         b.Origin.Z >= c.Origin.Z + c.Height || b.Origin.Z + box_height <= c.Origin.Z)
     {
         return(false);
     }
     else
     {
         return(true);
     }
 }
Ejemplo n.º 4
0
        }   //ending the event handler for Generate button

        private void Load_Data()
        {
            // Created an Optimization object for storing the OptimizationID
            // and OptimizationType of given xml file.
            Optimization optimization_object = new Optimization();

            // Created an Containers object for storing the ContainerID,
            // Length, MinLength.... of the given Container
            Containers container_object = new Containers();

            // Created an Box object for storing the BoxID, Quantity,
            // Length.... of the given Box
            Box box_object = new Box();

            // Create a new xml document
            XmlDocument document = new XmlDocument();

            // loaded the newly created xml document with the input of xml
            // file path
            document.Load(@"" + xmlFileLabel.Text.ToString());

            // Created a list of all the child nodes of <xml> tag
            // which include OptimizationID, OptimizationType,
            // Containers, and Boxes.
            XmlNodeList xnList = document.SelectNodes("/xml[@*]");

            foreach (XmlNode xn in xnList)
            {
                // Selecting the given child nodes of <xml> tag to
                // XmlNode class objects.
                XmlNode OptimizationID   = xn.SelectSingleNode("OptimizationID");
                XmlNode OptimizationType = xn.SelectSingleNode("OptimizationType");
                XmlNode Containers       = xn.SelectSingleNode("Containers");
                XmlNode Boxes            = xn.SelectSingleNode("Boxes");

                // assigning the text of OptimizationID to Optimization class object
                if (OptimizationID != null)
                {
                    optimization_object.OptimizationID = OptimizationID.InnerText;
                }

                // assigning the text of OptimizationType to Optimization class object
                if (OptimizationType != null)
                {
                    optimization_object.OptimizationType = OptimizationType.InnerText;
                }

                if (Containers != null)
                {
                    XmlNodeList innercontainers = Containers.SelectNodes("Containers/Container");
                    foreach (XmlNode node in innercontainers)
                    {
                        if (node != null)
                        {
                            Point3D point = new Point3D();
                            container_object.ContainerID = node["ContainerID"].InnerText;

                            container_object.Length     = Int32.Parse(node["Length"].InnerText);
                            container_object.MinLength  = Int32.Parse(node["MinLength"].InnerText);
                            container_object.MaxLength  = Int32.Parse(node["MaxLength"].InnerText);
                            container_object.StepLenght = Int32.Parse(node["StepLength"].InnerText);

                            container_object.Width     = Int32.Parse(node["Width"].InnerText);
                            container_object.MinWidth  = Int32.Parse(node["MinWidth"].InnerText);
                            container_object.MaxWidth  = Int32.Parse(node["MaxWidth"].InnerText);
                            container_object.StepWidth = Int32.Parse(node["StepWidth"].InnerText);

                            container_object.Height     = Int32.Parse(node["Height"].InnerText);
                            container_object.MinHeight  = Int32.Parse(node["MinHeight"].InnerText);
                            container_object.MaxHeight  = Int32.Parse(node["MaxHeight"].InnerText);
                            container_object.StepHeight = Int32.Parse(node["StepHeight"].InnerText);

                            container_object.MaxWeight     = Double.Parse(node["MaxWeight"].InnerText);
                            container_object.MaxCount      = Int32.Parse(node["MaxCount"].InnerText);
                            container_object.Still_to_Open = true;
                            container_object.Closed        = false;


                            point.X = 0.0F;
                            point.Y = 0.0F;
                            point.Z = 0.0F;
                            container_object.Origin = point;

                            Guillotine3D.ContainerList.Add(container_object.ContainerID, container_object);
                        } // ending if (node != null)
                    }     // ending foreach loop
                }         // ending if (Containers != null)

                if (Boxes != null)
                {
                    XmlNodeList boxlist = Boxes.SelectNodes("Boxes/Box");
                    foreach (XmlNode box in boxlist)
                    {
                        box_object.BoxID    = box["BoxID"].InnerText;
                        box_object.Quantity = Int32.Parse(box["Quantity"].InnerText);
                        box_object.Length   = Int32.Parse(box["Length"].InnerText);
                        box_object.Width    = Int32.Parse(box["Width"].InnerText);
                        box_object.Height   = Int32.Parse(box["Height"].InnerText);
                        box_object.Weight   = Double.Parse(box["Weight"].InnerText);

                        if (box["AllowedRotations"].InnerText.Contains("X"))
                        {
                            box_object.AllowedRotationsX = true;
                        }
                        else
                        {
                            box_object.AllowedRotationsX = false;
                        }

                        if (box["AllowedRotations"].InnerText.Contains("Y"))
                        {
                            box_object.AllowedRotationsY = true;
                        }
                        else
                        {
                            box_object.AllowedRotationsY = false;
                        }

                        if (box["AllowedRotations"].InnerText.Contains("Z"))
                        {
                            box_object.AllowedRotationsZ = true;
                        }
                        else
                        {
                            box_object.AllowedRotationsZ = false;
                        }

                        box_object.IsPlaced = false;

                        if (box["TopOnly"].InnerText.ToUpper() == "FALSE")
                        {
                            box_object.TopOnly = false;
                        }
                        else
                        {
                            box_object.TopOnly = true;
                        }

                        if (box["BottomOnly"].InnerText.ToUpper() == "FALSE")
                        {
                            box_object.TopOnly = false;
                        }
                        else
                        {
                            box_object.TopOnly = true;
                        }

                        Guillotine3D.BoxList.Add(box_object.BoxID, box_object);
                    } // ending foreach (XmlNode box in boxlist)
                }     // ending If (Boxes != null)
            }         // ending foreach (XmlNode xn in xnList)
        }             //ending the Load_Data() function