Esempio n. 1
0
        private void FormNewAnalysis_Load(object sender, EventArgs e)
        {
            try
            {
                // name / description
                if (null != _analysis)
                {
                    tbName.Text        = _analysis.Name;
                    tbDescription.Text = _analysis.Description;
                }
                // fill boxes combo
                foreach (BProperties box in _cases)
                {
                    cbBox.Items.Add(new BoxItem(box));
                }
                if (cbBox.Items.Count > 0)
                {
                    if (null == _analysis)
                    {
                        cbBox.SelectedIndex = 0;
                    }
                    else
                    {
                        for (int i = 0; i < cbBox.Items.Count; ++i)
                        {
                            BoxItem boxItem = cbBox.Items[i] as BoxItem;
                            if (boxItem.Item == _analysis.BProperties)
                            {
                                cbBox.SelectedIndex = i;
                                break;
                            }
                        }
                    }
                }
                // fill pallet combo
                foreach (PalletProperties pallet in _palletProperties)
                {
                    cbPallet.Items.Add(new PalletItem(pallet));
                }
                if (cbPallet.Items.Count > 0)
                {
                    if (null == _analysis)
                    {
                        cbPallet.SelectedIndex = 0;
                    }
                    else
                    {
                        for (int i = 0; i < cbPallet.Items.Count; ++i)
                        {
                            PalletItem palletItem = cbPallet.Items[i] as PalletItem;
                            if (palletItem.Item == _analysis.PalletProperties)
                            {
                                cbPallet.SelectedIndex = i;
                                break;
                            }
                        }
                    }
                }
                // fill other combo
                FillCombo(checkBoxInterlayer, cbInterlayer, _interlayerProperties, (null == _analysis) ? null : _analysis.InterlayerProperties);
                FillCombo(checkBoxAntiSlipInterlayer, cbInterlayerAntiSlip, _interlayerProperties, (null == _analysis) ? null : _analysis.InterlayerPropertiesAntiSlip);
                FillCombo(chkbPalletCorners, cbPalletCorners, _palletCornerProperties, (null == _analysis) ? null : _analysis.PalletCornerProperties);
                FillCombo(chkbPalletCap, cbPalletCap, _palletCapProperties, (null == _analysis) ? null : _analysis.PalletCapProperties);
                FillCombo(chkbPalletFilm, cbPalletFilm, _palletFilmProperties, (null == _analysis) ? null : _analysis.PalletFilmProperties);
                // overhang
                if (null == _analysis)
                {
                    OverhangX = Settings.Default.OverhangX;
                    OverhangY = Settings.Default.OverhangY;
                }
                else
                {
                    OverhangX = _analysis.ConstraintSet.OverhangX;
                    OverhangY = _analysis.ConstraintSet.OverhangY;
                }

                // allowed position box + allowed patterns
                if (null == _analysis)
                {
                    AllowVerticalX = Settings.Default.AllowVerticalX;
                    AllowVerticalY = Settings.Default.AllowVerticalY;
                    AllowVerticalZ = Settings.Default.AllowVerticalZ;

                    AllowedPatternsString = Settings.Default.AllowedPatterns;

                    AllowTwoLayerOrientations       = Settings.Default.AllowLayerOrientChange;
                    AllowLastLayerOrientationChange = Settings.Default.AllowLayerOrientChangeLastOnly;
                }
                else
                {
                    PalletConstraintSet constraintSet = _analysis.ConstraintSet;
                    InterlayerPeriod = Math.Max(constraintSet.InterlayerPeriod, 1);
                    AllowVerticalX   = constraintSet.AllowOrthoAxis(HalfAxis.HAxis.AXIS_X_N) || constraintSet.AllowOrthoAxis(HalfAxis.HAxis.AXIS_X_P);
                    AllowVerticalY   = constraintSet.AllowOrthoAxis(HalfAxis.HAxis.AXIS_Y_N) || constraintSet.AllowOrthoAxis(HalfAxis.HAxis.AXIS_Y_P);
                    AllowVerticalZ   = constraintSet.AllowOrthoAxis(HalfAxis.HAxis.AXIS_Z_N) || constraintSet.AllowOrthoAxis(HalfAxis.HAxis.AXIS_Z_P);

                    AllowTwoLayerOrientations       = constraintSet.AllowTwoLayerOrientations;
                    AllowLastLayerOrientationChange = constraintSet.AllowLastLayerOrientationChange;

                    AllowedPatternsString = constraintSet.AllowedPatternString;
                }

                // alternate / aligned layers + stop stacking criterion
                if (null == _analysis)
                {
                    AllowAlignedLayers   = Settings.Default.AllowAlignedLayer;
                    AllowAlternateLayers = Settings.Default.AllowAlternateLayer;

                    UseMaximumNumberOfBoxes = false;
                    UseMaximumPalletHeight  = true;
                    UseMaximumPalletWeight  = true;
                    UseMaximumLoadOnBox     = false;

                    MaximumNumberOfBoxes = 500;
                    MaximumPalletHeight  = UnitsManager.ConvertLengthFrom(Properties.Settings.Default.MaximumPalletHeight, UnitsManager.UnitSystem.UNIT_METRIC1);
                    MaximumPalletWeight  = UnitsManager.ConvertMassFrom(Properties.Settings.Default.MaximumPalletWeight, UnitsManager.UnitSystem.UNIT_METRIC1);
                    MaximumLoadOnBox     = 100.0;
                }
                else
                {
                    AllowAlignedLayers      = _analysis.ConstraintSet.AllowAlignedLayers;
                    AllowAlternateLayers    = _analysis.ConstraintSet.AllowAlternateLayers;
                    UseMaximumNumberOfBoxes = _analysis.ConstraintSet.UseMaximumNumberOfCases;
                    UseMaximumPalletHeight  = _analysis.ConstraintSet.UseMaximumHeight;
                    UseMaximumPalletWeight  = _analysis.ConstraintSet.UseMaximumPalletWeight;
                    UseMaximumLoadOnBox     = _analysis.ConstraintSet.UseMaximumWeightOnBox;

                    MaximumNumberOfBoxes = _analysis.ConstraintSet.MaximumNumberOfItems;
                    MaximumPalletHeight  = _analysis.ConstraintSet.MaximumHeight;
                    MaximumPalletWeight  = _analysis.ConstraintSet.MaximumPalletWeight;
                    MaximumLoadOnBox     = _analysis.ConstraintSet.MaximumWeightOnBox;
                }

                if (null != _analysis)
                {
                    PalletFilmTurns = _analysis.ConstraintSet.PalletFilmTurns;
                }

                UpdateCriterionFields();
                UpdateButtonOkStatus();

                // windows settings
                if (null != Settings.Default.FormNewAnalysisPosition)
                {
                    Settings.Default.FormNewAnalysisPosition.Restore(this);
                }
            }
            catch (Exception ex)
            {
                _log.Error(ex.ToString());
            }
        }
