Example #1
0
        public List <Analysis> BuildAnalyses(ConstraintSetAbstract constraintSet)
        {
            var analyses = new List <Analysis>();
            // build layer list
            var            solver = new LayerSolver();
            List <Layer2D> layers = solver.BuildLayers(
                _packable.OuterDimensions
                , new Vector2D(_caseProperties.InsideLength, _caseProperties.InsideWidth)
                , 0.0     /* offsetZ */
                , constraintSet
                , true
                );

            Solution.SetSolver(solver);
            // loop on layers
            foreach (Layer2D layer in layers)
            {
                var layerDescs = new List <LayerDesc>();
                layerDescs.Add(layer.LayerDescriptor);
                var analysis = new AnalysisBoxCase(null, _packable, _caseProperties, constraintSet as ConstraintSetBoxCase);
                analysis.AddSolution(layerDescs);
                // only add analysis if it has a valid solution
                if (analysis.Solution.ItemCount > 0)
                {
                    analyses.Add(analysis);
                }
            }
            return(analyses);
        }
        public static HCylLayout BuildLayout(Packable packable
                                             , IContainer container
                                             , ConstraintSetAbstract constraintSet
                                             , string patternName, bool swapped)
        {
            if (!(packable is CylinderProperties cylProperties))
            {
                throw new Exception("Invalid type!");
            }

            // get pattern by name
            var pattern = HCylLoadPattern.PatternByName(patternName);

            if (null == pattern)
            {
                return(null);
            }

            var layout = new HCylLayout(
                cylProperties.Diameter
                , cylProperties.Height
                , container.GetStackingDimensions(constraintSet)
                , pattern.Name
                , swapped)
            {
                Offset = container.GetOffset(constraintSet)
            };

            pattern.GetDimensions(layout, constraintSet.OptGlobMaxNumber(packable), out double actualLength, out double actualWidth);
            pattern.Generate(layout, constraintSet.OptGlobMaxNumber(packable), actualLength, actualWidth, constraintSet.OptMaxHeight.Value);
            return(layout);
        }
Example #3
0
        public List <Layer2DCyl> BuildLayers(
            double radius, double height
            , Vector2D dimContainer
            , double offsetZ /* e.g. pallet height */
            , ConstraintSetAbstract constraintSet
            , bool keepOnlyBest)
        {
            List <Layer2DCyl> listLayers0 = new List <Layer2DCyl>();

            foreach (LayerPatternCyl pattern in LayerPatternCyl.All)
            {
                // not swapped vs swapped pattern
                for (int iSwapped = 0; iSwapped < 2; ++iSwapped)
                {
                    // does swapping makes sense for this layer pattern ?
                    if (!pattern.CanBeSwapped && (iSwapped == 1))
                    {
                        continue;
                    }
                    // instantiate layer
                    Layer2DCyl layer = new Layer2DCyl(radius, height, dimContainer, iSwapped == 1);
                    layer.PatternName = pattern.Name;

                    double actualLength = 0.0, actualWidth = 0.0;
                    if (!pattern.GetLayerDimensions(layer, out actualLength, out actualWidth))
                    {
                        continue;
                    }
                    pattern.GenerateLayer(layer, actualLength, actualWidth);
                    listLayers0.Add(layer);
                }

                // keep only best layers
                if (keepOnlyBest)
                {
                    // 1. get best count
                    int bestCount = 0;
                    foreach (Layer2DCyl layer in listLayers0)
                    {
                        bestCount = Math.Max(layer.CountInHeight(constraintSet.OptMaxHeight.Value - offsetZ), bestCount);
                    }

                    // 2. remove any layer that does not match the best count given its orientation
                    List <Layer2DCyl> listLayers1 = new List <Layer2DCyl>();
                    foreach (Layer2DCyl layer in listLayers0)
                    {
                        if (layer.CountInHeight(constraintSet.OptMaxHeight.Value - offsetZ) >= bestCount)
                        {
                            listLayers1.Add(layer);
                        }
                    }
                    // 3. copy back in original list
                    listLayers0.Clear();
                    listLayers0.AddRange(listLayers1);
                }
                listLayers0.Sort(new LayerCylComparerCount(constraintSet.OptMaxHeight.Value - offsetZ));
            }
            return(listLayers0);
        }
 public HCylLayout BuildLayoutNonStatic(Packable packable
                                        , IContainer container
                                        , ConstraintSetAbstract constraintSet
                                        , string patternName
                                        , bool swapped)
 {
     return(BuildLayout(packable, container, constraintSet, patternName, swapped));
 }
