Example #1
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;
        }
Example #2
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 #3
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 #4
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);
        }
Example #5
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);
        }