private PalletProperties ConvertDCSBPallet(DCSBPallet sbPallet) { if (null == sbPallet.Dimensions) { throw new Exception("Pallet dimensions were not defined!"); } return(new PalletProperties(null, sbPallet.PalletType, sbPallet.Dimensions.M0, sbPallet.Dimensions.M1, sbPallet.Dimensions.M2) { Weight = sbPallet.Weight, Color = Color.FromArgb(sbPallet.Color) }); }
public DCSBSolution SB_GetCasePalletBestSolution( DCSBCase sbCase, DCSBPallet sbPallet, DCSBInterlayer sbInterlayer, DCSBConstraintSet sbConstraintSet, DCCompFormat expectedFormat, bool showCotations) { List <string> lErrors = new List <string>(); try { BoxProperties boxProperties = new BoxProperties(null, sbCase.DimensionsOuter.M0, sbCase.DimensionsOuter.M1, sbCase.DimensionsOuter.M2) { InsideLength = null != sbCase.DimensionsInner ? sbCase.DimensionsInner.M0 : 0.0, InsideWidth = null != sbCase.DimensionsInner ? sbCase.DimensionsInner.M1 : 0.0, InsideHeight = null != sbCase.DimensionsInner ? sbCase.DimensionsInner.M2 : 0.0, TapeColor = Color.FromArgb(sbCase.TapeColor), TapeWidth = new OptDouble(sbCase.TapeWidth != 0.0, sbCase.TapeWidth) }; boxProperties.SetWeight(sbCase.Weight); boxProperties.SetNetWeight(new OptDouble(sbCase.NetWeight.HasValue, sbCase.NetWeight.Value)); if (null != sbCase.Colors && sbCase.Colors.Length >= 6) { for (int i = 0; i < 6; ++i) { boxProperties.SetColor((HalfAxis.HAxis)i, Color.FromArgb(sbCase.Colors[i])); } } else { boxProperties.SetAllColors(Enumerable.Repeat <Color>(Color.Chocolate, 6).ToArray()); } PalletProperties palletProperties = null; if (null != sbPallet.Dimensions) { palletProperties = new PalletProperties(null, sbPallet.PalletType, sbPallet.Dimensions.M0, sbPallet.Dimensions.M1, sbPallet.Dimensions.M2) { Weight = sbPallet.Weight, Color = Color.FromArgb(sbPallet.Color) } } ; else { palletProperties = new PalletProperties(null, "EUR2", 1200.0, 1000.0, 150.0); } InterlayerProperties interlayerProperties = null; if (null != sbInterlayer) { interlayerProperties = new InterlayerProperties(null, sbInterlayer.Name, sbInterlayer.Description, sbInterlayer.Dimensions.M0, sbInterlayer.Dimensions.M1, sbInterlayer.Dimensions.M2, sbInterlayer.Weight, Color.FromArgb(sbInterlayer.Color)); } OptDouble oMaxWeight = null != sbConstraintSet.MaxWeight ? new OptDouble(sbConstraintSet.MaxWeight.Active, sbConstraintSet.MaxWeight.Value_d) : OptDouble.Zero; OptDouble oMaxHeight = null != sbConstraintSet.MaxHeight ? new OptDouble(sbConstraintSet.MaxHeight.Active, sbConstraintSet.MaxHeight.Value_d) : OptDouble.Zero; OptInt oMaxNumber = null != sbConstraintSet.MaxNumber ? new OptInt(sbConstraintSet.MaxNumber.Active, sbConstraintSet.MaxNumber.Value_i) : OptInt.Zero; ConstraintSetCasePallet constraintSet = new ConstraintSetCasePallet() { OptMaxWeight = oMaxWeight, OptMaxNumber = oMaxNumber }; constraintSet.SetMaxHeight(oMaxHeight); constraintSet.SetAllowedOrientations(new bool[] { sbConstraintSet.Orientation.X, sbConstraintSet.Orientation.Y, sbConstraintSet.Orientation.Z }); if (!constraintSet.Valid) { throw new Exception("Invalid constraint set"); } Vector3D cameraPosition = Graphics3D.Corner_0; int layerCount = 0, caseCount = 0, interlayerCount = 0; double weightTotal = 0.0, weightLoad = 0.0, volumeEfficiency = 0.0; double? weightEfficiency = 0.0; double? weightNet = (double?)null; Vector3D bbLoad = new Vector3D(); Vector3D bbGlob = new Vector3D(); string palletMapPhrase = string.Empty; byte[] imageBytes = null; string[] errors = null; if (StackBuilderProcessor.GetBestSolution( boxProperties, palletProperties, interlayerProperties, constraintSet, sbConstraintSet.AllowMultipleLayerOrientations, cameraPosition, showCotations, 0.03f, new Size(expectedFormat.Size.CX, expectedFormat.Size.CY), ref layerCount, ref caseCount, ref interlayerCount, ref weightTotal, ref weightLoad, ref weightNet, ref bbLoad, ref bbGlob, ref volumeEfficiency, ref weightEfficiency, ref palletMapPhrase, ref imageBytes, ref errors)) { foreach (string err in errors) { lErrors.Add(err); } return(new DCSBSolution() { LayerCount = layerCount, CaseCount = caseCount, InterlayerCount = interlayerCount, WeightLoad = weightLoad, WeightTotal = weightTotal, NetWeight = weightNet, BBoxLoad = new DCSBDim3D(bbLoad.X, bbLoad.Y, bbLoad.Z), BBoxTotal = new DCSBDim3D(bbGlob.X, bbGlob.Y, bbGlob.Z), Efficiency = volumeEfficiency, OutFile = new DCCompFileOutput() { Bytes = imageBytes, Format = new DCCompFormat() { Format = EOutFormat.IMAGE, Size = new DCCompSize() { CX = expectedFormat.Size.CX, CY = expectedFormat.Size.CY } } }, PalletMapPhrase = palletMapPhrase, Errors = lErrors.ToArray() }); } } catch (Exception ex) { lErrors.Add(ex.Message); _log.Error(ex.ToString()); } return(new DCSBSolution() { Errors = lErrors.ToArray() }); }
public DCSBSolution SB_GetBundlePalletBestSolution( DCSBBundle sbBundle, DCSBPallet sbPallet, DCSBInterlayer sbInterlayer , DCSBConstraintSet sbConstraintSet , DCCompFormat expectedFormat, bool showCotations) { List <string> lErrors = new List <string>(); try { BundleProperties bundleProperties = new BundleProperties(null , sbBundle.Name, sbBundle.Description , sbBundle.DimensionsUnit.M0, sbBundle.DimensionsUnit.M1, sbBundle.DimensionsUnit.M2 , sbBundle.UnitWeight, sbBundle.Number , Color.FromArgb(sbBundle.Color)); PalletProperties palletProperties = null; if (null != sbPallet.Dimensions) { palletProperties = new PalletProperties(null, sbPallet.PalletType, sbPallet.Dimensions.M0, sbPallet.Dimensions.M1, sbPallet.Dimensions.M2) { Weight = sbPallet.Weight, Color = Color.FromArgb(sbPallet.Color) } } ; else { palletProperties = new PalletProperties(null, "EUR2", 1200.0, 1000.0, 150.0); } InterlayerProperties interlayerProperties = null; if (null != sbInterlayer) { interlayerProperties = new InterlayerProperties(null, sbInterlayer.Name, sbInterlayer.Description, sbInterlayer.Dimensions.M0, sbInterlayer.Dimensions.M1, sbInterlayer.Dimensions.M2, sbInterlayer.Weight, Color.FromArgb(sbInterlayer.Color)); } OptDouble oMaxWeight = null != sbConstraintSet.MaxWeight ? new OptDouble(sbConstraintSet.MaxWeight.Active, sbConstraintSet.MaxWeight.Value_d) : OptDouble.Zero; OptDouble oMaxHeight = null != sbConstraintSet.MaxHeight ? new OptDouble(sbConstraintSet.MaxHeight.Active, sbConstraintSet.MaxHeight.Value_d) : OptDouble.Zero; OptInt oMaxNumber = null != sbConstraintSet.MaxNumber ? new OptInt(sbConstraintSet.MaxNumber.Active, sbConstraintSet.MaxNumber.Value_i) : OptInt.Zero; ConstraintSetCasePallet constraintSet = new ConstraintSetCasePallet() { OptMaxWeight = oMaxWeight, OptMaxNumber = oMaxNumber }; constraintSet.SetMaxHeight(oMaxHeight); constraintSet.SetAllowedOrientations(new bool[] { false, false, true }); if (!constraintSet.Valid) { throw new Exception("Invalid constraint set"); } Vector3D cameraPosition = Graphics3D.Corner_0; int layerCount = 0, caseCount = 0, interlayerCount = 0; double weightTotal = 0.0, weightLoad = 0.0, volumeEfficiency = 0.0; double? weightEfficiency = 0.0; double? weightNet = (double?)null; Vector3D bbLoad = new Vector3D(); Vector3D bbGlob = new Vector3D(); byte[] imageBytes = null; string[] errors = null; string palletMapPhrase = string.Empty; if (StackBuilderProcessor.GetBestSolution( bundleProperties, palletProperties, interlayerProperties, constraintSet, false, cameraPosition, showCotations, 0.03f, new Size(expectedFormat.Size.CX, expectedFormat.Size.CY), ref layerCount, ref caseCount, ref interlayerCount, ref weightTotal, ref weightLoad, ref weightNet, ref bbLoad, ref bbGlob, ref volumeEfficiency, ref weightEfficiency, ref palletMapPhrase, ref imageBytes, ref errors)) { foreach (string err in errors) { lErrors.Add(err); } return(new DCSBSolution() { LayerCount = layerCount, CaseCount = caseCount, InterlayerCount = interlayerCount, WeightLoad = weightLoad, WeightTotal = weightTotal, NetWeight = weightNet, BBoxLoad = new DCSBDim3D(bbLoad.X, bbLoad.Y, bbLoad.Z), BBoxTotal = new DCSBDim3D(bbGlob.X, bbGlob.Y, bbGlob.Z), Efficiency = volumeEfficiency, OutFile = new DCCompFileOutput() { Bytes = imageBytes, Format = new DCCompFormat() { Format = EOutFormat.IMAGE, Size = new DCCompSize() { CX = expectedFormat.Size.CX, CY = expectedFormat.Size.CY } } }, Errors = lErrors.ToArray() }); } } catch (Exception ex) { lErrors.Add(ex.Message); _log.Error(ex.ToString()); } return(new DCSBSolution() { Errors = lErrors.ToArray() }); }
/* * public DCSBHSolutionList SB_GetHCasePalletSolution(DCSBContentItem[] sbContentItems, DCSBPallet sbPallet, DCSBHConstraintSet sbConstraintSet) * { * var lErrors = new List<string>(); * var sbSolutions = new List<DCSBHSolution>(); * * try * { * // list of content items * var contentItems = new List<ContentItem>(); * foreach (var sbci in sbContentItems) * { * contentItems.Add( * new ContentItem(ConvertDCSBCase(sbci.Case), sbci.Number, sbci.Orientation.ToArray()) * ); * } * // pallet * var palletProperties = ConvertDCSBPallet(sbPallet); * // constraint set * var constraintSet = new HConstraintSetPallet() * { * Overhang = new Vector2D(sbConstraintSet.Overhang.M0, sbConstraintSet.Overhang.M1), * MaximumHeight = sbConstraintSet.MaxHeight.Value_d * }; * // solve * var solver = new HSolver(); * var solutions = solver.BuildSolutions( * new HAnalysisPallet(null) * { * Content = contentItems, * Pallet = palletProperties, * ConstraintSet = constraintSet * } * ); * // analyse each solution * int solIndex = 0; * foreach (var sol in solutions) * { * sbSolutions.Add( * new DCSBHSolution() * { * SolIndex = solIndex, * PalletCount = sol.SolItemCount, * Algorithm = sol.Algorithm * } * ); * } * } * catch (Exception ex) * { * lErrors.Add(ex.Message); * _log.Error(ex.ToString()); * } * return new DCSBHSolutionList() * { * Solutions = sbSolutions.ToArray(), * Errors = lErrors.ToArray() * }; * } */ public DCSBHSolutionItem SB_GetHSolutionPart( DCSBContentItem[] sbContentItems, DCSBPallet sbPallet, DCSBHConstraintSet sbConstraintSet, int solIndex, int binIndex, DCCompFormat expectedFormat, bool showCotations) { var lErrors = new List <string>(); Vector3D cameraPosition = Graphics3D.Corner_0; byte[] imageBytes = null; string[] errors = null; double weightLoad = 0.0, weightTotal = 0.0; Vector3D bbLoad = new Vector3D(); Vector3D bbGlob = new Vector3D(); try { if (StackBuilderProcessor.GetHSolutionPart( ConvertDCSBContentItems(sbContentItems), ConvertDCSBPallet(sbPallet), ConvertDCSBConstraintSet(sbConstraintSet), solIndex, binIndex, cameraPosition, showCotations, 0.03f, new Size(expectedFormat.Size.CX, expectedFormat.Size.CY), ref weightLoad, ref weightTotal, ref bbLoad, ref bbGlob, ref imageBytes, ref errors) ) { foreach (string err in errors) { lErrors.Add(err); } return(new DCSBHSolutionItem() { SolIndex = solIndex, BinIndex = binIndex, WeightLoad = weightLoad, WeightTotal = weightTotal, BBoxLoad = new DCSBDim3D(bbLoad.X, bbLoad.Y, bbLoad.Z), BBoxTotal = new DCSBDim3D(bbGlob.X, bbGlob.Y, bbGlob.Z), OutFile = new DCCompFileOutput() { Bytes = imageBytes, Format = new DCCompFormat() { Format = EOutFormat.IMAGE, Size = new DCCompSize() { CX = expectedFormat.Size.CX, CY = expectedFormat.Size.CY } } }, Errors = lErrors.ToArray() }); } } catch (Exception ex) { lErrors.Add(ex.Message); _log.Error(ex.ToString()); } return(new DCSBHSolutionItem() { Errors = lErrors.ToArray() }); }
public DCSBHSolution SB_GetHSolutionBestCasePallet(DCSBContentItem[] sbConstentItems, DCSBPallet sbPallet, DCSBHConstraintSet sbConstraintSet, DCCompFormat expectedFormat, bool showCotations) { var lErrors = new List <string>(); Vector3D cameraPosition = Graphics3D.Corner_0; int palletCount = 0; byte[] imageBytes = null; string algorithm = string.Empty; string[] errors = null; try { if (StackBuilderProcessor.GetHSolutionBestCasePallet( ConvertDCSBContentItems(sbConstentItems), ConvertDCSBPallet(sbPallet), ConvertDCSBConstraintSet(sbConstraintSet), cameraPosition, showCotations, 0.03f, new Size(expectedFormat.Size.CX, expectedFormat.Size.CY), ref palletCount, ref algorithm, ref imageBytes, ref errors)) { foreach (string err in errors) { lErrors.Add(err); } return(new DCSBHSolution() { SolIndex = 0, PalletCount = palletCount, Algorithm = string.Empty, OutFile = new DCCompFileOutput() { Bytes = imageBytes, Format = new DCCompFormat() { Format = EOutFormat.IMAGE, Size = new DCCompSize() { CX = expectedFormat.Size.CX, CY = expectedFormat.Size.CY } } }, Errors = lErrors.ToArray() }); } } catch (Exception ex) { lErrors.Add(ex.Message); _log.Error(ex.ToString()); } return(new DCSBHSolution() { Errors = lErrors.ToArray() }); }
public DCSBSolution[] SB_GetSolutionList( DCSBCase sbCase, DCSBPallet sbPallet, DCSBInterlayer sbInterlayer, DCSBConstraintSet sbConstraintSet) { var listSolution = new List <DCSBSolution>(); var lErrors = new List <string>(); try { BoxProperties boxProperties = new BoxProperties(null, sbCase.DimensionsOuter.M0, sbCase.DimensionsOuter.M1, sbCase.DimensionsOuter.M2) { InsideLength = null != sbCase.DimensionsInner ? sbCase.DimensionsInner.M0 : 0.0, InsideWidth = null != sbCase.DimensionsInner ? sbCase.DimensionsInner.M1 : 0.0, InsideHeight = null != sbCase.DimensionsInner ? sbCase.DimensionsInner.M2 : 0.0, TapeColor = Color.FromArgb(sbCase.TapeColor), TapeWidth = new OptDouble(sbCase.TapeWidth != 0.0, sbCase.TapeWidth) }; boxProperties.SetWeight(sbCase.Weight); boxProperties.SetNetWeight(new OptDouble(sbCase.NetWeight.HasValue, sbCase.NetWeight.Value)); if (null != sbCase.Colors && sbCase.Colors.Length >= 6) { for (int i = 0; i < 6; ++i) { boxProperties.SetColor((HalfAxis.HAxis)i, Color.FromArgb(sbCase.Colors[i])); } } else { boxProperties.SetAllColors(Enumerable.Repeat(Color.Chocolate, 6).ToArray()); } PalletProperties palletProperties = null; if (null != sbPallet.Dimensions) { palletProperties = new PalletProperties(null, sbPallet.PalletType, sbPallet.Dimensions.M0, sbPallet.Dimensions.M1, sbPallet.Dimensions.M2) { Weight = sbPallet.Weight, Color = Color.FromArgb(sbPallet.Color) } } ; else { palletProperties = new PalletProperties(null, "EUR2", 1200.0, 1000.0, 150.0); } InterlayerProperties interlayerProperties = null; if (null != sbInterlayer) { interlayerProperties = new InterlayerProperties(null, sbInterlayer.Name, sbInterlayer.Description, sbInterlayer.Dimensions.M0, sbInterlayer.Dimensions.M1, sbInterlayer.Dimensions.M2, sbInterlayer.Weight, Color.FromArgb(sbInterlayer.Color)); } OptDouble oMaxWeight = null != sbConstraintSet.MaxWeight ? new OptDouble(sbConstraintSet.MaxWeight.Active, sbConstraintSet.MaxWeight.Value_d) : OptDouble.Zero; OptDouble oMaxHeight = null != sbConstraintSet.MaxHeight ? new OptDouble(sbConstraintSet.MaxHeight.Active, sbConstraintSet.MaxHeight.Value_d) : OptDouble.Zero; OptInt oMaxNumber = null != sbConstraintSet.MaxNumber ? new OptInt(sbConstraintSet.MaxNumber.Active, sbConstraintSet.MaxNumber.Value_i) : OptInt.Zero; ConstraintSetCasePallet constraintSet = new ConstraintSetCasePallet() { Overhang = new Vector2D(sbConstraintSet.Overhang.M0, sbConstraintSet.Overhang.M1), OptMaxWeight = oMaxWeight, OptMaxNumber = oMaxNumber }; constraintSet.SetMaxHeight(oMaxHeight); constraintSet.SetAllowedOrientations(new bool[] { sbConstraintSet.Orientation.X, sbConstraintSet.Orientation.Y, sbConstraintSet.Orientation.Z }); if (!constraintSet.Valid) { throw new Exception("Invalid constraint set"); } List <AnalysisLayered> analyses = new List <AnalysisLayered>(); if (StackBuilderProcessor.GetSolutionList( boxProperties, palletProperties, interlayerProperties, constraintSet, ref analyses )) { foreach (var analysis in analyses) { Vector3D bbGlob = analysis.Solution.BBoxGlobal.DimensionsVec; Vector3D bbLoad = analysis.Solution.BBoxLoad.DimensionsVec; OptDouble optNetWeight = analysis.Solution.NetWeight; double? weightNet = optNetWeight.Activated ? optNetWeight.Value : (double?)null; List <string> layerDescs = new List <string>(); foreach (var lp in analysis.SolutionLay.LayerPhrases.Keys) { layerDescs.Add(lp.LayerDescriptor.ToString()); } DCSBSolution solution = new DCSBSolution() { LayerCount = analysis.SolutionLay.LayerCount, CaseCount = analysis.Solution.ItemCount, InterlayerCount = analysis.SolutionLay.InterlayerCount, WeightLoad = analysis.Solution.LoadWeight, WeightTotal = analysis.Solution.Weight, NetWeight = weightNet, BBoxLoad = new DCSBDim3D(bbLoad.X, bbLoad.Y, bbLoad.Z), BBoxTotal = new DCSBDim3D(bbGlob.X, bbGlob.Y, bbGlob.Z), Efficiency = analysis.Solution.VolumeEfficiency, OutFile = null, LayerDescs = layerDescs.ToArray(), PalletMapPhrase = StackBuilderProcessor.BuildPalletMapPhrase(analysis.SolutionLay), Errors = lErrors.ToArray() }; listSolution.Add(solution); } } } catch (Exception ex) { lErrors.Add(ex.Message); _log.Error(ex.ToString()); } return(listSolution.ToArray()); }