Example #5
0
        public List <Analysis> BuildAnalyses(ConstraintSetAbstract constraintSet)
        {
            List <Analysis> analyses = PackOptimSolutions(
                constraintSet as ConstraintSetCasePallet,
                _paramSetPackOptim.NoBoxes);

            return(analyses);
        }
        public List <Analysis> BuildAnalyses(ConstraintSetAbstract constraintSet, bool allowMultipleLayerOrientations)
        {
            List <Analysis> analyses = PackOptimSolutions(
                constraintSet as ConstraintSetCasePallet,
                _paramSetPackOptim.NoBoxes);

            return(analyses);
        }
        public List <Analysis> BuildAnalyses(ConstraintSetAbstract constraintSet, bool allowMultipleLayerOrientations)
        {
            var analyses = new List <Analysis>();

            // get best set of layers
            if (allowMultipleLayerOrientations)
            {
                List <KeyValuePair <LayerDesc, int> > listLayer = new List <KeyValuePair <LayerDesc, int> >();
                LayerSolver.GetBestCombination(
                    _packable.OuterDimensions,
                    _caseProperties.GetStackingDimensions(constraintSet),
                    constraintSet,
                    ref listLayer);

                var layerDescs = new List <LayerDesc>();
                foreach (KeyValuePair <LayerDesc, int> vp in listLayer)
                {
                    layerDescs.Add(vp.Key);
                }

                var analysis = new AnalysisBoxCase(null, _packable, _caseProperties, constraintSet as ConstraintSetBoxCase);
                analysis.AddSolution(layerDescs);
                // only add analysis if it has a valid solution
                if (analysis.Solution.ItemCount > 0)
                {
                    analyses.Add(analysis);
                }
            }
            else
            {
                // build layer list
                var            solver = new LayerSolver();
                List <Layer2D> layers = solver.BuildLayers(
                    _packable.OuterDimensions
                    , new Vector2D(_caseProperties.InsideLength, _caseProperties.InsideWidth)
                    , 0.0  /* offsetZ */
                    , constraintSet
                    , true
                    );
                Solution.SetSolver(solver);
                // loop on layers
                foreach (Layer2D layer in layers)
                {
                    var layerDescs = new List <LayerDesc> {
                        layer.LayerDescriptor
                    };
                    var analysis = new AnalysisBoxCase(null, _packable, _caseProperties, constraintSet as ConstraintSetBoxCase);
                    analysis.AddSolution(layerDescs);
                    // only add analysis if it has a valid solution
                    if (analysis.Solution.ItemCount > 0)
                    {
                        analyses.Add(analysis);
                    }
                }
            }
            return(analyses);
        }
