Packing issue on several containers
petrasvestartas opened this issue · comments
Hi,
I am trying to pack boxes into two containers. But the problem is that all boxes are packed separately for each container. I expected that second container will be filled only if first container is full is it right or not? Is this desired behavior or something wrong is with my code?
//Input
List<Box> b_result = new List<Box>(); //Output of packed boxes
List<Box> b0 = new List<Box>();
List<Box> b1 = new List<Box>();
DA.GetDataList(0, b0);//Gui to get containers
DA.GetDataList(1, b1);//Gui to get items
//Create a list of Container objects, which describes the dimensions of the containers:
List<Container> containers = new List<Container>();
for (int i = 0; i < b0.Count; i++) {
containers.Add(new Container(i, Convert.ToDecimal(b0[i].X.Length), Convert.ToDecimal(b0[i].Z.Length), Convert.ToDecimal(b0[i].Y.Length)));
}
//Create a list of items to pack:
List<Item> itemsToPack = new List<Item>();
for (int i = 0; i < b1.Count; i++) {
itemsToPack.Add(new Item(i, Convert.ToDecimal(b1[i].X.Length), Convert.ToDecimal(b1[i].Z.Length), Convert.ToDecimal(b1[i].Y.Length),1));
}
//Create a list of algorithm IDs corresponding to the algorithms you would like to use. (Currently EB-AFIT is the only algorithm implemented.) Algorithm IDs are listed in the AlgorithmType enum.
List<int> algorithms = new List<int>();
algorithms.Add((int)AlgorithmType.EB_AFIT);
//Call the Pack method on your container list, item list, and algorithm list:
List<ContainerPackingResult> result = PackingService.Pack(containers, itemsToPack, algorithms);
//Extracting values
for(int i = 0; i < result.Count; i++) {
for (int j = 0; j < result[i].AlgorithmPackingResults.Count; j++) {
for(int k = 0; k< result[i].AlgorithmPackingResults[j].PackedItems.Count; k++) {
Point3d origin = new Point3d(
Convert.ToDouble(result[i].AlgorithmPackingResults[j].PackedItems[k].CoordX),
Convert.ToDouble(result[i].AlgorithmPackingResults[j].PackedItems[k].CoordY),
Convert.ToDouble(result[i].AlgorithmPackingResults[j].PackedItems[k].CoordZ)
);
origin += b0[result[i].ContainerID].BoundingBox.Min;
double x_ = Convert.ToDouble(result[i].AlgorithmPackingResults[j].PackedItems[k].PackDimX);
double y_ = Convert.ToDouble(result[i].AlgorithmPackingResults[j].PackedItems[k].PackDimY) ;
double z_ = Convert.ToDouble(result[i].AlgorithmPackingResults[j].PackedItems[k].PackDimZ) ;
b_result.Add(new Box(
new Plane(origin, Vector3d.ZAxis),
new Interval(0, x_),
new Interval(0, y_),
new Interval(0, z_)
));
}
}
}
Hi, there! Yes, the way the service is written, it will try to pack all the items into all of the containers--it is not packing one and then taking the leftovers and packing them in the next. To do what you are trying to do, I suggest taking the pack results from round one, find the "best" result, see which items are in the unpacked list for that result, and then run that subset through a second time, etc. Keep peeling off the best sets in each round and go again with the leftovers. Does that make sense?
Hello, I would like to render the boxes in my scene, the thing is that I dont know what does the coordinates mean, are they the center of the box? if yes we will need to add the value of the boundingBox/2 to the origin!! .. , and i have an issue with the rotation values, they are around 1 2 3 and it doesnt make sense to me..