Exemplo n.º 1
0
        public DCSBSolution SB_GetBundleCaseBestSolution(
            DCSBBundle sbBundle, DCSBCase sbCase
            , 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));
                BoxProperties caseProperties = new BoxProperties(null)
                {
                    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)
                };
                caseProperties.SetWeight(sbCase.Weight);
                if (null != sbCase.Colors && sbCase.Colors.Length >= 6)
                {
                    for (int i = 0; i < 6; ++i)
                    {
                        caseProperties.SetColor((HalfAxis.HAxis)i, Color.FromArgb(sbCase.Colors[i]));
                    }
                }
                else
                {
                    caseProperties.SetAllColors(Enumerable.Repeat <Color>(Color.Chocolate, 6).ToArray());
                }

                OptDouble            oMaxWeight    = null != sbConstraintSet.MaxWeight ? new OptDouble(sbConstraintSet.MaxWeight.Active, sbConstraintSet.MaxWeight.Value_d) : OptDouble.Zero;
                OptInt               oMaxNumber    = null != sbConstraintSet.MaxNumber ? new OptInt(sbConstraintSet.MaxNumber.Active, sbConstraintSet.MaxNumber.Value_i) : OptInt.Zero;
                ConstraintSetBoxCase constraintSet = new ConstraintSetBoxCase(caseProperties)
                {
                    OptMaxWeight = oMaxWeight,
                    OptMaxNumber = oMaxNumber
                };
                if (!constraintSet.Valid)
                {
                    throw new Exception("Invalid constraint set");
                }
                constraintSet.SetAllowedOrientations(new bool[] { false, false, true });

                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;

                if (StackBuilderProcessor.GetBestSolution(
                        bundleProperties, caseProperties, null,
                        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 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()
            });
        }
Exemplo n.º 2
0
        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()
            });
        }