Example #8
0
        public List <Analysis> BuildAnalyses(ConstraintSetAbstract constraintSet, bool allowMultipleLayerOrientations)
        {
            var analyses = new List <Analysis>();
            var constraintSetCasePallet = constraintSet as ConstraintSetCasePallet;

            if (null == constraintSetCasePallet)
            {
                return(analyses);
            }
            Vector2D overhang = constraintSetCasePallet.Overhang;

            if (allowMultipleLayerOrientations)
            {
                List <KeyValuePair <LayerDesc, int> > listLayer = new List <KeyValuePair <LayerDesc, int> >();
                LayerSolver.GetBestCombination(
                    _packable.OuterDimensions,
                    _palletProperties.GetStackingDimensions(constraintSet),
                    constraintSet,
                    ref listLayer);
                Solution.SetSolver(new LayerSolver());
                var analysis = new AnalysisCasePallet(_packable, _palletProperties, constraintSet as ConstraintSetCasePallet);
                analysis.AddSolution(listLayer);
                // only add analysis if it has a valid solution
                if (analysis.Solution.ItemCount > 0)
                {
                    analyses.Add(analysis);
                }
            }
            else
            {
                // build layer list
                var            solver = new LayerSolver();
                List <Layer2D> layers = solver.BuildLayers(
                    _packable.OuterDimensions
                    , new Vector2D(_palletProperties.Length + 2.0 * overhang.X, _palletProperties.Width + 2.0 * overhang.Y)
                    , _palletProperties.Height
                    , constraintSetCasePallet
                    , true
                    );
                Solution.SetSolver(solver);
                // loop on layers
                foreach (Layer2D layer in layers)
                {
                    var layerDescs = new List <LayerDesc> {
                        layer.LayerDescriptor
                    };
                    var analysis = new AnalysisCasePallet(_packable, _palletProperties, constraintSet as ConstraintSetCasePallet);
                    analysis.AddSolution(layerDescs);
                    // only add analysis if it has a valid solution
                    if (analysis.Solution.ItemCount > 0)
                    {
                        analyses.Add(analysis);
                    }
                }
            }
            return(analyses);
        }
Example #9
0
 public PackOptimizer(
     PackableBrick packable
     , PalletProperties palletProperties
     , ConstraintSetAbstract constraintSet
     , ParamSetPackOptim paramSetPackOptim
     )
 {
     BoxProperties    = packable;
     PalletProperties = palletProperties;
     ConstraintSet    = constraintSet;
     ParamSetPackOpt  = paramSetPackOptim;
 }
Example #10
0
 public SolverBoxCase(PackableBrick packable, BoxProperties bProperties, ConstraintSetAbstract constraintSet)
 {
     _packable       = packable;
     _caseProperties = bProperties;
     if (constraintSet is ConstraintSetBoxCase constraintSetBoxCase)
     {
         ConstraintSet = constraintSetBoxCase;
     }
     else
     {
         throw new InvalidConstraintSetException();
     }
 }
Example #11
0
        public Layer2D BuildBestLayer(ConstraintSetAbstract constraintSet)
        {
            // build layer list
            var            solver = new LayerSolver();
            List <Layer2D> layers = solver.BuildLayers(
                _packable.OuterDimensions
                , new Vector2D(_caseProperties.InsideLength, _caseProperties.InsideWidth)
                , 0.0     /* offsetZ */
                , constraintSet
                , true
                );

            if (layers.Count > 0)
            {
                return(layers[0]);
            }
            return(null);
        }
