private BoxQuantityPair FindTheMostSuitableBoxForThePlatform(List <BoxQuantityPair> boxesSet, Box platform) { // Box is the most suitable if after its placing, the distance left to the ceiling is minimum var heightLeft = 100000000000D; BoxQuantityPair theMostSuitableBox = null; foreach (var boxQuantityPair in boxesSet.Where(b => b.Quantity != 0)) { var boxesInStackQuantity = Math.Floor((double)platform.Height / boxQuantityPair.Box.Height); var heightWillBeLeft = platform.Height - boxesInStackQuantity * boxQuantityPair.Box.Height; if (heightWillBeLeft >= 0 && heightWillBeLeft < heightLeft && boxQuantityPair.Box.Length <= platform.Length && boxQuantityPair.Box.Width <= platform.Length && boxQuantityPair.Box.Length <= platform.Width - platform.YPos + Delta && boxQuantityPair.Box.Width <= platform.Width - platform.YPos + Delta) { heightLeft = heightWillBeLeft; theMostSuitableBox = boxQuantityPair; } } return(theMostSuitableBox); }
private void PlaceFirstLevelOfBoxes(BoxQuantityPair boxQuantityPair, Container container) { var box = boxQuantityPair.Box; while (box.Length <= FindDistanceLeftToTheWallOfContainer(container) && boxQuantityPair.Quantity > 0) { RotateBoxToMatchRowsWidth(box); _rowOfBoxes.Add(new Box(box.Name, length: box.Length, width: box.Width, height: box.Height, x: _xo, y: _yo, z: _zo)); boxQuantityPair.Quantity--; _zo += box.Height; _distanceLeftToTheCeiling = container.Height - box.Height; PutTheSameBoxOnTheTop(boxQuantityPair, _xo, _yo, _zo); _distanceLeftToTheCeiling = container.Height; PutTheSameBoxInFrontOf(boxQuantityPair, _yo + box.Width, container.Height); _xo += box.Length; _zo = 0; } }
private void PlaceTheSameBoxOnTheTop(BoxQuantityPair boxQuantityPair, int destinationXPos, int destinationYPos, ref int destinationZPos) { var box = boxQuantityPair.Box; _rowOfBoxes.Add(new Box(box.Name, length: box.Length, width: box.Width, height: box.Height, x: destinationXPos, y: destinationYPos, z: destinationZPos)); boxQuantityPair.Quantity--; destinationZPos += box.Height; _distanceLeftToTheCeiling -= box.Height; }
private void AddSecondRowBox(BoxQuantityPair boxQuantityPair, Box platform) { var box = boxQuantityPair.Box; _rowOfBoxes.Add(new Box(box.Name, length: box.Length, width: box.Width, height: box.Height, x: platform.XPos, y: platform.YPos, z: platform.ZPos)); _distanceLeftToTheCeiling = platform.Height - box.Height; boxQuantityPair.Quantity--; PutTheSameBoxOnTheTop(boxQuantityPair, platform.XPos, platform.YPos, platform.ZPos + box.Height); }
private void PutTheSameBoxOnTheTop(BoxQuantityPair boxQuantityPair, int destinationXPos, int destinationYPos, int destinationZPos) { var isPossibleToPutAnotherOne = true; while (isPossibleToPutAnotherOne) { if (_distanceLeftToTheCeiling > boxQuantityPair.Box.Height && boxQuantityPair.Quantity > 0) { PlaceTheSameBoxOnTheTop(boxQuantityPair, destinationXPos, destinationYPos, ref destinationZPos); } else { isPossibleToPutAnotherOne = false; } } }
public PlacingPlanProviderTest() { var boxA = new BoxQuantityPair { Box = new Box("F", length: 60, width: 60, height: 200), Quantity = 8 }; var boxB = new BoxQuantityPair { Box = new Box("WM", length: 55, width: 60, height: 80), Quantity = 20 }; var boxC = new BoxQuantityPair { Box = new Box("EK", length: 20, width: 20, height: 30), Quantity = 40 }; _container = new Container("Name1", length: 400, width: 300, height: 300); _boxesSet = new List <BoxQuantityPair> { boxA, boxB, boxC }; _placingPlanProvider = new PlacingPlanProvider(); }
private void PutTheSameBoxInFrontOf(BoxQuantityPair boxQuantityPair, int destinationYPos, int containerHeight) { var box = boxQuantityPair.Box; var widthDistanceLeft = _rowWidth - boxQuantityPair.Box.Width; var destinationZPos = 0; while (widthDistanceLeft >= boxQuantityPair.Box.Width && boxQuantityPair.Quantity > 0 && _yo + _rowWidth >= destinationYPos + boxQuantityPair.Box.Width) { _rowOfBoxes.Add(new Box(box.Name, length: box.Length, width: box.Width, height: box.Height, x: _xo, y: destinationYPos, z: destinationZPos)); destinationZPos += box.Height; _distanceLeftToTheCeiling -= box.Height; PutTheSameBoxOnTheTop(boxQuantityPair, _xo, destinationYPos, destinationZPos); destinationZPos = 0; _distanceLeftToTheCeiling = containerHeight; destinationYPos += box.Width; widthDistanceLeft -= boxQuantityPair.Box.Width; } }