diff --git a/3D-Bin-Packing/Box.cs b/3D-Bin-Packing/Box.cs index 114be3b..db89d04 100644 --- a/3D-Bin-Packing/Box.cs +++ b/3D-Bin-Packing/Box.cs @@ -11,12 +11,29 @@ class Box private Int32 b_width; private Int32 b_height; private Double b_weight; - private String b_allowedRotation; + private Boolean b_allowedRotation_x; + private Boolean b_allowedRotation_y; + private Boolean b_allowedRotation_z; private Boolean b_toponly; private Boolean b_bottomonly; private Boolean b_is_placed; #endregion + #region Functions + + //Returns true if Box i > Box j else false + public static Boolean compareVolume(Box i, Box j) + { + return ((i.Height * i.Width * i.Length) > (j.Height * j.Width * j.Length)); + } + + //returns volume of a box; + public Double Volume () + { + return Height * Width * Length; + } + #endregion + #region Properties public Boolean IsPlaced { @@ -71,10 +88,22 @@ public Boolean BottomOnly set { this.b_bottomonly = value; } } - public String AllowedRotations + public Boolean AllowedRotationsX + { + get { return this.b_allowedRotation_x; } + set { this.b_allowedRotation_x = value; } + } + + public Boolean AllowedRotationsY + { + get { return this.b_allowedRotation_y; } + set { this.b_allowedRotation_y = value; } + } + + public Boolean AllowedRotationsZ { - get { return this.b_allowedRotation; } - set { this.b_allowedRotation = value; } + get { return this.b_allowedRotation_z; } + set { this.b_allowedRotation_z = value; } } #endregion } diff --git a/3D-Bin-Packing/Container.cs b/3D-Bin-Packing/Container.cs index af6b3a9..1f262db 100644 --- a/3D-Bin-Packing/Container.cs +++ b/3D-Bin-Packing/Container.cs @@ -41,6 +41,13 @@ class Containers private Point3D origin; #endregion + #region Functions + public Double volume() + { + return Height * Length * Width; + } + #endregion + #region properties public Point3D Origin diff --git a/3D-Bin-Packing/Form1.cs b/3D-Bin-Packing/Form1.cs index a00403a..969bab5 100644 --- a/3D-Bin-Packing/Form1.cs +++ b/3D-Bin-Packing/Form1.cs @@ -117,8 +117,8 @@ private void Load_Data() container_object.MaxCount = Int32.Parse(node["MaxCount"].InnerText); container_object.Still_to_Open = true; container_object.Closed = false; - container_object.Currenlty_Open = false; + point.X = 0.0F; point.Y = 0.0F; point.Z = 0.0F; @@ -140,7 +140,22 @@ private void Load_Data() box_object.Width = Int32.Parse(box["Width"].InnerText); box_object.Height = Int32.Parse(box["Height"].InnerText); box_object.Weight = Double.Parse(box["Weight"].InnerText); - box_object.AllowedRotations = box["AllowedRotations"].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") diff --git a/3D-Bin-Packing/Guillotine3D.cs b/3D-Bin-Packing/Guillotine3D.cs index 603cdba..2f75afd 100644 --- a/3D-Bin-Packing/Guillotine3D.cs +++ b/3D-Bin-Packing/Guillotine3D.cs @@ -15,13 +15,19 @@ class Guillotine3D // Created a list of boxes for holding all the box objects public static Dictionary BoxList = new Dictionary(); - Dictionary> Split_Container_list = new Dictionary>(); + // list of the splitted containers from the given containers. + Dictionary> Split_Container_open_list = new Dictionary>(); + Dictionary> Split_Container_closed_list = new Dictionary>(); + // list of all the boxes in the given container. + Dictionary> Container_Containing_Boxes = new Dictionary>(); + + List> sorted_box_List; /* return the container which has the smallest volume of all the unopened containers; */ - Containers find_smallest_unopen_container () + String find_smallest_unopen_container () { Double volume = ContainerList.First().Value.Height * ContainerList.First().Value.Width * ContainerList.First().Value.Length; String key = ContainerList.First().Key; @@ -34,7 +40,174 @@ Containers find_smallest_unopen_container () key = c.Key; } } - return ContainerList[key]; + return key; + } + + /* + Fill the box with items in it not violating its maximum weight limit + and other constraints + */ + void fill_container(String key) //here the key will be of the smallest available container. + { + // Still to open = false + // means that it is currenlty open. + ContainerList[key].Still_to_Open = false; + + // added the currently opened container in its splitted container list as it is. + Split_Container_open_list[key].Add(ContainerList[key]); + + // rearranging the boxes in descending order of its volume. + re_arranging_boxes(); + + foreach (KeyValuePair box in sorted_box_List) + { + if (!box.Value.IsPlaced) // if the box is not yet placed. + { + + } + //if this box can be contained in the container(splitted continers) + // with out violating the weight and other constraint then + //add this box to the list of container_containing_boxes with Key value + // passed in argument of the funtion + + // also check the placing order by merging 2 or more locations. + + //while placing it in the container, marks its accurate origin. + + // if the box is placed. mark it as is_placed. + + // the box will be considered closed if total unconvered area is < 5% + } + } + + + Boolean has_free_space(String Container_Key, Box box) + { + // list of all the splitted-containers of the given container-key + List temp_list = Split_Container_open_list[Container_Key]; + + //could be placed in only touching the bottom + if (box.BottomOnly) + { + foreach (Containers container in temp_list) + { + //as the object is bottom only so it should be placed on xy-plane only + if (container.Origin.Z == 0.0F && container.volume() >= box.Volume()) //z-axis value should be zero. + { + //no rotation + if (container.Height >= box.Height && + container.Length >= box.Length && + container.Width >= box.Width) + return true; + + else if (box.AllowedRotationsX && + container.Width >= box.Height && + container.Height >= box.Width && + container.Length >= box.Length) + return true; + + else if (box.AllowedRotationsZ && + container.Height >= box.Height && + container.Width >= box.Length && + container.Length >= box.Width) + return true; + + else if (box.AllowedRotationsY && + container.Width >= box.Width && + container.Length >= box.Width && + container.Width >= box.Length) + return true; + } + } + + // check all the bottom containers after merging them + } + else if (box.TopOnly) + { + foreach (Containers container in temp_list) + { + //as the object is bottom only so it should be placed on xy-plane only + if (container.Origin.Z + container.Height == ContainerList[Container_Key].Height + && container.volume() >= box.Volume()) //z-axis value should be zero. + { + //no rotation + if (container.Height >= box.Height && + container.Length >= box.Length && + container.Width >= box.Width) + return true; + + //along X-axis rotation is allowed + else if (box.AllowedRotationsX && + container.Width >= box.Height && + container.Height >= box.Width && + container.Length >= box.Length) + return true; + + //along Z-axis rotation is allowed + else if (box.AllowedRotationsZ && + container.Height >= box.Height && + container.Width >= box.Length && + container.Length >= box.Width) + return true; + + //along Y-axis rotation is allowed + else if (box.AllowedRotationsY && + container.Width >= box.Width && + container.Length >= box.Width && + container.Width >= box.Length) + return true; + } + } + + //after mergin top_only containers + } + else + { + foreach (Containers container in temp_list) + { + if (container.volume() >= box.Volume()) + { + //no rotation + if (container.Height >= box.Height && + container.Length >= box.Length && + container.Width >= box.Width) + return true; + + //along X-axis rotation is allowed + else if (box.AllowedRotationsX && + container.Width >= box.Height && + container.Height >= box.Width && + container.Length >= box.Length) + return true; + + //along Z-axis rotation is allowed + else if (box.AllowedRotationsZ && + container.Height >= box.Height && + container.Width >= box.Length && + container.Length >= box.Width) + return true; + + //along Y-axis rotation is allowed + else if (box.AllowedRotationsY && + container.Width >= box.Width && + container.Length >= box.Width && + container.Width >= box.Length) + return true; + } + } + + //after mergin top_only containers + } + + // if still not available. + return false; + } + //This function rearrange the items in descending order of there volumes. + void re_arranging_boxes() + { + sorted_box_List = BoxList.ToList(); + sorted_box_List.Sort((firstPair, nextPair) => ( firstPair.Value.Width * firstPair.Value.Height * firstPair.Value.Length).CompareTo (nextPair.Value.Length * nextPair.Value.Width * nextPair.Value.Height)); + sorted_box_List.Reverse(); } } }