Example #12
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            cbCases.Initialize(_document, this, null != AnalysisCast ? AnalysisCast.Content : null);
            cbPallets.Initialize(_document, this, null != AnalysisCast ? AnalysisCast.PalletProperties : null);

            // event handling
            uCtrlLayerList.LayerSelected   += onLayerSelected;
            uCtrlLayerList.RefreshFinished += onLayerSelected;
            uCtrlLayerList.ButtonSizes      = new Size(100, 100);

            if (null == AnalysisCast)
            {
                tbName.Text        = _document.GetValidNewAnalysisName(ItemDefaultName);
                tbDescription.Text = tbName.Text;

                uCtrlCaseOrientation.AllowedOrientations = new bool[] { Settings.Default.AllowVerticalX, Settings.Default.AllowVerticalY, Settings.Default.AllowVerticalZ };
                uCtrlMaximumHeight.Value    = Settings.Default.MaximumPalletHeight;
                uCtrlOptMaximumWeight.Value = new OptDouble(false, Settings.Default.MaximumPalletWeight);

                uCtrlOverhang.ValueX = Settings.Default.OverhangX;
                uCtrlOverhang.ValueY = Settings.Default.OverhangY;
            }
            else
            {
                tbName.Text        = AnalysisBase.Name;
                tbDescription.Text = AnalysisBase.Description;

                ConstraintSetAbstract constraintSet = AnalysisBase.ConstraintSet;
                uCtrlCaseOrientation.AllowedOrientations = new bool[] {
                    constraintSet.AllowOrientation(HalfAxis.HAxis.AXIS_X_P)
                    , constraintSet.AllowOrientation(HalfAxis.HAxis.AXIS_Y_P)
                    , constraintSet.AllowOrientation(HalfAxis.HAxis.AXIS_Z_P)
                };
                uCtrlMaximumHeight.Value    = constraintSet.OptMaxHeight.Value;
                uCtrlOptMaximumWeight.Value = constraintSet.OptMaxWeight;

                ConstraintSetCasePallet constraintSetCasePallet = constraintSet as ConstraintSetCasePallet;

                uCtrlOverhang.ValueX = constraintSetCasePallet.Overhang.X;
                uCtrlOverhang.ValueY = constraintSetCasePallet.Overhang.Y;
            }
            checkBoxBestLayersOnly.Checked = Settings.Default.KeepBestSolutions;
        }
        private void OnBestCombinationClicked(object sender, EventArgs e)
        {
            try
            {
                Packable         packable         = cbCases.SelectedType as Packable;
                PalletProperties palletProperties = cbPallets.SelectedType as PalletProperties;
                if (null == packable || null == palletProperties)
                {
                    return;
                }
                ConstraintSetAbstract constraintSet = BuildConstraintSet();
                // get best combination
                List <KeyValuePair <LayerDesc, int> > listLayer = new List <KeyValuePair <LayerDesc, int> >();
                LayerSolver.GetBestCombination(
                    packable.OuterDimensions,
                    palletProperties.GetStackingDimensions(constraintSet),
                    constraintSet,
                    ref listLayer);

                // select best layers
                List <LayerDesc> listLayerDesc = new List <LayerDesc>();
                foreach (KeyValuePair <LayerDesc, int> kvp in listLayer)
                {
                    listLayerDesc.Add(kvp.Key);
                }
                uCtrlLayerList.SelectLayers(listLayerDesc);

                _item = _document.CreateNewAnalysisCasePallet(
                    ItemName, ItemDescription
                    , SelectedPackable, SelectedPallet
                    , new List <InterlayerProperties>()
                    , null, null, null
                    , BuildConstraintSet()
                    , listLayer
                    );
                Close();
            }
            catch (Exception ex)
            {
                _log.Error(ex.ToString());
            }
        }
Example #14
0
        public Layer2D BuildBestLayer(ConstraintSetAbstract constraintSet)
        {
            var      constraintSetCasePallet = constraintSet as ConstraintSetCasePallet;
            Vector2D overhang = constraintSetCasePallet.Overhang;
            // build layer list
            var            solver = new LayerSolver();
            List <Layer2D> layers = solver.BuildLayers(
                _packable.OuterDimensions
                , new Vector2D(_palletProperties.Length + 2.0 * overhang.X, _palletProperties.Width + 2.0 * overhang.Y)
                , _palletProperties.Height
                , constraintSetCasePallet
                , true
                );

            if (layers.Count > 0)
            {
                return(layers[0]);
            }
            return(null);
        }
Example #15
0
        public static List <HCylLayout> BuildLayouts(
            Packable packable
            , IContainer container
            , ConstraintSetAbstract constraintSet)
        {
            var layouts = new List <HCylLayout>();

            if (packable is CylinderProperties cylProperties)
            {
                // loop through patterns
                foreach (var pattern in HCylLoadPattern.Patterns)
                {
                    // loop through directions
                    for (int iDir = 0; iDir < (pattern.CanBeSwapped ? 2 : 1); ++iDir)
                    {
                        var layout = new HCylLayout(
                            cylProperties.Diameter
                            , cylProperties.Height
                            , container.GetStackingDimensions(constraintSet)
                            , pattern.Name
                            , iDir == 1)
                        {
                            Offset = container.GetOffset(constraintSet)
                        };

                        pattern.GetDimensions(layout, constraintSet.OptGlobMaxNumber(packable), out double actualLength, out double actualWidth);
                        pattern.Generate(layout, constraintSet.OptGlobMaxNumber(packable), actualLength, actualWidth, constraintSet.OptMaxHeight.Value);
                        if (layout.Positions.Count > 0)
                        {
                            layouts.Add(layout);
                        }
                    }
                }
            }
            layouts.Sort(new HCylLayoutComparer());
            return(layouts);
        }
