protected BoxPosition GetFinalBoxPosition(uint caseIndex) { int iCounted = 0; int iLayer = 0; foreach (ILayer layer in _palletSolution) { BoxLayer bLayer = layer as BoxLayer; if (null != bLayer) { if (iCounted + bLayer.BoxCount > caseIndex) { break; } else { iCounted += bLayer.Count; } } ++iLayer; } BoxLayer layerW = _palletSolution[iLayer] as BoxLayer; return(layerW[(int)caseIndex - iCounted]); }
/// <summary> /// Draw layers /// Images are used during report generation /// </summary> public void DrawLayers(Graphics3D graphics, bool showPallet, int layerIndex) { if (null == _caseSolution) { throw new Exception("No solution defined!"); } BoxCasePalletAnalysis caseAnalysis = _caseSolution.ParentCaseAnalysis; // draw solution uint pickId = 0; int iLayer = 0, iLayerCount = 0; while (iLayerCount <= layerIndex && iLayer < _caseSolution.Count) { ILayer layer = _caseSolution[iLayer]; BoxLayer blayer = layer as BoxLayer; if (null != blayer) { foreach (BoxPosition bPosition in blayer) { graphics.AddBox(new Box(pickId++, caseAnalysis.BoxProperties, bPosition)); } ++iLayerCount; } ++iLayer; } }
/// <summary> /// Draw layers /// Images are used during report generation /// </summary> public void DrawLayers(Graphics3D graphics, bool showPallet, int layerIndex) { if (null == _solution) { throw new Exception("No solution defined!"); } if (!graphics.ShowBoxIds) // -> if box ids are drawn, we do not draw pallet { // draw pallet Pallet pallet = new Pallet(_analysis.PalletProperties); pallet.Draw(graphics, Transform3D.Identity); } // draw solution uint pickId = 0; int iLayer = 0, iLayerCount = 0; while (iLayerCount <= layerIndex && iLayer < _solution.Count) { ILayer layer = _solution[iLayer]; BoxLayer blayer = layer as BoxLayer; if (null != blayer) { foreach (BoxPosition bPosition in blayer) { graphics.AddBox(new Box(pickId++, _analysis.BProperties, bPosition)); } ++iLayerCount; } ++iLayer; } // flush graphics.Flush(); }
protected BoxPosition GetInitialBoxPosition(uint caseIndex) { uint iLayer = 0, iCounted = 0; foreach (ILayer layer in _palletSolution) { BoxLayer bLayer = layer as BoxLayer; if (null != bLayer) { if (iCounted + bLayer.BoxCount > caseIndex) { break; } else { iCounted += (uint)bLayer.Count; } } ++iLayer; } BProperties bProperties = _palletSolution.Analysis.BProperties; double yOffset = 0.5 * (_palletSolution.Analysis.PalletProperties.Width - bProperties.Length); Vector3D vPosition = new Vector3D(_xOffset + (caseIndex - iCounted) * bProperties.Width, yOffset, (_palletSolution.Count - 1 - iLayer) * bProperties.Height); return(new BoxPosition(vPosition, HalfAxis.HAxis.AXIS_Y_P, HalfAxis.HAxis.AXIS_X_N)); }
private List <TruckSolution> GenerateSolutions(TruckAnalysis truckAnalysis) { List <TruckSolution> solutions = new List <TruckSolution>(); HalfAxis.HAxis[] axis = { HalfAxis.HAxis.AXIS_Z_N, HalfAxis.HAxis.AXIS_Z_P }; // build layer using truck length / width foreach (LayerPattern pattern in LayerPattern.All) { for (int swapPos = 0; swapPos < (pattern.CanBeSwapped ? 2 : 1); ++swapPos) { for (int orientation = 0; orientation < 2; ++orientation) { try { Layer2D layer = BuildLayer(truckAnalysis.ParentSolution, truckAnalysis.TruckProperties, truckAnalysis.ConstraintSet , axis[orientation], swapPos == 1); double actualLength = 0.0, actualWidth = 0.0; if (!pattern.GetLayerDimensionsChecked(layer, out actualLength, out actualWidth)) { continue; } pattern.GenerateLayer(layer, actualLength, actualWidth); TruckSolution sol = new TruckSolution("sol", truckAnalysis); BoxLayer boxLayer = new BoxLayer(0.0, 0); foreach (LayerPosition layerPos in layer) { boxLayer.AddPosition(layerPos.Position, layerPos.LengthAxis, layerPos.WidthAxis); } sol.Layer = boxLayer; // insert solution if (sol.PalletCount > 0) { solutions.Add(sol); } } catch (Exception ex) { _log.Error(string.Format("Exception caught: {0}", ex.ToString())); } } } } // sort solutions solutions.Sort(); return(solutions); }
public void Draw(Graphics3D graphics) { // sanity check if (null == _solution) { return; } InterlayerProperties interlayerProperties = _analysis.InterlayerProperties; // draw pallet Pallet pallet = new Pallet(_analysis.PalletProperties); pallet.Draw(graphics, Transform3D.Identity); // draw solution uint pickid = 0; for (int iLayerIndex = 0; iLayerIndex < _solution.LayerCount; ++iLayerIndex) { bool hasInterlayer = false; double zInterlayer = 0.0; BoxLayer blayer = _solution.GetBoxLayer(iLayerIndex, ref hasInterlayer, ref zInterlayer); if (hasInterlayer && (null != interlayerProperties)) { // instantiate box Box box = new Box(pickid++, interlayerProperties); // set position box.Position = new Vector3D( 0.5 * (_analysis.PalletProperties.Length - interlayerProperties.Length) , 0.5 * (_analysis.PalletProperties.Width - interlayerProperties.Width) , zInterlayer); // draw graphics.AddBox(box); } foreach (BoxPosition bPosition in blayer) { graphics.AddBox(new Pack(pickid++, _analysis.PackProperties, bPosition)); } if (_showDimensions) { graphics.AddDimensions( new DimensionCube(BoundingBoxDim(Properties.Settings.Default.DimCasePalletSol1) , Color.Black, false)); graphics.AddDimensions( new DimensionCube(BoundingBoxDim(Properties.Settings.Default.DimCasePalletSol2) , Color.Red, true)); } } }
/// <summary> /// Use this method when solution does not refer an analysis (e.g. when displaying CaseOptimizer result) /// </summary> public void Draw(Graphics3D graphics) { if (null == _boxCaseSolution) { throw new Exception("No box/case solution defined!"); } BoxCaseAnalysis boxCaseAnalysis = _boxCaseSolution.Analysis; // retrieve case properties BProperties boxProperties = boxCaseAnalysis.BProperties; if (null == boxProperties) { return; } BoxProperties caseProperties = boxCaseAnalysis.CaseProperties; // draw case (inside) Case case_ = new Case(caseProperties); case_.DrawInside(graphics); // draw solution uint pickId = 0; foreach (ILayer layer in _boxCaseSolution) { BoxLayer blayer = layer as BoxLayer; if (null != blayer) { foreach (BoxPosition bPosition in blayer) { graphics.AddBox(new Box(pickId++, boxProperties, bPosition)); } } } // get case analysis if (_showDimensions) { graphics.AddDimensions(new DimensionCube( Vector3D.Zero , caseProperties.Length, caseProperties.Width, caseProperties.Height , System.Drawing.Color.Black , true)); graphics.AddDimensions(new DimensionCube( _boxCaseSolution.LoadBoundingBox , System.Drawing.Color.Red , false)); } }
private List<TruckSolution> GenerateSolutions(TruckAnalysis truckAnalysis) { List<TruckSolution> solutions = new List<TruckSolution>(); HalfAxis.HAxis[] axis = { HalfAxis.HAxis.AXIS_Z_N, HalfAxis.HAxis.AXIS_Z_P}; // build layer using truck length / width foreach (LayerPattern pattern in LayerPattern.All) { for (int swapPos = 0; swapPos < (pattern.CanBeSwapped ? 2 : 1); ++swapPos) { for (int orientation = 0; orientation < 2; ++orientation) { try { Layer2D layer = BuildLayer(truckAnalysis.ParentSolution, truckAnalysis.TruckProperties, truckAnalysis.ConstraintSet , axis[orientation], swapPos == 1); double actualLength = 0.0, actualWidth = 0.0; if (!pattern.GetLayerDimensionsChecked(layer, out actualLength, out actualWidth)) continue; pattern.GenerateLayer(layer, actualLength, actualWidth); TruckSolution sol = new TruckSolution("sol", truckAnalysis); BoxLayer boxLayer = new BoxLayer(0.0, 0); foreach (LayerPosition layerPos in layer) boxLayer.AddPosition(layerPos.Position, layerPos.LengthAxis, layerPos.WidthAxis); sol.Layer = boxLayer; // insert solution if (sol.PalletCount > 0) solutions.Add(sol); } catch (Exception ex) { _log.Error(string.Format("Exception caught: {0}", ex.ToString())); } } } } // sort solutions solutions.Sort(); return solutions; }
/// <summary> /// Use this method when solution does not refer an analysis (e.g. when displaying CaseOptimizer result) /// </summary> public static void Draw(Graphics3D graphics , CasePalletSolution solution , BoxProperties boxProperties, InterlayerProperties interlayerProperties, PalletProperties palletProperties) { // draw pallet Pallet pallet = new Pallet(palletProperties); pallet.Draw(graphics, Transform3D.Identity); // draw solution uint pickId = 0; foreach (ILayer layer in solution) { BoxLayer blayer = layer as BoxLayer; if (null != blayer) { foreach (BoxPosition bPosition in blayer) { graphics.AddBox(new Box(pickId++, boxProperties, bPosition)); } } InterlayerPos interlayerPos = layer as InterlayerPos; if (null != interlayerPos && null != interlayerProperties) { Box box = new Box(pickId++, interlayerProperties); // set position box.Position = new Vector3D( 0.5 * (palletProperties.Length - interlayerProperties.Length) , 0.5 * (palletProperties.Width - interlayerProperties.Width) , interlayerPos.ZLow); // draw graphics.AddBox(box); } } // always show dimensions BoxLayer bLayer = solution[solution.Count - 1] as BoxLayer; double palletHeight = solution[solution.Count - 1].ZLow + (null != bLayer ? bLayer.Thickness(boxProperties) : 0.0); // show dimensions graphics.AddDimensions(new DimensionCube(solution.BoundingBox, Color.Black, false)); graphics.AddDimensions(new DimensionCube(solution.LoadBoundingBox, Color.Red, true)); }
public void DrawLayer(Graphics3D graphics, int layerIndex) { // sanity check if (null == _solution) { return; } if (_showDimensions) { BoxLayer layer = layerIndex % 2 == 0 ? _solution.Layer : _solution.LayerSwapped; uint pickId = 0; foreach (BoxPosition bPosition in layer) { graphics.AddBox(new Pack(pickId++, _solution.Analysis.PackProperties, bPosition)); } graphics.AddDimensions( new DimensionCube(layer.BoundingBox(_solution.Analysis.PackProperties) , Color.Black, false)); } }
public void Draw(Graphics2D graphics) { if (null == _solution || _solution.LayerCount == 0) { return; } BoxLayer blayer = _solution.Layer; if (blayer != null) { // initialize Graphics2D object graphics.NumberOfViews = 1; BBox3D bbox = blayer.BoundingBox(_analysis.PackProperties); graphics.SetViewport(0.0f, 0.0f, (float)bbox.Length, (float)bbox.Width); graphics.SetCurrentView(0); graphics.DrawRectangle(Vector2D.Zero, new Vector2D(_analysis.PalletProperties.Length, _analysis.PalletProperties.Width), Color.Black); uint pickId = 0; foreach (BoxPosition bPosition in blayer) { graphics.DrawBox(new Box(pickId++, _analysis.PackProperties, bPosition)); } } }
/// <summary> /// Draw a 2D representation of first (and second, if solution does not have homogeneous layers) layer(s) /// The images produced are used in /// </summary> public void Draw(Graphics2D graphics) { // access case properties BoxCaseAnalysis boxCaseAnalysis = _boxCaseSolution.Analysis; BoxProperties caseProperties = boxCaseAnalysis.CaseProperties; BProperties boxProperties = boxCaseAnalysis.BProperties; // initialize Graphics2D object graphics.NumberOfViews = 1; graphics.SetViewport(0.0f, 0.0f, (float)caseProperties.Length, (float)caseProperties.Width); // access first layer BoxLayer blayer = _boxCaseSolution.BoxLayerFirst; if (null != blayer) { graphics.SetCurrentView(0); graphics.DrawRectangle(Vector2D.Zero, new Vector2D(caseProperties.InsideLength, caseProperties.InsideWidth), Color.Black); uint pickId = 0; foreach (BoxPosition bPosition in blayer) { graphics.DrawBox(new Box(pickId++, boxProperties, bPosition)); } } }
/// <summary> /// Draw case solution /// </summary> public void Draw(Graphics3D graphics) { if (null == _caseSolution) { throw new Exception("No case solution defined!"); } // load pallet solution BoxProperties caseProperties; CasePalletSolution palletSolution = _caseSolution.PalletSolutionDesc.LoadPalletSolution(); if (null == palletSolution) { caseProperties = new BoxProperties(null, _caseSolution.CaseLength, _caseSolution.CaseWidth, _caseSolution.CaseHeight); } else { CasePalletAnalysis palletAnalysis = palletSolution.Analysis; // retrieve case properties caseProperties = palletAnalysis.BProperties as BoxProperties; } if (null == caseProperties) { return; } // draw case (inside) Case case_ = new Case(caseProperties); case_.DrawInside(graphics); // get case analysis BoxCasePalletAnalysis caseAnalysis = _caseSolution.ParentCaseAnalysis; // draw solution uint pickId = 0; foreach (ILayer layer in _caseSolution) { BoxLayer blayer = layer as BoxLayer; if (null != blayer) { foreach (BoxPosition bPosition in blayer) { graphics.AddBox(new Box(pickId++, caseAnalysis.BoxProperties, bPosition)); } } InterlayerPos interlayerPos = layer as InterlayerPos; if (null != interlayerPos) { Box box = new Box(pickId++, caseAnalysis.InterlayerProperties); // set position box.Position = new Vector3D(0.0, 0.0, interlayerPos.ZLow); // draw graphics.AddBox(box); } } // get case analysis if (_showDimensions) { graphics.AddDimensions(new DimensionCube(_caseSolution.CaseLength, _caseSolution.CaseWidth, _caseSolution.CaseHeight)); } }
private List <CasePalletSolution> GenerateSolutions() { // generate best layers Layer[] bestLayers = new Layer[3]; if (_constraintSet.AllowLastLayerOrientationChange) { bestLayers[0] = GenerateBestLayer(_bProperties, _palletProperties, _cornerProperties, _constraintSet, HalfAxis.HAxis.AXIS_X_P); bestLayers[1] = GenerateBestLayer(_bProperties, _palletProperties, _cornerProperties, _constraintSet, HalfAxis.HAxis.AXIS_Y_P); bestLayers[2] = GenerateBestLayer(_bProperties, _palletProperties, _cornerProperties, _constraintSet, HalfAxis.HAxis.AXIS_Z_P); } List <CasePalletSolution> solutions = new List <CasePalletSolution>(); // loop through all patterns foreach (LayerPattern pattern in _patterns) { if (!_constraintSet.AllowPattern(pattern.Name)) { continue; } // loop through all swap positions (if layer can be swapped) for (int swapPos = 0; swapPos < (pattern.CanBeSwapped ? 2 : 1); ++swapPos) { pattern.Swapped = swapPos == 1; // loop through all vertical axes for (int i = 0; i < 3; ++i) { HalfAxis.HAxis axisOrtho1 = (HalfAxis.HAxis)(2 * i); HalfAxis.HAxis axisOrtho2 = (HalfAxis.HAxis)(2 * i + 1); if (!_constraintSet.AllowOrthoAxis(axisOrtho2)) { continue; } try { // build 2 layers (pallet length/width) Layer layer1 = new Layer(_bProperties, _palletProperties, _cornerProperties, _constraintSet, axisOrtho1); Layer layer1_inv = new Layer(_bProperties, _palletProperties, _cornerProperties, _constraintSet, axisOrtho1, true); Layer layer2 = new Layer(_bProperties, _palletProperties, _cornerProperties, _constraintSet, axisOrtho2); Layer layer2_inv = new Layer(_bProperties, _palletProperties, _cornerProperties, _constraintSet, axisOrtho2, true); double actualLength1 = 0.0, actualLength2 = 0.0, actualWidth1 = 0.0, actualWidth2 = 0.0; pattern.GetLayerDimensionsChecked(layer1, out actualLength1, out actualWidth1); pattern.GetLayerDimensionsChecked(layer2, out actualLength2, out actualWidth2); string layerAlignment = string.Empty; for (int j = 0; j < 6; ++j) { Layer layer1T = null, layer2T = null; if (0 == j && _constraintSet.AllowAlignedLayers) { pattern.GenerateLayer(layer1, actualLength1, actualWidth1); layer1T = layer1; layer2T = layer1; layerAlignment = "aligned-1"; } else if (1 == j && _constraintSet.AllowAlignedLayers) { pattern.GenerateLayer(layer2, actualLength2, actualWidth2); layer1T = layer2; layer2T = layer2; layerAlignment = "aligned-2"; } else if (2 == j && _constraintSet.AllowAlternateLayers) { pattern.GenerateLayer(layer1, Math.Max(actualLength1, actualLength2), Math.Max(actualWidth1, actualWidth2)); pattern.GenerateLayer(layer2, Math.Max(actualLength1, actualLength2), Math.Max(actualWidth1, actualWidth2)); layer1T = layer1; layer2T = layer2; layerAlignment = "alternate-12"; } else if (3 == j && _constraintSet.AllowAlternateLayers) { pattern.GenerateLayer(layer1, Math.Max(actualLength1, actualLength2), Math.Max(actualWidth1, actualWidth2)); pattern.GenerateLayer(layer2, Math.Max(actualLength1, actualLength2), Math.Max(actualWidth1, actualWidth2)); layer1T = layer2; layer2T = layer1; layerAlignment = "alternate-21"; } else if (4 == j && _constraintSet.AllowAlternateLayers && pattern.CanBeInverted) { pattern.GenerateLayer(layer1, actualLength1, actualWidth1); pattern.GenerateLayer(layer1_inv, actualLength1, actualWidth1); layer1T = layer1; layer2T = layer1_inv; layerAlignment = "inv-1"; } else if (5 == j && _constraintSet.AllowAlternateLayers && pattern.CanBeInverted) { pattern.GenerateLayer(layer2, actualLength2, actualWidth2); pattern.GenerateLayer(layer2_inv, actualLength2, actualWidth2); layer1T = layer2; layer2T = layer2_inv; layerAlignment = "inv-2"; } if (null == layer1T || null == layer2T || 0 == layer1T.Count || 0 == layer2T.Count) { continue; } // counters string axisName = string.Empty; switch (i) { case 0: axisName = "X"; break; case 1: axisName = "Y"; break; case 2: axisName = "Z"; break; default: break; } string title = string.Format("{0}-{1}-{2}{3}", pattern.Name, axisName, layerAlignment, swapPos == 1 ? "-swapped" : ""); CasePalletSolution sol = new CasePalletSolution(null, title, layer1T == layer2T); int iLayerIndex = 0; double zLayer = _palletProperties.Height; double capThickness = null != _capProperties ? _capProperties.Thickness : 0; int iInterlayer = 0; int iCount = 0; bool maxWeightReached = _constraintSet.UseMaximumPalletWeight && (_palletProperties.Weight + _bProperties.Weight > _constraintSet.MaximumPalletWeight); bool maxHeightReached = _constraintSet.UseMaximumHeight && (zLayer + capThickness + _bProperties.Dimension(axisOrtho1) > _constraintSet.MaximumHeight); bool maxNumberReached = false; // insert anti-slip interlayer id there is one if (_constraintSet.HasInterlayerAntiSlip) { InterlayerPos interlayerPos = sol.CreateNewInterlayer(zLayer, 1); zLayer += _interlayerPropertiesAntiSlip.Thickness; } while (!maxWeightReached && !maxHeightReached && !maxNumberReached) { if (_constraintSet.HasInterlayer) { if (iInterlayer >= _constraintSet.InterlayerPeriod) { InterlayerPos interlayerPos = sol.CreateNewInterlayer(zLayer, 0); zLayer += _interlayerProperties.Thickness; iInterlayer = 0; } ++iInterlayer; } // select current layer type double cornerThickness = null != _cornerProperties ? _cornerProperties.Thickness : 0.0; Layer currentLayer = iLayerIndex % 2 == 0 ? layer1T : layer2T; BoxLayer layer = sol.CreateNewLayer(zLayer, pattern.Name); foreach (LayerPosition layerPos in currentLayer) { ++iCount; maxWeightReached = _constraintSet.UseMaximumPalletWeight && ((iCount * _bProperties.Weight + _palletProperties.Weight) > _constraintSet.MaximumPalletWeight); maxNumberReached = _constraintSet.UseMaximumNumberOfCases && (iCount > _constraintSet.MaximumNumberOfItems); if (!maxWeightReached && !maxNumberReached) { LayerPosition layerPosTemp = AdjustLayerPosition(layerPos); BoxPosition boxPos = new BoxPosition( layerPosTemp.Position - (0.5 * _constraintSet.OverhangX - cornerThickness) * Vector3D.XAxis - (0.5 * _constraintSet.OverhangY - cornerThickness) * Vector3D.YAxis + zLayer * Vector3D.ZAxis , layerPosTemp.LengthAxis , layerPosTemp.WidthAxis ); layer.Add(boxPos); } else { break; } } // increment layer index ++iLayerIndex; zLayer += currentLayer.BoxHeight; // check height maxHeightReached = _constraintSet.UseMaximumHeight && (zLayer + _bProperties.Dimension(axisOrtho1) > _constraintSet.MaximumHeight); } if (maxHeightReached && _constraintSet.AllowLastLayerOrientationChange) { // remaining height double remainingHeight = _constraintSet.MaximumHeight - zLayer; // test to complete with best layer Layer bestLayer = null; int ibestLayerCount = 0; for (int iLayerDir = 0; iLayerDir < 3; ++iLayerDir) { // another direction than the current direction if (iLayerDir == i) { continue; } Layer layer = bestLayers[iLayerDir]; if (null == layer) { continue; } int layerCount = Convert.ToInt32(Math.Floor(remainingHeight / layer.BoxHeight)); if (layerCount < 1) { continue; } if (null == bestLayer || ibestLayerCount * bestLayer.Count < layerCount * layer.Count) { bestLayer = layer; ibestLayerCount = layerCount; } } if (null != bestLayer) { double cornerThickness = null != _cornerProperties ? _cornerProperties.Thickness : 0.0; for (int iAddLayer = 0; iAddLayer < ibestLayerCount; ++iAddLayer) { BoxLayer layer = sol.CreateNewLayer(zLayer, string.Empty); foreach (LayerPosition layerPos in bestLayer) { LayerPosition layerPosTemp = AdjustLayerPosition(layerPos); BoxPosition boxPos = new BoxPosition( layerPosTemp.Position - (0.5 * _constraintSet.OverhangX - cornerThickness) * Vector3D.XAxis - (0.5 * _constraintSet.OverhangY - cornerThickness) * Vector3D.YAxis + zLayer * Vector3D.ZAxis , layerPosTemp.LengthAxis , layerPosTemp.WidthAxis ); layer.Add(boxPos); } zLayer += bestLayer.BoxHeight; } } } // set maximum criterion if (maxNumberReached) { sol.LimitReached = CasePalletSolution.Limit.LIMIT_MAXNUMBERREACHED; } else if (maxWeightReached) { sol.LimitReached = CasePalletSolution.Limit.LIMIT_MAXWEIGHTREACHED; } else if (maxHeightReached) { sol.LimitReached = CasePalletSolution.Limit.LIMIT_MAXHEIGHTREACHED; } // insert solution if (sol.Count > 0) { solutions.Add(sol); } } } catch (NotImplementedException) { _log.Info(string.Format("Pattern {0} is not implemented", pattern.Name)); } catch (Exception ex) { _log.Error(string.Format("Exception caught: {0}", ex.Message)); } } // loop through all vertical axes } // loop through all swap positions (if layer can be swapped) } // loop through all patterns // sort solutions solutions.Sort(); if (ConstraintSet.AllowTwoLayerOrientations && solutions.Count > 0) { // get best solution count int iBestSolutionCount = solutions[0].CaseCount; // if solutions exceeds List <CasePalletSolution> multiOrientSolution = GenerateOptimizedCombinationOfLayers(); foreach (CasePalletSolution sol in multiOrientSolution) { if (sol.CaseCount > iBestSolutionCount) { solutions.Add(sol); } } solutions.Sort(); } // remove unwanted solutions if (_constraintSet.UseNumberOfSolutionsKept && solutions.Count > _constraintSet.NumberOfSolutionsKept) { // get minimum box count int minBoxCount = solutions[_constraintSet.NumberOfSolutionsKept].CaseCount; // remove any solution with less boxes than minBoxCount while (solutions[solutions.Count - 1].CaseCount < minBoxCount) { solutions.RemoveAt(solutions.Count - 1); } } return(solutions); }
private List<PackPalletSolution> GenerateSolutions() { List<PackPalletSolution> solutions = new List<PackPalletSolution>(); HalfAxis.HAxis[] axes = { HalfAxis.HAxis.AXIS_Z_N, HalfAxis.HAxis.AXIS_Z_P }; // loop throught all patterns foreach (LayerPattern pattern in LayerPattern.All) { // loop throught all axes foreach (HalfAxis.HAxis axis in axes) // axis { // loop through Layer2D layer = BuildLayer(_packProperties, _palletProperties, _constraintSet, axis, false, false); double actualLength = 0.0, actualWidth = 0.0; if (!pattern.GetLayerDimensionsChecked(layer, out actualLength, out actualWidth)) continue; pattern.GenerateLayer(layer, actualLength, actualWidth); // filter by layer weight if (_constraintSet.MaximumLayerWeight.Activated && (layer.Count * _packProperties.Weight > _constraintSet.MaximumLayerWeight.Value)) continue; // filter by maximum space if (_constraintSet.MaximumSpaceAllowed.Activated && layer.MaximumSpace > _constraintSet.MaximumSpaceAllowed.Value) continue; double layerHeight = layer.BoxHeight; string title = string.Format("{0}-{1}", pattern.Name, axis.ToString()); double zLayer = 0.0; BoxLayer boxLayer = new BoxLayer(zLayer, 0); foreach (LayerPosition layerPos in layer) { LayerPosition layerPosTemp = AdjustLayerPosition(layerPos); BoxPosition boxPos = new BoxPosition( layerPosTemp.Position - (0.5 * _constraintSet.OverhangX) * Vector3D.XAxis - (0.5 * _constraintSet.OverhangY) * Vector3D.YAxis + zLayer * Vector3D.ZAxis , layerPosTemp.LengthAxis , layerPosTemp.WidthAxis ); boxLayer.Add(boxPos); } boxLayer.MaximumSpace = layer.MaximumSpace; BBox3D layerBBox = boxLayer.BoundingBox(_packProperties); // filter by overhangX if (_constraintSet.MinOverhangX.Activated && (0.5 * (layerBBox.Length - _palletProperties.Length) < _constraintSet.MinOverhangX.Value)) continue; // filter by overhangY if (_constraintSet.MinOverhangY.Activated && (0.5 * (layerBBox.Width - _palletProperties.Width) < _constraintSet.MinOverhangY.Value)) continue; double interlayerThickness = null != _interlayerProperties ? _interlayerProperties.Thickness : 0; double interlayerWeight = null != _interlayerProperties ? _interlayerProperties.Weight : 0; PackPalletSolution sol = new PackPalletSolution(null, title, boxLayer); int noLayer = 1, noInterlayer = (null != _interlayerProperties && _constraintSet.HasFirstInterlayer) ? 1 : 0; bool maxHeightReached = _constraintSet.MaximumPalletHeight.Activated && (_packProperties.Height + noInterlayer * interlayerThickness + noLayer * layer.BoxHeight) > _constraintSet.MaximumPalletHeight.Value; bool maxWeightReached = _constraintSet.MaximumPalletWeight.Activated && (_palletProperties.Weight + noInterlayer * interlayerWeight + noLayer * boxLayer.Count * _packProperties.Weight > _constraintSet.MaximumPalletWeight.Value); noLayer = 0; noInterlayer = 0; int iCountInterlayer = 0, iCountSwap = 1; bool bSwap = false; while (!maxHeightReached && !maxWeightReached) { bool bInterlayer = (0 == iCountInterlayer) && ((noLayer != 0) || _constraintSet.HasFirstInterlayer); // actually insert new layer sol.AddLayer(bSwap, bInterlayer); // increment number of layers noLayer++; noInterlayer += (bInterlayer ? 1 : 0); // update iCountInterlayer && iCountSwap ++iCountInterlayer; if (iCountInterlayer >= _constraintSet.InterlayerPeriod) iCountInterlayer = 0; ++iCountSwap; if (iCountSwap > _constraintSet.LayerSwapPeriod) { iCountSwap = 1; bSwap = !bSwap; } // update maxHeightReached & maxWeightReached maxHeightReached = _constraintSet.MaximumPalletHeight.Activated && (_palletProperties.Height + (noInterlayer + (iCountInterlayer == 0 ? 1 : 0)) * interlayerThickness + (noLayer + 1) * layer.BoxHeight) > _constraintSet.MaximumPalletHeight.Value; maxWeightReached = _constraintSet.MaximumPalletWeight.Activated && (_palletProperties.Weight + (noInterlayer + (iCountInterlayer == 0 ? 1 : 0)) * interlayerWeight + (noLayer + 1) * boxLayer.Count * _packProperties.Weight > _constraintSet.MaximumPalletWeight.Value); } if (sol.PackCount > 0) solutions.Add(sol); } // axis } // pattern solutions.Sort(); return solutions; }
private List <BoxCasePalletSolution> GenerateSolutions() { List <BoxCasePalletSolution> solutions = new List <BoxCasePalletSolution>(); // loop through all pallet solutions foreach (PalletSolutionDesc desc in _palletSolutionList) { CasePalletSolution palletSolution = desc.LoadPalletSolution(); if (null == palletSolution) { _log.Warn(string.Format("Failed to load pallet solution ")); continue; } BoxProperties caseProperties = palletSolution.Analysis.BProperties as BoxProperties; // loop through all patterns foreach (LayerPattern pattern in _patterns) { if (!_constraintSet.AllowPattern(pattern.Name)) { continue; } // loop through all swap positions (if layer can be swapped) for (int swapPos = 0; swapPos < (pattern.CanBeSwapped ? 2 : 1); ++swapPos) { pattern.Swapped = swapPos == 1; // loop through all vertical axes for (int i = 0; i < 3; ++i) { HalfAxis.HAxis axisOrtho1 = (HalfAxis.HAxis)(2 * i); HalfAxis.HAxis axisOrtho2 = (HalfAxis.HAxis)(2 * i + 1); if (!_constraintSet.AllowOrthoAxis(axisOrtho2)) { continue; } try { // build 2 layers (pallet length/width) Layer layer1 = new Layer(_boxProperties, caseProperties, axisOrtho1); Layer layer2 = new Layer(_boxProperties, caseProperties, axisOrtho2); double actualLength1 = 0.0, actualLength2 = 0.0, actualWidth1 = 0.0, actualWidth2 = 0.0; bool bResult1 = pattern.GetLayerDimensionsChecked(layer1, out actualLength1, out actualWidth1); bool bResult2 = pattern.GetLayerDimensionsChecked(layer2, out actualLength2, out actualWidth2); string layerAlignment = string.Empty; for (int j = 0; j < 4; ++j) { Layer layer1T = null, layer2T = null; if (0 == j && _constraintSet.AllowAlignedLayers && bResult1) { pattern.GenerateLayer(layer1, actualLength1, actualWidth1); layer1T = layer1; layer2T = layer1; layerAlignment = "aligned-1"; } else if (1 == j && _constraintSet.AllowAlignedLayers && bResult2) { pattern.GenerateLayer(layer2, actualLength2, actualWidth2); layer1T = layer2; layer2T = layer2; layerAlignment = "aligned-2"; } else if (2 == j && _constraintSet.AllowAlternateLayers && bResult1 && bResult2) { pattern.GenerateLayer(layer1, Math.Max(actualLength1, actualLength2), Math.Max(actualWidth1, actualWidth2)); pattern.GenerateLayer(layer2, Math.Max(actualLength1, actualLength2), Math.Max(actualWidth1, actualWidth2)); layer1T = layer1; layer2T = layer2; layerAlignment = "alternate-12"; } else if (3 == j && _constraintSet.AllowAlternateLayers && bResult1 && bResult2) { pattern.GenerateLayer(layer1, Math.Max(actualLength1, actualLength2), Math.Max(actualWidth1, actualWidth2)); pattern.GenerateLayer(layer2, Math.Max(actualLength1, actualLength2), Math.Max(actualWidth1, actualWidth2)); layer1T = layer2; layer2T = layer1; layerAlignment = "alternate-21"; } if (null == layer1T || null == layer2T || 0 == layer1T.Count || 0 == layer2T.Count) { continue; } // counters string axisName = string.Empty; switch (i) { case 0: axisName = "X"; break; case 1: axisName = "Y"; break; case 2: axisName = "Z"; break; default: break; } string title = string.Format("{0}-{1}-{2}{3}", pattern.Name, axisName, layerAlignment, swapPos == 1 ? "-swapped" : ""); BoxCasePalletSolution sol = new BoxCasePalletSolution(null, title, desc, layer1T == layer2T); int iLayerIndex = 0; bool innerLoopStop = false; double offsetX = 0.5 * (caseProperties.Length - caseProperties.InsideLength); double offsetY = 0.5 * (caseProperties.Width - caseProperties.InsideWidth); double zLayer = 0.5 * (caseProperties.Height - caseProperties.InsideHeight); int iInterlayer = 0; int boxCount = 0; while ( !innerLoopStop && ((zLayer + _boxProperties.Dimension(axisOrtho1) < caseProperties.InsideHeight)) ) { if (_constraintSet.HasInterlayer) { if (iInterlayer >= _constraintSet.InterlayerPeriod) { InterlayerPos interlayerPos = sol.CreateNewInterlayer(zLayer, 0); zLayer += _interlayerProperties.Thickness; iInterlayer = 0; } ++iInterlayer; } // select current layer type Layer currentLayer = iLayerIndex % 2 == 0 ? layer1T : layer2T; BoxLayer layer = sol.CreateNewLayer(zLayer, pattern.Name); foreach (LayerPosition layerPos in currentLayer) { int iCount = sol.Count + 1; innerLoopStop = (_constraintSet.UseMaximumCaseWeight && ((boxCount + 1) * _boxProperties.Weight + caseProperties.Weight > _constraintSet.MaximumCaseWeight)) || (_constraintSet.UseMaximumNumberOfItems && ((boxCount + 1) > _constraintSet.MaximumNumberOfItems)); if (!innerLoopStop) { BoxPosition boxPos = new BoxPosition( layerPos.Position + offsetX * Vector3D.XAxis + offsetY * Vector3D.YAxis + zLayer * Vector3D.ZAxis , layerPos.LengthAxis , layerPos.WidthAxis ); layer.Add(boxPos); ++boxCount; } else { break; } } // increment layer index ++iLayerIndex; zLayer += currentLayer.BoxHeight; } // insert solution if ( sol.Count > 0 && (!_constraintSet.UseMinimumNumberOfItems || sol.Count >= _constraintSet.MinimumNumberOfItems) ) { solutions.Add(sol); } } } catch (NotImplementedException) { _log.Info(string.Format("Pattern {0} is not implemented", pattern.Name)); } catch (Exception ex) { _log.Error(string.Format("Exception caught: {0}", ex.Message)); } } // loop through all vertical axes } // loop through all swap positions (if layer can be swapped) } // loop through all patterns } // loop through all pallet solutions // sort solutions solutions.Sort(); // return list of solutions return(solutions); }
public BoxLayer GetBoxLayer(int iLayerIndex, ref bool hasInterlayer, ref double zInterlayer) { if (null == _parentAnalysis) throw new Exception("_parentAnalysis not set."); double interlayerThickness = (null != _parentAnalysis.InterlayerProperties) ? _parentAnalysis.InterlayerProperties.Thickness : 0.0; double packHeight = _parentAnalysis.PackProperties.Height; double zLow = _parentAnalysis.PalletProperties.Height; int i = 0; while (i <= iLayerIndex-1) { LayerDescriptor desc = _listLayers[i]; zLow += (desc.HasInterlayer ? interlayerThickness : 0.0) + packHeight; ++i; } zInterlayer = zLow; hasInterlayer = _listLayers[iLayerIndex].HasInterlayer; zLow += hasInterlayer ? interlayerThickness : 0.0; Transform3D swapTransform = Transform3D.Identity; if (_listLayers[iLayerIndex].Swapped) { Matrix4D matRot = new Matrix4D( -1.0, 0.0, 0.0, _parentAnalysis.PalletProperties.Length , 0.0, -1.0, 0.0, _parentAnalysis.PalletProperties.Width , 0.0, 0.0, 1.0, 0.0 , 0.0, 0.0, 0.0, 1.0); swapTransform = new Transform3D(matRot); } // build BoxLayer BoxLayer layer = new BoxLayer(zLow + (hasInterlayer ? interlayerThickness : 0.0), 0); foreach (BoxPosition b in _layer) { layer.Add( new BoxPosition( swapTransform.transform(b.Position + zLow * Vector3D.ZAxis) , HalfAxis.Transform(b.DirectionLength, swapTransform) , HalfAxis.Transform(b.DirectionWidth, swapTransform) ) ); } return layer; }
public PackPalletSolution(PackPalletAnalysis analysis, string title, BoxLayer layer) { _parentAnalysis = analysis; _title = title; _layer = layer; }
public override void Draw(Graphics3D graphics, bool showDimensions) { // clear list of picking box ClearPickingBoxes(); if (null == _solution) { return; } Analysis analysis = _solution.Analysis; AnalysisCasePallet analysisCasePallet = analysis as AnalysisCasePallet; AnalysisBoxCase analysisBoxCase = analysis as AnalysisBoxCase; if (null != analysisCasePallet) { // ### draw pallet Pallet pallet = new Pallet(analysisCasePallet.PalletProperties); pallet.Draw(graphics, Transform3D.Identity); } else if (null != analysisBoxCase) { // draw case (inside) Case case_ = new Case(analysisBoxCase._caseProperties); case_.DrawInside(graphics); } // ### draw solution uint layerId = 0, pickId = 0; List <ILayer> layers = _solution.Layers; foreach (ILayer layer in layers) { // ### layer of boxes BoxLayer blayer = layer as BoxLayer; if (null != blayer) { BBox3D bbox = new BBox3D(); foreach (BoxPosition bPosition in blayer) { Box b = null; if (analysis.Content is PackProperties) { b = new Pack(pickId++, analysis.Content as PackProperties, bPosition); } else { b = new Box(pickId++, analysis.Content, bPosition); } graphics.AddBox(b); bbox.Extend(b.BBox); } // add layer BBox AddPickingBox(bbox, layerId); // draw bounding box around selected layer if (layerId == _solution.SelectedLayerIndex) { DrawLayerBoundingBox(graphics, bbox); } ++layerId; } // ### interlayer InterlayerPos interlayerPos = layer as InterlayerPos; if (null != interlayerPos) { InterlayerProperties interlayerProp = _solution.Interlayers[interlayerPos.TypeId]; if (null != interlayerProp) { Box box = new Box(pickId++, interlayerProp); box.Position = new Vector3D( 0.5 * (analysis.ContainerDimensions.X - interlayerProp.Length) , 0.5 * (analysis.ContainerDimensions.Y - interlayerProp.Width) , interlayerPos.ZLow ); graphics.AddBox(box); } } } BBox3D loadBBox = _solution.BBoxLoad; BBox3D loadBBoxWDeco = _solution.BBoxLoadWDeco; if (null != analysisCasePallet) { #region Pallet corners // ### pallet corners : Begin Corner[] corners = new Corner[4]; if (analysisCasePallet.HasPalletCorners) { // positions Vector3D[] cornerPositions = { loadBBox.PtMin , new Vector3D(loadBBox.PtMax.X, loadBBox.PtMin.Y, loadBBox.PtMin.Z) , new Vector3D(loadBBox.PtMax.X, loadBBox.PtMax.Y, loadBBox.PtMin.Z) , new Vector3D(loadBBox.PtMin.X, loadBBox.PtMax.Y, loadBBox.PtMin.Z) }; // length axes HalfAxis.HAxis[] lAxes = { HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Y_P, HalfAxis.HAxis.AXIS_X_N, HalfAxis.HAxis.AXIS_Y_N }; // width axes HalfAxis.HAxis[] wAxes = { HalfAxis.HAxis.AXIS_Y_P, HalfAxis.HAxis.AXIS_X_N, HalfAxis.HAxis.AXIS_Y_N, HalfAxis.HAxis.AXIS_X_P }; // corners if (analysisCasePallet.HasPalletCorners) { for (int i = 0; i < 4; ++i) { corners[i] = new Corner(0, analysisCasePallet.PalletCornerProperties); corners[i].Height = Math.Min(analysisCasePallet.PalletCornerProperties.Length, loadBBox.Height); corners[i].SetPosition(cornerPositions[i], lAxes[i], wAxes[i]); corners[i].DrawBegin(graphics); } } } #endregion #region Pallet film // ### pallet film Film film = null; if (analysisCasePallet.HasPalletFilm) { PalletFilmProperties palletFilmProperties = analysisCasePallet.PalletFilmProperties; film = new Film( palletFilmProperties.Color, palletFilmProperties.UseTransparency, palletFilmProperties.UseHatching, palletFilmProperties.HatchSpacing, palletFilmProperties.HatchAngle); film.AddRectangle(new FilmRectangle(loadBBoxWDeco.PtMin, HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Z_P, new Vector2D(loadBBoxWDeco.Length, loadBBoxWDeco.Height), 0.0)); film.AddRectangle(new FilmRectangle(loadBBoxWDeco.PtMin + loadBBoxWDeco.Length * Vector3D.XAxis, HalfAxis.HAxis.AXIS_Y_P, HalfAxis.HAxis.AXIS_Z_P, new Vector2D(loadBBoxWDeco.Width, loadBBoxWDeco.Height), 0.0)); film.AddRectangle(new FilmRectangle(loadBBoxWDeco.PtMin + loadBBoxWDeco.Length * Vector3D.XAxis + loadBBoxWDeco.Width * Vector3D.YAxis, HalfAxis.HAxis.AXIS_X_N, HalfAxis.HAxis.AXIS_Z_P, new Vector2D(loadBBoxWDeco.Length, loadBBoxWDeco.Height), 0.0)); film.AddRectangle(new FilmRectangle(loadBBoxWDeco.PtMin + loadBBoxWDeco.Width * Vector3D.YAxis, HalfAxis.HAxis.AXIS_Y_N, HalfAxis.HAxis.AXIS_Z_P, new Vector2D(loadBBoxWDeco.Width, loadBBoxWDeco.Height), 0.0)); film.AddRectangle(new FilmRectangle(loadBBoxWDeco.PtMin + loadBBoxWDeco.Height * Vector3D.ZAxis, HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Y_P, new Vector2D(loadBBoxWDeco.Length, loadBBoxWDeco.Width), UnitsManager.ConvertLengthFrom(200.0, UnitsManager.UnitSystem.UNIT_METRIC1))); film.DrawBegin(graphics); } #endregion #region Pallet corners // pallet corners : End if (analysisCasePallet.HasPalletCorners) { for (int i = 0; i < 4; ++i) { corners[i].DrawEnd(graphics); } } #endregion #region Pallet Cap // ### pallet cap if (analysisCasePallet.HasPalletCap) { PalletCapProperties capProperties = analysisCasePallet.PalletCapProperties; Vector3D pos = new Vector3D( 0.5 * (analysisCasePallet.PalletProperties.Length - capProperties.Length), 0.5 * (analysisCasePallet.PalletProperties.Width - capProperties.Width), loadBBox.PtMax.Z - capProperties.InsideHeight); PalletCap cap = new PalletCap(0, capProperties, pos); cap.DrawEnd(graphics); } #endregion #region Pallet film // pallet film : End if (analysisCasePallet.HasPalletFilm) { film.DrawEnd(graphics); } #endregion } // ### dimensions if (showDimensions) { graphics.AddDimensions( new DimensionCube(BoundingBoxDim(Properties.Settings.Default.DimCasePalletSol1) , Color.Black, false)); graphics.AddDimensions( new DimensionCube(BoundingBoxDim(Properties.Settings.Default.DimCasePalletSol2) , Color.Red, true)); } }
public void Draw(Graphics3D graphics) { if (null == _truckSolution) { throw new Exception("No trucksolution defined!"); } // draw truck Truck truck = new Truck(_truckSolution.ParentTruckAnalysis.TruckProperties); truck.DrawBegin(graphics); truck.DrawEnd(graphics); // get pallet height CasePalletAnalysis analysis = _truckSolution.ParentTruckAnalysis.ParentAnalysis; double palletLength = _truckSolution.ParentTruckAnalysis.ParentSolution.PalletLength; double palletWidth = _truckSolution.ParentTruckAnalysis.ParentSolution.PalletWidth; double palletHeight = _truckSolution.ParentTruckAnalysis.ParentSolution.PalletHeight; // get parent pallet solution CasePalletSolution sol = _truckSolution.ParentTruckAnalysis.ParentSolution; // draw solution uint pickIdGlobal = 0; for (int i = 0; i < _truckSolution.NoLayers; ++i) { foreach (BoxPosition bPositionLayer in _truckSolution.Layer) { BoxPosition bPalletPosition = new BoxPosition( new Vector3D( bPositionLayer.Position.X , bPositionLayer.Position.Y , bPositionLayer.Position.Z + palletHeight * i) , bPositionLayer.DirectionLength , bPositionLayer.DirectionWidth); if (_showDetails) { // build transformation Transform3D transformPallet = bPalletPosition.Transformation; // draw pallet Pallet pallet = new Pallet(analysis.PalletProperties); pallet.Draw(graphics, transformPallet); // draw solution uint pickId = 0; foreach (ILayer layer in sol) { BoxLayer bLayer = layer as BoxLayer; if (null != bLayer) { foreach (BoxPosition bPosition in bLayer) { graphics.AddBox(new Box(pickId++, analysis.BProperties, BoxPosition.Transform(bPosition, transformPallet))); } } InterlayerPos interlayerPos = layer as InterlayerPos; if (null != interlayerPos) { BoxPosition iPos = new BoxPosition(new Vector3D(0.0, 0.0, interlayerPos.ZLow), HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Y_P); graphics.AddBox(new Box(pickId++, analysis.InterlayerProperties, BoxPosition.Transform(iPos, transformPallet))); } } } else { Box b = new Box(pickIdGlobal++, new BoxProperties(null, palletLength, palletWidth, palletHeight), bPalletPosition); b.SetAllFacesColor(Color.Chocolate); graphics.AddBox(b); } } } // fluch graphics.UseBoxelOrderer = false; // can not use boxel orderer for full truck view -> too slow... }
/// <summary> /// build optimal solutions with 2 layer types /// </summary> /// <returns></returns> private List <CasePalletSolution> GenerateOptimizedCombinationOfLayers() { List <CasePalletSolution> solutions = new List <CasePalletSolution>(); // generate best layers Layer[] bestLayers = new Layer[3]; bestLayers[0] = GenerateBestLayer(_bProperties, _palletProperties, _cornerProperties, _constraintSet, HalfAxis.HAxis.AXIS_X_P); bestLayers[1] = GenerateBestLayer(_bProperties, _palletProperties, _cornerProperties, _constraintSet, HalfAxis.HAxis.AXIS_Y_P); bestLayers[2] = GenerateBestLayer(_bProperties, _palletProperties, _cornerProperties, _constraintSet, HalfAxis.HAxis.AXIS_Z_P); string[] dir = { "X", "Y", "Z" }; for (int i = 0; i < 3; ++i) { HalfAxis.HAxis axisOrtho = (HalfAxis.HAxis)(2 * i + 1); HalfAxis.HAxis axis0 = (HalfAxis.HAxis)((2 * (i + 1)) % 6 + 1); HalfAxis.HAxis axis1 = (HalfAxis.HAxis)((2 * (i + 2)) % 6 + 1); int noLayer0 = 0, noLayer1 = 0; if (GetOptimalRequest( _bProperties.Dimension(axis0), bestLayers[i % 3].Count , _bProperties.Dimension(axis1), bestLayers[(i + 1) % 3].Count , out noLayer0, out noLayer1)) { Layer layer0 = bestLayers[i % 3]; Layer layer1 = bestLayers[(i + 1) % 3]; // sol0 CasePalletSolution sol0 = new CasePalletSolution(null, string.Format("combination_{0}{1}", dir[i % 3], dir[(i % 3) + 1]), false); double zLayer = _palletProperties.Height; double cornerThickness = null != _cornerProperties ? _cornerProperties.Thickness : 0.0; for (int j = 0; j < noLayer0; ++j) { BoxLayer layer = sol0.CreateNewLayer(zLayer, string.Empty); foreach (LayerPosition layerPos in layer0) { LayerPosition layerPosTemp = AdjustLayerPosition(layerPos); BoxPosition boxPos = new BoxPosition( layerPosTemp.Position - 0.5 * _constraintSet.OverhangX * Vector3D.XAxis - 0.5 * _constraintSet.OverhangY * Vector3D.YAxis + zLayer * Vector3D.ZAxis , layerPosTemp.LengthAxis , layerPosTemp.WidthAxis ); layer.Add(boxPos); } zLayer += layer0.BoxHeight; } for (int j = 0; j < noLayer1; ++j) { BoxLayer layer = sol0.CreateNewLayer(zLayer, string.Empty); foreach (LayerPosition layerPos in layer1) { LayerPosition layerPosTemp = AdjustLayerPosition(layerPos); BoxPosition boxPos = new BoxPosition( layerPosTemp.Position - (0.5 * _constraintSet.OverhangX - cornerThickness) * Vector3D.XAxis - (0.5 * _constraintSet.OverhangY - cornerThickness) * Vector3D.YAxis + zLayer * Vector3D.ZAxis , layerPosTemp.LengthAxis , layerPosTemp.WidthAxis ); layer.Add(boxPos); } zLayer += layer1.BoxHeight; } solutions.Add(sol0); // sol1 CasePalletSolution sol1 = new CasePalletSolution(null, string.Format("combination_{0}{1}", dir[i % 3], dir[(i % 3) + 1]), false); zLayer = _palletProperties.Height; for (int j = 0; j < noLayer0; ++j) { BoxLayer layer = sol1.CreateNewLayer(zLayer, string.Empty); foreach (LayerPosition layerPos in layer1) { LayerPosition layerPosTemp = AdjustLayerPosition(layerPos); BoxPosition boxPos = new BoxPosition( layerPosTemp.Position - (0.5 * _constraintSet.OverhangX - cornerThickness) * Vector3D.XAxis - (0.5 * _constraintSet.OverhangY - cornerThickness) * Vector3D.YAxis + zLayer * Vector3D.ZAxis , layerPosTemp.LengthAxis , layerPosTemp.WidthAxis ); layer.Add(boxPos); } zLayer += layer1.BoxHeight; } for (int j = 0; j < noLayer1; ++j) { BoxLayer layer = sol1.CreateNewLayer(zLayer, string.Empty); foreach (LayerPosition layerPos in layer0) { LayerPosition layerPosTemp = AdjustLayerPosition(layerPos); BoxPosition boxPos = new BoxPosition( layerPosTemp.Position - (0.5 * _constraintSet.OverhangX - cornerThickness) * Vector3D.XAxis - (0.5 * _constraintSet.OverhangY - cornerThickness) * Vector3D.YAxis + zLayer * Vector3D.ZAxis , layerPosTemp.LengthAxis , layerPosTemp.WidthAxis ); layer.Add(boxPos); } zLayer += layer0.BoxHeight; } solutions.Add(sol1); } } return(solutions); }
/// <summary> /// Draw a 2D representation of first (and second, if solution does not have homogeneous layers) layer(s) /// The images produced are used in /// </summary> public void Draw(Graphics2D graphics) { if (null == _solution || _solution.Count == 0) { return; } bool showAxis = false; if (_solution.HasHomogeneousLayers) { // initialize Graphics2D object graphics.NumberOfViews = 1; graphics.SetViewport(0.0f, 0.0f, (float)_solution.PalletLength, (float)_solution.PalletWidth); BoxLayer blayer = _solution.CaseLayerFirst; if (blayer != null) { graphics.SetCurrentView(0); graphics.DrawRectangle(Vector2D.Zero, new Vector2D(_analysis.PalletProperties.Length, _analysis.PalletProperties.Width), Color.Black); uint pickId = 0; foreach (BoxPosition bPosition in blayer) { graphics.DrawBox(new Box(pickId++, _analysis.BProperties, bPosition)); } // draw axes if (showAxis) { // draw axis X graphics.DrawLine(Vector2D.Zero, new Vector2D(_analysis.PalletProperties.Length, 0.0), Color.Red); // draw axis Y graphics.DrawLine(Vector2D.Zero, new Vector2D(0.0, _analysis.PalletProperties.Width), Color.Green); } } } else { graphics.NumberOfViews = 2; graphics.SetViewport(0.0f, 0.0f, (float)_analysis.PalletProperties.Length, (float)_analysis.PalletProperties.Width); // get first box layer if (_solution.CaseLayersCount < 1) { return; } BoxLayer blayer0 = _solution.CaseLayerFirst; if (blayer0 != null) { graphics.SetCurrentView(0); graphics.DrawRectangle(Vector2D.Zero, new Vector2D(_analysis.PalletProperties.Length, _analysis.PalletProperties.Width), Color.Black); uint pickId = 0; foreach (BoxPosition bPosition in blayer0) { graphics.DrawBox(new Box(pickId++, _analysis.BProperties, bPosition)); } // show axes if (showAxis) { // draw axis X graphics.DrawLine(Vector2D.Zero, new Vector2D(_analysis.PalletProperties.Length, 0.0), Color.Red); // draw axis Y graphics.DrawLine(Vector2D.Zero, new Vector2D(0.0, _analysis.PalletProperties.Width), Color.Green); } } // get second box layer if (_solution.CaseLayersCount < 2) { return; } BoxLayer blayer1 = _solution.CaseLayerSecond; if (null == blayer1 && _solution.Count > 2) { blayer1 = _solution[2] as BoxLayer; } if (blayer1 != null) { graphics.SetCurrentView(1); graphics.DrawRectangle(Vector2D.Zero, new Vector2D(_analysis.PalletProperties.Length, _analysis.PalletProperties.Width), Color.Black); uint pickId = 0; foreach (BoxPosition bPosition in blayer1) { graphics.DrawBox(new Box(pickId++, _analysis.BProperties, bPosition)); } // show axes if (showAxis) { // draw axis X graphics.DrawLine(Vector2D.Zero, new Vector2D(_analysis.PalletProperties.Length, 0.0), Color.Red); // draw axis Y graphics.DrawLine(Vector2D.Zero, new Vector2D(0.0, _analysis.PalletProperties.Width), Color.Green); } } } }
private List <BoxCaseSolution> GenerateSolutions() { List <BoxCaseSolution> solutions = new List <BoxCaseSolution>(); int[] patternColumnCount = new int[6]; // loop throw all patterns foreach (LayerPattern pattern in _patterns) { // loop through all vertical axes for (int i = 0; i < 6; ++i) { HalfAxis.HAxis axisOrtho = (HalfAxis.HAxis)i; if (!_constraintSet.AllowOrthoAxis(axisOrtho)) { continue; } try { // build layer Layer layer = new Layer(_bProperties, _caseProperties, axisOrtho); double actualLength = 0.0, actualWidth = 0.0; if (!pattern.GetLayerDimensionsChecked(layer, out actualLength, out actualWidth)) { continue; } pattern.GenerateLayer(layer, actualLength, actualWidth); string title = string.Empty; BoxCaseSolution sol = new BoxCaseSolution(null, axisOrtho, pattern.Name); double offsetX = 0.5 * (_caseProperties.Length - _caseProperties.InsideLength); double offsetY = 0.5 * (_caseProperties.Width - _caseProperties.InsideWidth); double zLayer = 0.5 * (_caseProperties.Height - _caseProperties.InsideHeight); bool maxWeightReached = _constraintSet.UseMaximumCaseWeight && (_caseProperties.Weight + _bProperties.Weight > _constraintSet.MaximumCaseWeight); bool maxHeightReached = _bProperties.Dimension(axisOrtho) > _caseProperties.InsideHeight; bool maxNumberReached = false; int boxCount = 0; while (!maxWeightReached && !maxHeightReached && !maxNumberReached) { BoxLayer bLayer = sol.CreateNewLayer(zLayer, string.Empty); foreach (LayerPosition layerPos in layer) { // increment ++boxCount; if (maxNumberReached = _constraintSet.UseMaximumNumberOfBoxes && (boxCount > _constraintSet.MaximumNumberOfBoxes)) { break; } double weight = _caseProperties.Weight + boxCount * _bProperties.Weight; maxWeightReached = _constraintSet.UseMaximumCaseWeight && weight > _constraintSet.MaximumCaseWeight; if (maxWeightReached) { break; } // insert new box in current layer LayerPosition layerPosTemp = AdjustLayerPosition(layerPos); BoxPosition boxPos = new BoxPosition( layerPosTemp.Position + offsetX * Vector3D.XAxis + offsetY * Vector3D.YAxis + zLayer * Vector3D.ZAxis , layerPosTemp.LengthAxis , layerPosTemp.WidthAxis ); bLayer.Add(boxPos); } zLayer += layer.BoxHeight; if (!maxWeightReached && !maxNumberReached) { maxHeightReached = zLayer + layer.BoxHeight > 0.5 * (_caseProperties.Height + _caseProperties.InsideHeight); } } // set maximum criterion if (maxNumberReached) { sol.LimitReached = BoxCaseSolution.Limit.LIMIT_MAXNUMBERREACHED; } else if (maxWeightReached) { sol.LimitReached = BoxCaseSolution.Limit.LIMIT_MAXWEIGHTREACHED; } else if (maxHeightReached) { sol.LimitReached = BoxCaseSolution.Limit.LIMIT_MAXHEIGHTREACHED; } if (string.Equals(pattern.Name, "Column", StringComparison.CurrentCultureIgnoreCase)) { patternColumnCount[i] = Math.Max(patternColumnCount[i], sol.BoxPerCaseCount); } // insert solution if (sol.BoxPerCaseCount >= patternColumnCount[i]) { solutions.Add(sol); } } catch (NotImplementedException) { _log.Info(string.Format("Pattern {0} is not implemented", pattern.Name)); } catch (Exception ex) { _log.Error(string.Format("Exception caught: {0}", ex.Message)); } } // loop through all vertical axes } // loop through all patterns // sort solutions solutions.Sort(); /* * // removes solutions that do not equal the best number * if (solutions.Count > 0) * { * int indexFrom = 0, maxCount = solutions[0].BoxPerCaseCount; * while (indexFrom < solutions.Count && solutions[indexFrom].BoxPerCaseCount == maxCount) ++indexFrom; * solutions.RemoveRange(indexFrom, solutions.Count - indexFrom); * } */ return(solutions); }
/// <summary> /// Draw a 2D representation of first (and second, if solution does not have homogeneous layers) layer(s) /// </summary> public void Draw(Graphics2D graphics) { if (null == _caseSolution) { throw new Exception("No case solution defined!"); } BoxCasePalletAnalysis caseAnalysis = _caseSolution.ParentCaseAnalysis; if (_caseSolution.HasHomogeneousLayers) { graphics.NumberOfViews = 1; graphics.SetViewport(0.0f, 0.0f, (float)_caseSolution.CaseLength, (float)_caseSolution.CaseWidth); BoxLayer blayer = _caseSolution[0] as BoxLayer; if (blayer != null) { graphics.SetCurrentView(0); graphics.DrawRectangle(Vector2D.Zero, new Vector2D(_caseSolution.CaseLength, _caseSolution.CaseWidth), Color.Black); uint pickId = 0; foreach (BoxPosition bPosition in blayer) { graphics.DrawBox(new Box(pickId++, caseAnalysis.BoxProperties, bPosition)); } } } else { graphics.NumberOfViews = 2; graphics.SetViewport(0.0f, 0.0f, (float)_caseSolution.CaseLength, (float)_caseSolution.CaseWidth); // get first box layer if (_caseSolution.Count < 1) { return; } BoxLayer blayer0 = _caseSolution[0] as BoxLayer; if (blayer0 != null) { graphics.SetCurrentView(0); graphics.DrawRectangle(Vector2D.Zero, new Vector2D(_caseSolution.CaseLength, _caseSolution.CaseWidth), Color.Black); uint pickId = 0; foreach (BoxPosition bPosition in blayer0) { graphics.DrawBox(new Box(pickId++, caseAnalysis.BoxProperties, bPosition)); } } // get second box layer if (_caseSolution.Count < 2) { return; } BoxLayer blayer1 = _caseSolution[1] as BoxLayer; if (null == blayer1 && _caseSolution.Count > 2) { blayer1 = _caseSolution[2] as BoxLayer; } if (blayer1 != null) { graphics.SetCurrentView(1); graphics.DrawRectangle(Vector2D.Zero, new Vector2D(_caseSolution.CaseLength, _caseSolution.CaseWidth), Color.Black); uint pickId = 0; foreach (BoxPosition bPosition in blayer1) { graphics.DrawBox(new Box(pickId++, caseAnalysis.BoxProperties, bPosition)); } } } }
public void SetLayer(BoxLayer layer) { _layer = layer; }
public void Export(string filePath) { PalletProperties palletProperties = _palletSolution.Analysis.PalletProperties; COLLADA model = new COLLADA(); // asset model.asset = new asset() { created = DateTime.Now, modified = DateTime.Now }; model.asset.keywords = "StackBuilder Pallet Case"; model.asset.title = _palletSolution.Title; model.asset.unit = new assetUnit() { name = "millimeters", meter = 0.001 }; model.asset.up_axis = UpAxisType.Z_UP; library_images images = new library_images(); library_materials materials = new library_materials(); library_effects effects = new library_effects(); library_geometries geometries = new library_geometries(); library_nodes nodes = new library_nodes(); library_cameras cameras = new library_cameras(); library_animations animations = new library_animations(); library_visual_scenes scenes = new library_visual_scenes(); COLLADAScene colladaScene = new COLLADAScene(); model.Items = new Object[] { images, materials, effects, geometries, nodes, cameras, animations, scenes }; model.scene = colladaScene; // colors and materials List <effect> listEffects = new List <effect>(); List <material> listMaterials = new List <material>(); List <image> listImages = new List <image>(); // effects effect effectPallet; material materialPallet; CreateMaterial(palletProperties.Color, null, null, "Pallet", out effectPallet, out materialPallet); listEffects.Add(effectPallet); listMaterials.Add(materialPallet); Box box = new Box(0, _palletSolution.Analysis.BProperties); // build list of effects / materials / images uint faceIndex = 0; foreach (Face face in box.Faces) { // build texture image if any string textureName = null; if (face.HasBitmap) { textureName = string.Format("textureFace_{0}", faceIndex); string texturePath = System.IO.Path.Combine( System.IO.Path.GetDirectoryName(filePath) , textureName + ".jpg"); double dimX = 0.0, dimY = 0.0; switch (faceIndex) { case 0: dimX = box.Width; dimY = box.Height; break; case 1: dimX = box.Width; dimY = box.Height; break; case 2: dimX = box.Length; dimY = box.Height; break; case 3: dimX = box.Length; dimY = box.Height; break; case 4: dimX = box.Length; dimY = box.Width; break; case 5: dimX = box.Length; dimY = box.Width; break; default: break; } face.ExtractFaceBitmap(dimX, dimY, _bmpWidth, texturePath); // create image listImages.Add( new image() { id = textureName + ".jpg", name = textureName + ".jpg", Item = @".\" + textureName + @".jpg" } ); } material materialCase; effect effectCase; CreateMaterial(face.ColorFill, textureName, "0", string.Format("Case{0}", faceIndex), out effectCase, out materialCase); listEffects.Add(effectCase); listMaterials.Add(materialCase); ++faceIndex; } // add to image list images.image = listImages.ToArray(); // case lines material effect effectCaseLines; material materialCaseLines; CreateMaterial(Color.Black, null, null, "CaseLines", out effectCaseLines, out materialCaseLines); listEffects.Add(effectCaseLines); listMaterials.Add(materialCaseLines); effects.effect = listEffects.ToArray(); materials.material = listMaterials.ToArray(); // geometries geometry geomPallet = new geometry() { id = "palletGeometry", name = "palletGeometry" }; geometry geomCase = new geometry() { id = "caseGeometry", name = "caseGeometry" }; geometries.geometry = new geometry[] { geomPallet, geomCase }; // pallet mesh meshPallet = CreatePalletMesh(palletProperties); geomPallet.Item = meshPallet; // case mesh meshCase = CreateCaseMesh(_palletSolution.Analysis.BProperties as BoxProperties); geomCase.Item = meshCase; // library_animations animation animationMain = new animation() { id = "animationMain_ID", name = "animationMain" }; animations.animation = new animation[] { animationMain }; List <object> listAnimationSource = new List <object>(); // library_visual_scenes visual_scene mainScene = new visual_scene() { id = "MainScene", name = "MainScene" }; scenes.visual_scene = new visual_scene[] { mainScene }; List <node> sceneNodes = new List <node>(); sceneNodes.Add(new node() { id = "PalletNode", name = "PalletNode", instance_geometry = new instance_geometry[] { new instance_geometry() { url = "#palletGeometry", bind_material = new bind_material() { technique_common = new instance_material[] { new instance_material() { symbol = "materialPallet", target = string.Format("#{0}", materialPallet.id) } } } } } }); uint caseIndex = 0; foreach (ILayer layer in _palletSolution) { BoxLayer bLayer = layer as BoxLayer; if (null == bLayer) { continue; } foreach (BoxPosition bp in bLayer) { Vector3D translation = bp.Position; Vector3D rotations = bp.Transformation.Rotations; node caseNode = new node() { id = string.Format("CaseNode_{0}_ID", caseIndex), name = string.Format("CaseNode_{0}", caseIndex), ItemsElementName = new ItemsChoiceType2[] { ItemsChoiceType2.translate, ItemsChoiceType2.rotate, ItemsChoiceType2.rotate, ItemsChoiceType2.rotate }, Items = new object[] { new TargetableFloat3() { Values = new double[] { translation.X, translation.Y, translation.Z }, sid = "t", }, new rotate() { Values = new double[] { 1.0, 0.0, 0.0, rotations.X }, sid = "rx" }, new rotate() { Values = new double[] { 0.0, 1.0, 0.0, rotations.Y }, sid = "ry" }, new rotate() { Values = new double[] { 0.0, 0.0, 1.0, rotations.Z }, sid = "rz" } }, instance_geometry = new instance_geometry[] { new instance_geometry() { url = "#caseGeometry", bind_material = new bind_material() { technique_common = new instance_material[] { new instance_material() { symbol = "materialCase0", target = "#material_Case0_ID" }, new instance_material() { symbol = "materialCase1", target = "#material_Case1_ID" }, new instance_material() { symbol = "materialCase2", target = "#material_Case2_ID" }, new instance_material() { symbol = "materialCase3", target = "#material_Case3_ID" }, new instance_material() { symbol = "materialCase4", target = "#material_Case4_ID" }, new instance_material() { symbol = "materialCase5", target = "#material_Case5_ID" }, new instance_material() { symbol = "materialCaseLines", target = "#material_CaseLines_ID" } } } } } }; sceneNodes.Add(caseNode); // animations CreateAnimation(caseIndex, (uint)_palletSolution.CaseCount, listAnimationSource, bp); // increment case index ++caseIndex; } } // add nodes mainScene.node = sceneNodes.ToArray(); animationMain.Items = listAnimationSource.ToArray(); // library_cameras camera cameraCamera = new camera() { id = "Camera-Camera", name = "Camera-Camera" }; cameraOpticsTechnique_commonPerspective cameraPerspective = new cameraOpticsTechnique_commonPerspective() { znear = new TargetableFloat() { sid = "znear", Value = 1.0 }, zfar = new TargetableFloat() { sid = "zfar", Value = 10000.0 } }; cameraCamera.optics = new cameraOptics() { technique_common = new cameraOpticsTechnique_common() { Item = cameraPerspective } }; cameras.camera = new camera[] { cameraCamera }; // colladaScene colladaScene.instance_visual_scene = new InstanceWithExtra() { url = "#MainScene" }; model.Save(filePath); model.Save(System.IO.Path.ChangeExtension(filePath, "xml")); }
/// <summary> /// Use this method when drawing a solution that belongs an analysis /// </summary> /// <param name="graphics"></param> public void Draw(Graphics3D graphics) { if (null == _solution) { return; } // initialize Graphics3D object if (!graphics.ShowBoxIds) { // draw pallet Pallet pallet = new Pallet(_analysis.PalletProperties); pallet.Draw(graphics, Transform3D.Identity); } // load bounding box BBox3D loadBBox = _solution.LoadBoundingBox; BBox3D loadBBoxWDeco = _solution.LoadBoundingBoxWDeco; #region Pallet film : begin // draw film Film film = null; if (_solution.Analysis.HasPalletFilm) { PalletFilmProperties palletFilmProperties = _solution.Analysis.PalletFilmProperties; film = new Film( palletFilmProperties.Color, palletFilmProperties.UseTransparency, palletFilmProperties.UseHatching, palletFilmProperties.HatchSpacing, palletFilmProperties.HatchAngle); film.AddRectangle(new FilmRectangle(loadBBoxWDeco.PtMin, HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Z_P, new Vector2D(loadBBoxWDeco.Length, loadBBoxWDeco.Height), 0.0)); film.AddRectangle(new FilmRectangle(loadBBoxWDeco.PtMin + loadBBoxWDeco.Length * Vector3D.XAxis, HalfAxis.HAxis.AXIS_Y_P, HalfAxis.HAxis.AXIS_Z_P, new Vector2D(loadBBoxWDeco.Width, loadBBoxWDeco.Height), 0.0)); film.AddRectangle(new FilmRectangle(loadBBoxWDeco.PtMin + loadBBoxWDeco.Length * Vector3D.XAxis + loadBBoxWDeco.Width * Vector3D.YAxis, HalfAxis.HAxis.AXIS_X_N, HalfAxis.HAxis.AXIS_Z_P, new Vector2D(loadBBoxWDeco.Length, loadBBoxWDeco.Height), 0.0)); film.AddRectangle(new FilmRectangle(loadBBoxWDeco.PtMin + loadBBoxWDeco.Width * Vector3D.YAxis, HalfAxis.HAxis.AXIS_Y_N, HalfAxis.HAxis.AXIS_Z_P, new Vector2D(loadBBoxWDeco.Width, loadBBoxWDeco.Height), 0.0)); film.AddRectangle(new FilmRectangle(loadBBoxWDeco.PtMin + loadBBoxWDeco.Height * Vector3D.ZAxis, HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Y_P, new Vector2D(loadBBoxWDeco.Length, loadBBoxWDeco.Width), UnitsManager.ConvertLengthFrom(200.0, UnitsManager.UnitSystem.UNIT_METRIC1))); film.DrawBegin(graphics); } #endregion #region Pallet corners // *** pallet corners // positions Vector3D[] cornerPositions = { loadBBox.PtMin , new Vector3D(loadBBox.PtMax.X, loadBBox.PtMin.Y, loadBBox.PtMin.Z) , new Vector3D(loadBBox.PtMax.X, loadBBox.PtMax.Y, loadBBox.PtMin.Z) , new Vector3D(loadBBox.PtMin.X, loadBBox.PtMax.Y, loadBBox.PtMin.Z) }; // length axes HalfAxis.HAxis[] lAxes = { HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Y_P, HalfAxis.HAxis.AXIS_X_N, HalfAxis.HAxis.AXIS_Y_N }; // width axes HalfAxis.HAxis[] wAxes = { HalfAxis.HAxis.AXIS_Y_P, HalfAxis.HAxis.AXIS_X_N, HalfAxis.HAxis.AXIS_Y_N, HalfAxis.HAxis.AXIS_X_P }; // corners Corner[] corners = new Corner[4]; if (_solution.Analysis.HasPalletCorners) { for (int i = 0; i < 4; ++i) { corners[i] = new Corner(0, _solution.Analysis.PalletCornerProperties); corners[i].Height = Math.Min(_solution.Analysis.PalletCornerProperties.Length, loadBBox.Height); corners[i].SetPosition(cornerPositions[i], lAxes[i], wAxes[i]); corners[i].DrawBegin(graphics); } } // *** pallet corners : end #endregion // draw solution uint pickId = 0; foreach (ILayer layer in _solution) { BoxLayer blayer = layer as BoxLayer; if (null != blayer) { foreach (BoxPosition bPosition in blayer) { graphics.AddBox(new Box(pickId++, _analysis.BProperties, bPosition)); } } InterlayerPos interlayerPos = layer as InterlayerPos; if (null != interlayerPos) { InterlayerProperties currInterlayerProperties = (0 == interlayerPos.TypeId) ? _analysis.InterlayerProperties : _analysis.InterlayerPropertiesAntiSlip; Box box = new Box(pickId++, currInterlayerProperties); // set position box.Position = new Vector3D( 0.5 * (_analysis.PalletProperties.Length - currInterlayerProperties.Length) , 0.5 * (_analysis.PalletProperties.Width - currInterlayerProperties.Width) , interlayerPos.ZLow); // draw graphics.AddBox(box); } } if (_showDimensions) { graphics.AddDimensions( new DimensionCube(BoundingBoxDim(Properties.Settings.Default.DimCasePalletSol1) , Color.Black, false)); graphics.AddDimensions( new DimensionCube(BoundingBoxDim(Properties.Settings.Default.DimCasePalletSol2) , Color.Red, true)); } // pallet corners if (_solution.Analysis.HasPalletCorners) { for (int i = 0; i < 4; ++i) { corners[i].DrawEnd(graphics); } } // pallet cap if (_solution.HasPalletCap) { PalletCapProperties capProperties = _solution.Analysis.PalletCapProperties; Vector3D pos = new Vector3D( 0.5 * (_analysis.PalletProperties.Length - capProperties.Length), 0.5 * (_analysis.PalletProperties.Width - capProperties.Width), loadBBox.PtMax.Z - capProperties.InsideHeight); PalletCap cap = new PalletCap(0, capProperties, pos); cap.DrawEnd(graphics); } // pallet film if (_solution.Analysis.HasPalletFilm) { film.DrawEnd(graphics); } graphics.EnableFaceSorting = false; }
public void Save(BoxLayer boxLayer, XmlElement layersElt, XmlDocument xmlDoc) { // BoxLayer XmlElement boxlayerElt = xmlDoc.CreateElement("BoxLayer"); layersElt.AppendChild(boxlayerElt); // ZLow XmlAttribute zlowAttribute = xmlDoc.CreateAttribute("ZLow"); zlowAttribute.Value = string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}", boxLayer.ZLow); boxlayerElt.Attributes.Append(zlowAttribute); // maximum space XmlAttribute attributeMaxSpace = xmlDoc.CreateAttribute("MaximumSpace"); attributeMaxSpace.Value = string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}", boxLayer.MaximumSpace); boxlayerElt.Attributes.Append(attributeMaxSpace); foreach (BoxPosition boxPosition in boxLayer) { // BoxPosition XmlElement boxPositionElt = xmlDoc.CreateElement("BoxPosition"); boxlayerElt.AppendChild(boxPositionElt); // Position XmlAttribute positionAttribute = xmlDoc.CreateAttribute("Position"); positionAttribute.Value = boxPosition.Position.ToString(); boxPositionElt.Attributes.Append(positionAttribute); // AxisLength XmlAttribute axisLengthAttribute = xmlDoc.CreateAttribute("AxisLength"); axisLengthAttribute.Value = HalfAxis.ToString(boxPosition.DirectionLength); boxPositionElt.Attributes.Append(axisLengthAttribute); // AxisWidth XmlAttribute axisWidthAttribute = xmlDoc.CreateAttribute("AxisWidth"); axisWidthAttribute.Value = HalfAxis.ToString(boxPosition.DirectionWidth); boxPositionElt.Attributes.Append(axisWidthAttribute); } }
private List <PackPalletSolution> GenerateSolutions() { List <PackPalletSolution> solutions = new List <PackPalletSolution>(); HalfAxis.HAxis[] axes = { HalfAxis.HAxis.AXIS_Z_N, HalfAxis.HAxis.AXIS_Z_P }; // loop throught all patterns foreach (LayerPattern pattern in _patterns) { // loop throught all axes foreach (HalfAxis.HAxis axis in axes) // axis { // loop through Layer layer = new Layer(_packProperties, _palletProperties, _constraintSet, axis, false); double actualLength = 0.0, actualWidth = 0.0; if (!pattern.GetLayerDimensionsChecked(layer, out actualLength, out actualWidth)) { continue; } pattern.GenerateLayer(layer, actualLength, actualWidth); // filter by layer weight if (_constraintSet.MaximumLayerWeight.Activated && (layer.Count * _packProperties.Weight > _constraintSet.MaximumLayerWeight.Value)) { continue; } // filter by maximum space if (_constraintSet.MaximumSpaceAllowed.Activated && layer.MaximumSpace > _constraintSet.MaximumSpaceAllowed.Value) { continue; } double layerHeight = layer.BoxHeight; string title = string.Format("{0}-{1}", pattern.Name, axis.ToString()); double zLayer = 0.0; BoxLayer boxLayer = new BoxLayer(zLayer, ""); foreach (LayerPosition layerPos in layer) { LayerPosition layerPosTemp = AdjustLayerPosition(layerPos); BoxPosition boxPos = new BoxPosition( layerPosTemp.Position - (0.5 * _constraintSet.OverhangX) * Vector3D.XAxis - (0.5 * _constraintSet.OverhangY) * Vector3D.YAxis + zLayer * Vector3D.ZAxis , layerPosTemp.LengthAxis , layerPosTemp.WidthAxis ); boxLayer.Add(boxPos); } boxLayer.MaximumSpace = layer.MaximumSpace; BBox3D layerBBox = boxLayer.BoundingBox(_packProperties); // filter by overhangX if (_constraintSet.MinOverhangX.Activated && (0.5 * (layerBBox.Length - _palletProperties.Length) < _constraintSet.MinOverhangX.Value)) { continue; } // filter by overhangY if (_constraintSet.MinOverhangY.Activated && (0.5 * (layerBBox.Width - _palletProperties.Width) < _constraintSet.MinOverhangY.Value)) { continue; } double interlayerThickness = null != _interlayerProperties ? _interlayerProperties.Thickness : 0; double interlayerWeight = null != _interlayerProperties ? _interlayerProperties.Weight : 0; PackPalletSolution sol = new PackPalletSolution(null, title, boxLayer); int noLayer = 1, noInterlayer = (null != _interlayerProperties && _constraintSet.HasFirstInterlayer) ? 1 : 0; bool maxHeightReached = _constraintSet.MaximumPalletHeight.Activated && (_packProperties.Height + noInterlayer * interlayerThickness + noLayer * layer.BoxHeight) > _constraintSet.MaximumPalletHeight.Value; bool maxWeightReached = _constraintSet.MaximumPalletWeight.Activated && (_palletProperties.Weight + noInterlayer * interlayerWeight + noLayer * boxLayer.Count * _packProperties.Weight > _constraintSet.MaximumPalletWeight.Value); noLayer = 0; noInterlayer = 0; int iCountInterlayer = 0, iCountSwap = 1; bool bSwap = false; while (!maxHeightReached && !maxWeightReached) { bool bInterlayer = (0 == iCountInterlayer) && ((noLayer != 0) || _constraintSet.HasFirstInterlayer); // actually insert new layer sol.AddLayer(bSwap, bInterlayer); // increment number of layers noLayer++; noInterlayer += (bInterlayer ? 1 : 0); // update iCountInterlayer && iCountSwap ++iCountInterlayer; if (iCountInterlayer >= _constraintSet.InterlayerPeriod) { iCountInterlayer = 0; } ++iCountSwap; if (iCountSwap > _constraintSet.LayerSwapPeriod) { iCountSwap = 1; bSwap = !bSwap; } // update maxHeightReached & maxWeightReached maxHeightReached = _constraintSet.MaximumPalletHeight.Activated && (_palletProperties.Height + (noInterlayer + (iCountInterlayer == 0 ? 1 : 0)) * interlayerThickness + (noLayer + 1) * layer.BoxHeight) > _constraintSet.MaximumPalletHeight.Value; maxWeightReached = _constraintSet.MaximumPalletWeight.Activated && (_palletProperties.Weight + (noInterlayer + (iCountInterlayer == 0 ? 1 : 0)) * interlayerWeight + (noLayer + 1) * boxLayer.Count * _packProperties.Weight > _constraintSet.MaximumPalletWeight.Value); } if (sol.PackCount > 0) { solutions.Add(sol); } } // axis } // pattern solutions.Sort(); return(solutions); }
private ILayer LoadLayer(XmlElement eltLayer) { ILayer layer = null; double zLow = UnitsManager.ConvertLengthFrom( Convert.ToDouble(eltLayer.Attributes["ZLow"].Value, System.Globalization.CultureInfo.InvariantCulture) , _unitSystem); double maxSpace = 0.0; if (eltLayer.HasAttribute("MaximumSpace")) maxSpace = UnitsManager.ConvertLengthFrom( Convert.ToDouble(eltLayer.Attributes["MaximumSpace"].Value, System.Globalization.CultureInfo.InvariantCulture) , _unitSystem); string patternName = string.Empty; if (eltLayer.HasAttribute("PatternName")) patternName = eltLayer.Attributes["PatternName"].Value; if (string.Equals(eltLayer.Name, "BoxLayer", StringComparison.CurrentCultureIgnoreCase)) { BoxLayer boxLayer = new BoxLayer(UnitsManager.ConvertLengthFrom(zLow, _unitSystem), patternName); boxLayer.MaximumSpace = maxSpace; foreach (XmlNode nodeBoxPosition in eltLayer.ChildNodes) { XmlElement eltBoxPosition = nodeBoxPosition as XmlElement; string sPosition = eltBoxPosition.Attributes["Position"].Value; string sAxisLength = eltBoxPosition.Attributes["AxisLength"].Value; string sAxisWidth = eltBoxPosition.Attributes["AxisWidth"].Value; try { boxLayer.AddPosition(UnitsManager.ConvertLengthFrom(Vector3D.Parse(sPosition), _unitSystem), HalfAxis.Parse(sAxisLength), HalfAxis.Parse(sAxisWidth)); } catch (Exception /*ex*/) { _log.Error(string.Format("Exception thrown: Position = {0} | AxisLength = {1} | AxisWidth = {2}", sPosition, sAxisLength, sAxisWidth )); } } layer = boxLayer; } else if (string.Equals(eltLayer.Name, "CylLayer", StringComparison.CurrentCultureIgnoreCase)) { CylinderLayer cylLayer = new CylinderLayer(UnitsManager.ConvertLengthFrom(zLow, _unitSystem)); foreach (XmlNode nodePosition in eltLayer.ChildNodes) { XmlElement eltBoxPosition = nodePosition as XmlElement; string sPosition = eltBoxPosition.Attributes["Position"].Value; cylLayer.Add(UnitsManager.ConvertLengthFrom(Vector3D.Parse(sPosition), _unitSystem)); layer = cylLayer; } } else if (string.Equals(eltLayer.Name, "InterLayer", StringComparison.CurrentCultureIgnoreCase)) { int typeId = 0; if (eltLayer.HasAttribute("TypeId")) typeId = Convert.ToInt32(eltLayer.Attributes["TypeId"].Value); layer = new InterlayerPos(UnitsManager.ConvertLengthFrom(zLow, _unitSystem), typeId); } return layer; }