Skip to content
This repository has been archived by the owner on Jun 29, 2023. It is now read-only.

Commit

Permalink
18_January_2016 work
Browse files Browse the repository at this point in the history
  • Loading branch information
SahibYar committed Jan 19, 2016
1 parent 8e1f633 commit ae45cd2
Show file tree
Hide file tree
Showing 4 changed files with 233 additions and 9 deletions.
37 changes: 33 additions & 4 deletions 3D-Bin-Packing/Box.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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
}
Expand Down
7 changes: 7 additions & 0 deletions 3D-Bin-Packing/Container.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 17 additions & 2 deletions 3D-Bin-Packing/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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")
Expand Down
179 changes: 176 additions & 3 deletions 3D-Bin-Packing/Guillotine3D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,19 @@ class Guillotine3D
// Created a list of boxes for holding all the box objects
public static Dictionary<String, Box> BoxList = new Dictionary<string, Box>();

Dictionary<String, List<Containers>> Split_Container_list = new Dictionary<string, List<Containers>>();
// list of the splitted containers from the given containers.
Dictionary<String, List<Containers>> Split_Container_open_list = new Dictionary<string, List<Containers>>();
Dictionary<String, List<Containers>> Split_Container_closed_list = new Dictionary<string, List<Containers>>();

// list of all the boxes in the given container.
Dictionary<String, List<Box>> Container_Containing_Boxes = new Dictionary<string, List<Box>>();

List<KeyValuePair<String, Box>> 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;
Expand All @@ -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<String, Box> 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<Containers> 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();
}
}
}

0 comments on commit ae45cd2

Please sign in to comment.