Example #16
0
        public List <Analysis> BuildAnalyses(ConstraintSetAbstract constraintSet)
        {
            var analyses = new List <Analysis>();
            var constraintSetCasePallet = constraintSet as ConstraintSetCasePallet;

            if (null == constraintSetCasePallet)
            {
                return(analyses);
            }
            Vector2D overhang = constraintSetCasePallet.Overhang;
            // build layer list
            var            solver = new LayerSolver();
            List <Layer2D> layers = solver.BuildLayers(
                _packable.OuterDimensions
                , new Vector2D(_palletProperties.Length + 2.0 * overhang.X, _palletProperties.Width + 2.0 * overhang.Y)
                , _palletProperties.Height
                , constraintSetCasePallet
                , true
                );

            Solution.SetSolver(solver);
            // loop on layers
            foreach (Layer2D layer in layers)
            {
                var layerDescs = new List <LayerDesc>();
                layerDescs.Add(layer.LayerDescriptor);
                var analysis = new AnalysisCasePallet(_packable, _palletProperties, constraintSet as ConstraintSetCasePallet);
                analysis.AddSolution(layerDescs);
                // only add analysis if it has a valid solution
                if (analysis.Solution.ItemCount > 0)
                {
                    analyses.Add(analysis);
                }
            }
            return(analyses);
        }
Example #17
0
        public List <Layer2D> BuildLayers(Vector3D dimBox, Vector2D dimContainer, ConstraintSetAbstract constraintSet, bool keepOnlyBest)
        {
            // instantiate list of layers
            List <Layer2D> listLayers0 = new List <Layer2D>();

            // loop through all patterns
            foreach (LayerPattern pattern in LayerPattern.All)
            {
                // loop through all orientation
                foreach (HalfAxis.HAxis axisOrtho in HalfAxis.All)
                {
                    // is orientation allowed
                    if (!constraintSet.AllowOrientation(axisOrtho))
                    {
                        continue;
                    }
                    // not swapped vs swapped pattern
                    for (int iSwapped = 0; iSwapped < 1; ++iSwapped)
                    {
                        // does swapping makes sense for this layer pattern ?
                        if (!pattern.CanBeSwapped && (iSwapped == 1))
                        {
                            continue;
                        }
                        // instantiate layer
                        Layer2D layer = new Layer2D(dimBox, dimContainer, axisOrtho, iSwapped == 1);
                        layer.PatternName = pattern.Name;
                        double actualLength = 0.0, actualWidth = 0.0;
                        if (!pattern.GetLayerDimensionsChecked(layer, out actualLength, out actualWidth))
                        {
                            continue;
                        }
                        pattern.GenerateLayer(layer, actualLength, actualWidth);
                        if (0 == layer.Count)
                        {
                            continue;
                        }
                        listLayers0.Add(layer);
                    }
                }
            }

            // keep only best layers
            if (keepOnlyBest)
            {
                // 1. get best count
                int bestCount = 0;
                foreach (Layer2D layer in listLayers0)
                {
                    bestCount = Math.Max(layer.CountInHeight(constraintSet.OptMaxHeight.Value), bestCount);
                }

                // 2. remove any layer that does not match the best count given its orientation
                List <Layer2D> listLayers1 = new List <Layer2D>();
                foreach (Layer2D layer in listLayers0)
                {
                    if (layer.CountInHeight(constraintSet.OptMaxHeight.Value) >= bestCount)
                    {
                        listLayers1.Add(layer);
                    }
                }
                // 3. copy back in original list
                listLayers0.Clear();
                listLayers0.AddRange(listLayers1);
            }
            if (constraintSet.OptMaxHeight.Activated)
            {
                listLayers0.Sort(new LayerComparerCount(constraintSet.OptMaxHeight.Value));
            }

            return(listLayers0);
        }
 public SolverCasePallet(PackableBrick packable, PalletProperties palletProperties, ConstraintSetAbstract constraintSet)
 {
     Packable         = packable;
     PalletProperties = palletProperties;
     if (constraintSet is ConstraintSetCasePallet constraintSetCasePallet)
     {
         ConstraintSet = constraintSetCasePallet;
     }
     else
     {
         throw new InvalidConstraintSetException();
     }
 }