Esempio n. 2
0
        private List <CasePalletSolution> GenerateSolutions()
        {
            // generate best layers
            Layer2D[] bestLayers = new Layer2D[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 (LayerPatternBox pattern in LayerPatternBox.All)
            {
                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)
                {
                    // 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)
                            Layer2D layer1 = BuildLayer(_bProperties, _palletProperties, _cornerProperties, _constraintSet, axisOrtho1, swapPos == 1, false);
                            Layer2D layer1_inv = BuildLayer(_bProperties, _palletProperties, _cornerProperties, _constraintSet, axisOrtho1, swapPos == 1, true);
                            Layer2D layer2 = BuildLayer(_bProperties, _palletProperties, _cornerProperties, _constraintSet, axisOrtho2, swapPos == 1, false);
                            Layer2D layer2_inv = BuildLayer(_bProperties, _palletProperties, _cornerProperties, _constraintSet, axisOrtho2, swapPos == 1, true);
                            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 < 6; ++j)
                            {
                                Layer2D 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";
                                }
                                else if (4 == j && _constraintSet.AllowAlternateLayers && pattern.CanBeInverted && bResult1)
                                {
                                    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 && bResult2)
                                {
                                    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;
                                    Layer2D    currentLayer    = iLayerIndex % 2 == 0 ? layer1T : layer2T;
                                    Layer3DBox layer           = sol.CreateNewLayer(zLayer, 0);
                                    layer.MaximumSpace = currentLayer.MaximumSpace;

                                    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);
                                    // check number
                                    maxNumberReached = _constraintSet.UseMaximumNumberOfCases && (iCount + 1 > _constraintSet.MaximumNumberOfItems);
                                    // check weight
                                    maxWeightReached = _constraintSet.UseMaximumPalletWeight && (((iCount + 1) * _bProperties.Weight + _palletProperties.Weight) > _constraintSet.MaximumPalletWeight);
                                }

                                if (maxHeightReached && _constraintSet.AllowLastLayerOrientationChange)
                                {
                                    // remaining height
                                    double remainingHeight = _constraintSet.MaximumHeight - zLayer;
                                    // test to complete with best layer
                                    Layer2D bestLayer = null; int ibestLayerCount = 0;
                                    for (int iLayerDir = 0; iLayerDir < 3; ++iLayerDir)
                                    {
                                        // another direction than the current direction
                                        if (iLayerDir == i)
                                        {
                                            continue;
                                        }

                                        Layer2D 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)
                                        {
                                            Layer3DBox layer = sol.CreateNewLayer(zLayer, 0);

                                            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);
        }