Example #19
0
 public Layer2D BuildBestLayer(ConstraintSetAbstract constraintSet)
 {
     throw new NotImplementedException();
 }
Example #20
0
        public List <Layer2D> BuildLayers(
            Vector3D dimBox, Vector2D dimContainer,
            double offsetZ, /* e.g. pallet height */
            ConstraintSetAbstract constraintSet, bool keepOnlyBest)
        {
            // instantiate list of layers
            var listLayers0 = new List <Layer2D>();

            // loop through all patterns
            foreach (LayerPatternBox pattern in LayerPatternBox.All)
            {
                // loop through all orientation
                HalfAxis.HAxis[] patternAxes = pattern.IsSymetric ? HalfAxis.Positives : HalfAxis.All;
                foreach (HalfAxis.HAxis axisOrtho in patternAxes)
                {
                    // is orientation allowed
                    if (!constraintSet.AllowOrientation(Layer2D.VerticalAxis(axisOrtho)))
                    {
                        continue;
                    }
                    // not swapped vs swapped pattern
                    for (int iSwapped = 0; iSwapped < 2; ++iSwapped)
                    {
                        try
                        {
                            // does swapping makes sense for this layer pattern ?
                            if (!pattern.CanBeSwapped && (iSwapped == 1))
                            {
                                continue;
                            }
                            // instantiate layer
                            var layer = new Layer2D(dimBox, dimContainer, pattern.Name, axisOrtho, iSwapped == 1)
                            {
                                ForcedSpace = constraintSet.MinimumSpace.Value
                            };
                            if (layer.NoLayers(constraintSet.OptMaxHeight.Value) < 1)
                            {
                                continue;
                            }
                            layer.PatternName = pattern.Name;
                            if (!pattern.GetLayerDimensionsChecked(layer, out double actualLength, out double actualWidth))
                            {
                                continue;
                            }
                            pattern.GenerateLayer(layer, actualLength, actualWidth);
                            if (0 == layer.Count)
                            {
                                continue;
                            }
                            listLayers0.Add(layer);
                        }
                        catch (Exception ex)
                        {
                            _log.ErrorFormat("Pattern: {0} Orient: {1} Swapped: {2} Message: {3}"
                                             , pattern.Name
                                             , axisOrtho.ToString()
                                             , iSwapped == 1 ? "True" : "False"
                                             , ex.Message);
                        }
                    }
                }
            }
            // keep only best layers
            if (keepOnlyBest)
            {
                // 1. get best count
                int bestCount = 0;
                foreach (Layer2D layer in listLayers0)
                {
                    bestCount = Math.Max(layer.CountInHeight(constraintSet.OptMaxHeight.Value - offsetZ), bestCount);
                }

                // 2. remove any layer that does not match the best count given its orientation
                var listLayers1 = new List <Layer2D>();
                foreach (Layer2D layer in listLayers0)
                {
                    if (layer.CountInHeight(constraintSet.OptMaxHeight.Value - offsetZ) >= bestCount)
                    {
                        listLayers1.Add(layer);
                    }
                }
                // 3. copy back in original list
                listLayers0.Clear();
                listLayers0.AddRange(listLayers1);
            }
            if (constraintSet.OptMaxHeight.Activated)
            {
                listLayers0.Sort(new LayerComparerCount(constraintSet, offsetZ));
            }

            return(listLayers0);
        }
Example #21
0
        public LayerDesc BestLayerDesc(Vector3D dimBox, Vector2D dimContainer, double offsetZ, ConstraintSetAbstract constraintSet)
        {
            var layers = BuildLayers(dimBox, dimContainer, offsetZ, constraintSet, true);

            return(layers[0].LayerDescriptor);
        }
Example #22
0
        public static bool GetBestCombination(Vector3D dimBox, Vector3D dimContainer
                                              , ConstraintSetAbstract constraintSet
                                              , ref List <KeyValuePair <LayerDesc, int> > listLayer)
        {
            var layDescs = new LayerDesc[3];
            var counts   = new int[3] {
                0, 0, 0
            };
            var heights = new double[3] {
                0.0, 0.0, 0.0
            };
            Vector2D layerDim = new Vector2D(dimContainer.X, dimContainer.Y);

            // loop through all patterns
            foreach (LayerPatternBox pattern in LayerPatternBox.All)
            {
                // loop through all orientation
                HalfAxis.HAxis[] patternAxes = pattern.IsSymetric ? HalfAxis.Positives : HalfAxis.All;
                foreach (HalfAxis.HAxis axisOrtho in patternAxes)
                {
                    // is orientation allowed
                    if (!constraintSet.AllowOrientation(Layer2D.VerticalAxis(axisOrtho)))
                    {
                        continue;
                    }
                    // not swapped vs swapped pattern
                    for (int iSwapped = 0; iSwapped < 2; ++iSwapped)
                    {
                        try
                        {
                            // does swapping makes sense for this layer pattern ?
                            if (!pattern.CanBeSwapped && (iSwapped == 1))
                            {
                                continue;
                            }
                            // instantiate layer
                            var layer = new Layer2D(dimBox, layerDim, pattern.Name, axisOrtho, iSwapped == 1)
                            {
                                ForcedSpace = constraintSet.MinimumSpace.Value
                            };
                            if (layer.NoLayers(constraintSet.OptMaxHeight.Value) < 1)
                            {
                                continue;
                            }
                            layer.PatternName = pattern.Name;
                            if (!pattern.GetLayerDimensionsChecked(layer, out double actualLength, out double actualWidth))
                            {
                                continue;
                            }
                            pattern.GenerateLayer(layer, actualLength, actualWidth);
                            if (0 == layer.Count)
                            {
                                continue;
                            }
                            int iAxisIndex = layer.VerticalDirection;
                            if (layer.Count > counts[iAxisIndex])
                            {
                                counts[iAxisIndex]   = layer.Count;
                                layDescs[iAxisIndex] = layer.LayerDescriptor;
                                heights[iAxisIndex]  = layer.BoxHeight;
                            }
                        }
                        catch (Exception ex)
                        {
                            _log.Error($"Pattern: {pattern.Name} Orient: {axisOrtho.ToString()} Swapped: {iSwapped == 1} Message: {ex.Message}");
                        }
                    }
                }
            }
            double stackingHeight = dimContainer.Z;

            // single layer
            int indexIMax = 0, indexJMax = 0, noIMax = 0, noJMax = 0, iCountMax = 0;

            for (int i = 0; i < 3; ++i)
            {
                int noLayers = 0;
                if (counts[i] > 0)
                {
                    noLayers = (int)Math.Floor(stackingHeight / heights[i]);
                }
                if (counts[i] * noLayers > iCountMax)
                {
                    iCountMax = counts[i] * noLayers;
                    indexIMax = i;
                    noIMax    = noLayers;
                }
            }
            // layer combinations
            int[] comb1 = { 0, 1, 2 };
            int[] comb2 = { 1, 2, 0 };
            for (int i = 0; i < 3; ++i)
            {
                int iComb1 = comb1[i];
                int iComb2 = comb2[i];
                // --swap layers so that the thickest stays at the bottom
                if (heights[iComb2] > heights[iComb1])
                {
                    int iTemp = iComb1;
                    iComb1 = iComb2;
                    iComb2 = iTemp;
                }
                // --
                int noI = 0;
                if (counts[iComb1] != 0)
                {
                    noI = (int)Math.Floor(stackingHeight / heights[iComb1]);
                }
                // search all index
                while (noI > 0)
                {
                    double remainingHeight = stackingHeight - noI * heights[iComb1];
                    int    noJ             = 0;
                    if (counts[iComb2] != 0)
                    {
                        noJ = (int)Math.Floor(remainingHeight / heights[iComb2]);
                    }
                    if (noI * counts[iComb1] + noJ * counts[iComb2] > iCountMax)
                    {
                        indexIMax = iComb1;  indexJMax = iComb2;
                        noIMax    = noI;   noJMax = noJ;
                        iCountMax = noI * counts[iComb1] + noJ * counts[iComb2];
                    }
                    --noI;
                } // while
            }
            if (noIMax > 0)
            {
                listLayer.Add(new KeyValuePair <LayerDesc, int>(layDescs[indexIMax], noIMax));
            }
            if (noJMax > 0)
            {
                listLayer.Add(new KeyValuePair <LayerDesc, int>(layDescs[indexJMax], noJMax));
            }
            return(true);
        }
Example #23
0
        public static bool GetBestCombination(Vector3D dimBox, Vector2D dimContainer,
                                              ConstraintSetAbstract constraintSet, ref List <KeyValuePair <LayerDesc, int> > listLayer)
        {
            var layDescs = new LayerDesc[3];
            var counts   = new int[3] {
                0, 0, 0
            };
            var heights = new double[3] {
                0.0, 0.0, 0.0
            };

            // loop through all patterns
            foreach (LayerPatternBox pattern in LayerPatternBox.All)
            {
                // loop through all orientation
                HalfAxis.HAxis[] patternAxes = pattern.IsSymetric ? HalfAxis.Positives : HalfAxis.All;
                foreach (HalfAxis.HAxis axisOrtho in patternAxes)
                {
                    // is orientation allowed
                    if (!constraintSet.AllowOrientation(Layer2D.VerticalAxis(axisOrtho)))
                    {
                        continue;
                    }
                    // not swapped vs swapped pattern
                    for (int iSwapped = 0; iSwapped < 2; ++iSwapped)
                    {
                        // does swapping makes sense for this layer pattern ?
                        if (!pattern.CanBeSwapped && (iSwapped == 1))
                        {
                            continue;
                        }
                        // instantiate layer
                        var layer = new Layer2D(dimBox, dimContainer, axisOrtho, iSwapped == 1);
                        layer.PatternName = pattern.Name;
                        double actualLength = 0.0, actualWidth = 0.0;
                        if (!pattern.GetLayerDimensionsChecked(layer, out actualLength, out actualWidth))
                        {
                            continue;
                        }
                        pattern.GenerateLayer(layer, actualLength, actualWidth);
                        if (0 == layer.Count)
                        {
                            continue;
                        }

                        int iAxisIndex = HalfAxis.Direction(axisOrtho);
                        if (layer.Count > counts[iAxisIndex])
                        {
                            counts[iAxisIndex]   = layer.Count;
                            layDescs[iAxisIndex] = layer.LayerDescriptor;
                            heights[iAxisIndex]  = layer.BoxHeight;
                        }
                    }
                }
            }

            // get list of values
            int indexIMax = 0, indexJMax = 0, noIMax = 0, noJMax = 0, iCountMax = 0;

            for (int i = 0; i < 2; ++i)
            {
                int j = i + 1;
                // search best count
                double palletHeight = constraintSet.OptMaxHeight.Value;
                int    noI          = (int)Math.Floor(palletHeight / heights[i]);
                // search all index
                while (noI > 0)
                {
                    double remainingHeight = palletHeight - noI * heights[i];
                    int    noJ             = (int)Math.Floor(remainingHeight / heights[j]);
                    if (noI * counts[i] + noJ * counts[j] > iCountMax)
                    {
                        indexIMax = i;  indexJMax = j;
                        noIMax    = noI;   noJMax = noJ;
                        iCountMax = noI * counts[i] + noJ * counts[j];
                    }
                    --noI;
                } // while
            }

            listLayer.Add(new KeyValuePair <LayerDesc, int>(layDescs[indexIMax], noIMax));
            listLayer.Add(new KeyValuePair <LayerDesc, int>(layDescs[indexJMax], noJMax));
            return(true);
        }