Esempio n. 1
0
 public Pack(uint pickId, PackProperties packProperties, BoxPosition position)
     : base(pickId, packProperties, position)
 {
     _packProperties = packProperties;
     _arrangement = _packProperties.Arrangement;
     _innerBox = new Box(0, packProperties.Box);
     _forceTransparency = false;
 }
Esempio n. 2
0
 public static BoxPosition Transform(BoxPosition boxPosition, Transform3D transform)
 {
     if (!boxPosition.IsValid)
         throw new Exception("Invalid box position : can not transform");
     return new BoxPosition(
         transform.transform(boxPosition.Position)
         , HalfAxis.Transform(boxPosition.DirectionLength, transform)
         , HalfAxis.Transform(boxPosition.DirectionWidth, transform)
         );
 }
Esempio n. 3
0
        public static bool BoxCanMoveInside(BoxPosition bPos, Vector3D dim, Vector2D ptMin, Vector2D ptMax, HalfAxis.HAxis axis)
        {
            var bbox = bPos.BBox(dim);

            switch (axis)
            {
            case HalfAxis.HAxis.AXIS_X_N: return(bbox.PtMin.X > ptMin.X);

            case HalfAxis.HAxis.AXIS_X_P: return(bbox.PtMax.X < ptMax.X);

            case HalfAxis.HAxis.AXIS_Y_N: return(bbox.PtMin.Y > ptMin.Y);

            case HalfAxis.HAxis.AXIS_Y_P: return(bbox.PtMax.Y < ptMax.Y);

            default: return(false);
            }
        }
Esempio n. 4
0
        private BBox3D ComputeLoadBBox3D()
        {
            double palletLength = ParentTruckAnalysis.ParentSolution.PalletLength;
            double palletWidth  = ParentTruckAnalysis.ParentSolution.PalletWidth;
            double palletHeight = ParentTruckAnalysis.ParentSolution.PalletHeight;

            BBox3D bbox   = new BBox3D();
            int    iLayer = 0;

            while (iLayer < NoLayers)
            {
                foreach (BoxPosition bPositionLayer in Layer)
                {
                    // actual position in load
                    BoxPosition bpos = new BoxPosition(
                        new Vector3D(
                            bPositionLayer.Position.X
                            , bPositionLayer.Position.Y
                            , bPositionLayer.Position.Z + palletHeight * iLayer)
                        , bPositionLayer.DirectionLength
                        , bPositionLayer.DirectionWidth);

                    Vector3D[] pts = new Vector3D[8];
                    Vector3D   vI  = HalfAxis.ToVector3D(bpos.DirectionLength);
                    Vector3D   vJ  = HalfAxis.ToVector3D(bpos.DirectionWidth);
                    Vector3D   vK  = Vector3D.CrossProduct(vI, vJ);
                    pts[0] = bpos.Position;
                    pts[1] = bpos.Position + palletLength * vI;
                    pts[2] = bpos.Position + palletWidth * vJ;
                    pts[3] = bpos.Position + palletLength * vI + palletWidth * vJ;
                    pts[4] = bpos.Position + palletHeight * vK;
                    pts[5] = bpos.Position + palletWidth * vJ + palletHeight * vK;;
                    pts[6] = bpos.Position + HalfAxis.ToVector3D(bpos.DirectionWidth) * palletWidth;
                    pts[7] = bpos.Position + HalfAxis.ToVector3D(bpos.DirectionLength) * palletLength + HalfAxis.ToVector3D(bpos.DirectionWidth) * palletWidth;

                    foreach (Vector3D pt in pts)
                    {
                        bbox.Extend(pt);
                    }
                }
                ++iLayer;
            }
            return(bbox);
        }
Esempio n. 5
0
        private BoxPosition ApplyReflection(BoxPosition layerPos, Matrix4D matRot, Vector3D vTranslation)
        {
            Vector3D    dimensions = Analysis.ContentDimensions;
            Transform3D transfRot  = new Transform3D(matRot);

            HalfAxis.HAxis axisLength = HalfAxis.ToHalfAxis(transfRot.transform(HalfAxis.ToVector3D(layerPos.DirectionLength)));
            HalfAxis.HAxis axisWidth  = HalfAxis.ToHalfAxis(transfRot.transform(HalfAxis.ToVector3D(layerPos.DirectionWidth)));
            matRot.M14 = vTranslation[0];
            matRot.M24 = vTranslation[1];
            matRot.M34 = vTranslation[2];
            Transform3D transfRotTranslation = new Transform3D(matRot);

            Vector3D transPos = transfRotTranslation.transform(new Vector3D(layerPos.Position.X, layerPos.Position.Y, layerPos.Position.Z));

            return(new BoxPosition(
                       new Vector3D(transPos.X, transPos.Y, transPos.Z)
                       - dimensions.Z * Vector3D.CrossProduct(HalfAxis.ToVector3D(axisLength), HalfAxis.ToVector3D(axisWidth))
                       , axisLength
                       , axisWidth));
        }
Esempio n. 6
0
        public static bool HaveIntersection(BoxPosition bPos1, Vector3D dim1, BoxPosition bPos2, Vector3D dim2)
        {
            var      bbox1 = bPos1.BBox(dim1);
            var      bbox2 = bPos2.BBox(dim2);
            Vector3D pt1 = bbox1.PtMin, pt2 = bbox1.PtMax;
            Vector3D pt3 = bbox2.PtMin, pt4 = bbox2.PtMax;

            Vector3D pt5 = new Vector3D(Math.Max(pt1.X, pt3.X), Math.Max(pt1.Y, pt3.Y), Math.Max(pt1.Z, pt3.Z));
            Vector3D pt6 = new Vector3D(Math.Min(pt2.X, pt4.X), Math.Min(pt2.Y, pt4.Y), Math.Min(pt2.Z, pt4.Z));

            // no intersections ?
            if ((pt5.X - pt6.X > -EPSILON) ||
                (pt5.Y - pt6.Y > -EPSILON) ||
                (pt5.Z - pt6.Z > -EPSILON))
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Esempio n. 7
0
        public BBox3D(BoxPosition bPos, Vector3D dim)
        {
            Vector3D lengthAxis = HalfAxis.ToVector3D(bPos.DirectionLength);
            Vector3D widthAxis  = HalfAxis.ToVector3D(bPos.DirectionWidth);
            Vector3D heightAxis = HalfAxis.ToVector3D(bPos.DirectionHeight);

            var points = new Vector3D[8];

            points[0] = bPos.Position;
            points[1] = bPos.Position + dim[0] * lengthAxis;
            points[2] = bPos.Position + dim[0] * lengthAxis + dim[1] * widthAxis;
            points[3] = bPos.Position + dim[1] * widthAxis;

            points[4] = bPos.Position + dim[2] * heightAxis;
            points[5] = bPos.Position + dim[2] * heightAxis + dim[0] * lengthAxis;
            points[6] = bPos.Position + dim[2] * heightAxis + dim[0] * lengthAxis + dim[1] * widthAxis;
            points[7] = bPos.Position + dim[2] * heightAxis + dim[1] * widthAxis;

            foreach (var pt in points)
            {
                Extend(pt);
            }
        }
Esempio n. 8
0
 public static bool HaveIntersection(List <BoxPosition> list, Vector3D dim, int selectedIndex, BoxPosition bPosition)
 {
     for (int i = 0; i < list.Count; ++i)
     {
         if (i != selectedIndex && HaveIntersection(list[i], dim, bPosition, dim))
         {
             return(true);
         }
     }
     return(false);
 }
 public BoxPositionIndexed(Vector3D vPos, HalfAxis.HAxis axisLength, HalfAxis.HAxis axisWidth, int index)
 {
     BPos = new BoxPosition(vPos, axisLength, axisWidth);
     Index = index;
 }
Esempio n. 10
0
        public void Draw(Graphics3D graphics)
        {
            if (null == _truckSolution)
                throw new Exception("No trucksolution defined!");
            // draw truck
            Truck truck = new Truck(_truckSolution.ParentTruckAnalysis.TruckProperties);
            truck.DrawBegin(graphics);
            truck.DrawEnd(graphics);

            // get pallet height
            CasePalletAnalysis analysis = _truckSolution.ParentTruckAnalysis.ParentAnalysis;
            double palletLength = _truckSolution.ParentTruckAnalysis.ParentSolution.PalletLength;
            double palletWidth = _truckSolution.ParentTruckAnalysis.ParentSolution.PalletWidth;
            double palletHeight = _truckSolution.ParentTruckAnalysis.ParentSolution.PalletHeight;

            // get parent pallet solution
            CasePalletSolution sol = _truckSolution.ParentTruckAnalysis.ParentSolution;

            // draw solution
            uint pickIdGlobal = 0;
            for (int i = 0; i < _truckSolution.NoLayers; ++i)
            {
                foreach (BoxPosition bPositionLayer in _truckSolution.Layer)
                {
                    BoxPosition bPalletPosition = new BoxPosition(
                        new Vector3D(
                            bPositionLayer.Position.X
                            , bPositionLayer.Position.Y
                            , bPositionLayer.Position.Z + palletHeight * i)
                        , bPositionLayer.DirectionLength
                        , bPositionLayer.DirectionWidth);
                    if (_showDetails)
                    {
                        // build transformation
                        Transform3D transformPallet = bPalletPosition.Transformation;

                        // draw pallet
                        Pallet pallet = new Pallet(analysis.PalletProperties);
                        pallet.Draw(graphics, transformPallet);

                        // draw solution
                        uint pickId = 0;
                        foreach (ILayer layer in sol)
                        {
                            BoxLayer bLayer = layer as BoxLayer;
                            if (null != bLayer)
                            {
                                foreach (BoxPosition bPosition in bLayer)
                                    graphics.AddBox(new Box(pickId++, analysis.BProperties, BoxPosition.Transform(bPosition, transformPallet)));
                            }

                            InterlayerPos interlayerPos = layer as InterlayerPos;
                            if (null != interlayerPos)
                            {
                                BoxPosition iPos = new BoxPosition(new Vector3D(0.0, 0.0, interlayerPos.ZLow), HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Y_P);
                                graphics.AddBox(new Box(pickId++, analysis.InterlayerProperties, BoxPosition.Transform(iPos, transformPallet)));
                            }
                        }
                    }
                    else
                    {
                        Box b = new Box(pickIdGlobal++, new BoxProperties(null, palletLength, palletWidth, palletHeight), bPalletPosition);
                        b.SetAllFacesColor(Color.Chocolate);
                        graphics.AddBox(b);
                    }
                }
            }

            // fluch
            graphics.UseBoxelOrderer = false; // can not use boxel orderer for full truck view -> too slow...
        }
Esempio n. 11
0
 public void AddPosition(BoxPosition position) => Add(position);
Esempio n. 12
0
        private List<CasePalletSolution> GenerateSolutions()
        {
            // generate best layers
            Layer[] bestLayers = new Layer[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 (LayerPattern pattern in _patterns)
            {
                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)
                {
                    pattern.Swapped = swapPos == 1;

                    // 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)
                            Layer layer1 = new Layer(_bProperties, _palletProperties, _cornerProperties, _constraintSet, axisOrtho1);
                            Layer layer1_inv = new Layer(_bProperties, _palletProperties, _cornerProperties, _constraintSet, axisOrtho1, true);
                            Layer layer2 = new Layer(_bProperties, _palletProperties, _cornerProperties, _constraintSet, axisOrtho2);
                            Layer layer2_inv = new Layer(_bProperties, _palletProperties, _cornerProperties, _constraintSet, axisOrtho2, 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)
                            {
                                Layer 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;
                                    Layer currentLayer = iLayerIndex % 2 == 0 ? layer1T : layer2T;
                                    BoxLayer layer = sol.CreateNewLayer(zLayer, pattern.Name);
                                    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
                                    Layer bestLayer = null; int ibestLayerCount = 0;
                                    for (int iLayerDir = 0; iLayerDir < 3; ++iLayerDir)
                                    {
                                        // another direction than the current direction
                                        if (iLayerDir == i) continue;

                                        Layer 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)
                                        {
                                            BoxLayer layer = sol.CreateNewLayer(zLayer, string.Empty);

                                            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;
        }
Esempio n. 13
0
        public void CreateAnimation(uint caseIndex, uint caseCount, List<object> listAnimationObjects, BoxPosition bPos)
        {
            const int iStep = 5;
            _zOffset = _palletSolution.PalletHeight + 100.0;

            // build list of time
            List<double> listTime = new List<double>();
            List<string> listInterp = new List<string>();
            listTime.Add(0.0);
            listInterp.Add("LINEAR");
            for (int i = 0; i < iStep; ++i)
            {
                listTime.Add(((double)caseIndex + (double)i / (double)(iStep - 1)));
                listInterp.Add("LINEAR");
            }
            listTime.Add(caseCount);
            listInterp.Add("LINEAR");

            BProperties bProperties = _palletSolution.Analysis.BProperties;
            PalletProperties pProperties = _palletSolution.Analysis.PalletProperties;

            double yOffset = 0.5 * (_palletSolution.Analysis.PalletProperties.Width - bProperties.Length);
            BoxPosition bPosFinal = GetFinalBoxPosition(caseIndex);

            List<BoxPosition> listBoxPosition = new List<BoxPosition>();
            // -1.
            listBoxPosition.Add(GetInitialBoxPosition(caseIndex));
            // 0. initialbox position
            listBoxPosition.Add(GetInitialBoxPosition(caseIndex));
            // 1. position at out storing area
            listBoxPosition.Add(new BoxPosition(new Vector3D(_xOffset, yOffset, _zOffset), HalfAxis.HAxis.AXIS_Y_P, HalfAxis.HAxis.AXIS_X_N));
            // 2. position above pallet
            listBoxPosition.Add(new BoxPosition(new Vector3D(pProperties.Length * 0.5, pProperties.Width * 0.5, _zOffset), bPosFinal.DirectionLength, bPosFinal.DirectionWidth));
            // 3. position above final position
            listBoxPosition.Add(new BoxPosition(new Vector3D(bPosFinal.Position.X, bPosFinal.Position.Y, _zOffset), bPosFinal.DirectionLength, bPosFinal.DirectionWidth));
            // 4. final position
            listBoxPosition.Add(bPosFinal);
            // 5.
            listBoxPosition.Add(bPosFinal);

            List<double> listX = new List<double>();
            List<double> listY = new List<double>();
            List<double> listZ = new List<double>();
            List<double> listRX = new List<double>();
            List<double> listRY = new List<double>();
            List<double> listRZ = new List<double>();

            BoxPosition bPprev0 = listBoxPosition[0];
            listX.Add(bPprev0.Position.X);
            listY.Add(bPprev0.Position.Y);
            listZ.Add(bPprev0.Position.Z);
            Vector3D vRotPrev0 = bPprev0.Transformation.Rotations;
            listRX.Add(vRotPrev0.X);
            listRY.Add(vRotPrev0.Y);
            listRZ.Add(vRotPrev0.Z);

            for (int i = 1; i < listBoxPosition.Count; ++i)
            {
                BoxPosition bP = listBoxPosition[i];
                listX.Add(bP.Position.X);
                listY.Add(bP.Position.Y);
                listZ.Add(bP.Position.Z);
                Vector3D vRot = bP.Transformation.Rotations;
                listRX.Add(vRot.X);
                listRY.Add(vRot.Y);
                listRZ.Add(vRot.Z);
            }

            // time
            source sTime = new source()
            {
                id = string.Format("sTime_{0}_ID", caseIndex),
                name = string.Format("sTime_{0}", caseIndex),
                Item = new float_array()
                {
                    id = string.Format("fa_time_{0}_ID", caseIndex),
                    count = (ulong)listTime.Count,
                    Values = listTime.ToArray()
                },
                technique_common = new sourceTechnique_common()
                {
                    accessor = new accessor()
                    {
                        source = string.Format("#fa_time_{0}_ID", caseIndex),
                        count = (ulong)listTime.Count,
                        stride = 1,
                        param = new param[]
                        {
                            new param() { name="TIME", type="float" }
                        }
                    }
                }
            };
            listAnimationObjects.Add(sTime);

            // interp
            source sInterp = new source()
            {
                id = string.Format("sInterp_{0}_ID", caseIndex),
                name = string.Format("sInterp_{0}", caseIndex),
                Item = new Name_array()
                {
                    id = string.Format("na_interp_{0}_ID", caseIndex),
                    count = (ulong)listInterp.Count,
                    Values = listInterp.ToArray()
                },
                technique_common = new sourceTechnique_common()
                {
                    accessor = new accessor()
                    {
                        source = string.Format("#na_interp_{0}_ID", caseIndex),
                        count = (ulong)listInterp.Count,
                        stride = 1,
                        param = new param[]
                        {
                            new param() { name="INTERPOLATION", type="name" }
                        }
                    }
                }
            };
            listAnimationObjects.Add(sInterp);

            CreateChannel(listAnimationObjects, caseIndex, "X", "TIME", string.Format("CaseNode_{0}_ID/t.X", caseIndex), listX);
            CreateChannel(listAnimationObjects, caseIndex, "Y", "TIME", string.Format("CaseNode_{0}_ID/t.Y", caseIndex), listY);
            CreateChannel(listAnimationObjects, caseIndex, "Z", "TIME", string.Format("CaseNode_{0}_ID/t.Z", caseIndex), listZ);
            CreateChannel(listAnimationObjects, caseIndex, "RX", "ANGLE", string.Format("CaseNode_{0}_ID/rx.ANGLE", caseIndex), listRX);
            CreateChannel(listAnimationObjects, caseIndex, "RY", "ANGLE", string.Format("CaseNode_{0}_ID/ry.ANGLE", caseIndex), listRY);
            CreateChannel(listAnimationObjects, caseIndex, "RZ", "ANGLE", string.Format("CaseNode_{0}_ID/rz.ANGLE", caseIndex), listRZ);

        }
Esempio n. 14
0
        private BBox3D ComputeLoadBBox3D()
        {
            double palletLength = ParentTruckAnalysis.ParentSolution.PalletLength;
            double palletWidth = ParentTruckAnalysis.ParentSolution.PalletWidth;
            double palletHeight = ParentTruckAnalysis.ParentSolution.PalletHeight;

            BBox3D bbox = new BBox3D();
            int iLayer = 0;
            while (iLayer < NoLayers)
            {
                foreach (BoxPosition bPositionLayer in Layer)
                {
                    // actual position in load
                    BoxPosition bpos = new BoxPosition(
                        new Vector3D(
                            bPositionLayer.Position.X
                            , bPositionLayer.Position.Y
                            , bPositionLayer.Position.Z + palletHeight * iLayer)
                        , bPositionLayer.DirectionLength
                        , bPositionLayer.DirectionWidth);

                    Vector3D[] pts = new Vector3D[8];
                    Vector3D vI = HalfAxis.ToVector3D(bpos.DirectionLength);
                    Vector3D vJ = HalfAxis.ToVector3D(bpos.DirectionWidth);
                    Vector3D vK = Vector3D.CrossProduct(vI, vJ);
                    pts[0] = bpos.Position;
                    pts[1] = bpos.Position + palletLength * vI;
                    pts[2] = bpos.Position + palletWidth * vJ;
                    pts[3] = bpos.Position + palletLength * vI + palletWidth * vJ;
                    pts[4] = bpos.Position + palletHeight * vK;
                    pts[5] = bpos.Position + palletWidth * vJ + palletHeight * vK; ;
                    pts[6] = bpos.Position + HalfAxis.ToVector3D(bpos.DirectionWidth) * palletWidth;
                    pts[7] = bpos.Position + HalfAxis.ToVector3D(bpos.DirectionLength) * palletLength + HalfAxis.ToVector3D(bpos.DirectionWidth) * palletWidth;

                    foreach (Vector3D pt in pts)
                        bbox.Extend(pt);

                }
                ++iLayer;
            }
            return bbox;
        }
Esempio n. 15
0
        public static bool MinDistance(
            BoxPosition bPos1, Vector3D dim1
            , BoxPosition bPos2, Vector3D dim2
            , HalfAxis.HAxis axis
            , ref double distance)
        {
            var      bbox1 = bPos1.BBox(dim1);
            var      bbox2 = bPos2.BBox(dim2);
            Vector3D pt1 = bbox1.PtMin, pt2 = bbox1.PtMax;
            Vector3D pt3 = bbox2.PtMin, pt4 = bbox2.PtMax;

            Vector3D pt5 = new Vector3D(Math.Max(pt1.X, pt3.X), Math.Max(pt1.Y, pt3.Y), Math.Max(pt1.Z, pt3.Z));
            Vector3D pt6 = new Vector3D(Math.Min(pt2.X, pt4.X), Math.Min(pt2.Y, pt4.Y), Math.Min(pt2.Z, pt4.Z));

            if (axis == HalfAxis.HAxis.AXIS_X_N || axis == HalfAxis.HAxis.AXIS_X_P)
            {
                if ((pt5.Y - pt6.Y > -EPSILON) || (pt5.Z - pt6.Z > -EPSILON))
                {
                    return(false);
                }
                if (axis == HalfAxis.HAxis.AXIS_X_N)
                {
                    distance = pt1.X - pt4.X;
                    return(distance >= -EPSILON);
                }
                else if (axis == HalfAxis.HAxis.AXIS_X_P)
                {
                    distance = pt3.X - pt2.X;
                    return(distance >= -EPSILON);
                }
            }
            else if (axis == HalfAxis.HAxis.AXIS_Y_N || axis == HalfAxis.HAxis.AXIS_Y_P)
            {
                if ((pt5.X - pt6.X > -EPSILON) || (pt5.Z - pt6.Z > -EPSILON))
                {
                    return(false);
                }
                if (axis == HalfAxis.HAxis.AXIS_Y_N)
                {
                    distance = pt1.Y - pt4.Y;
                    return(distance >= -EPSILON);
                }
                else if (axis == HalfAxis.HAxis.AXIS_Y_P)
                {
                    distance = pt3.Y - pt2.Y;
                    return(distance >= -EPSILON);
                }
            }
            else if (axis == HalfAxis.HAxis.AXIS_Z_N || axis == HalfAxis.HAxis.AXIS_Z_P)
            {
                if ((pt5.X - pt6.X > -EPSILON) || (pt5.Y - pt6.Z > -EPSILON))
                {
                    return(false);
                }
                if (axis == HalfAxis.HAxis.AXIS_Z_N)
                {
                    distance = pt1.Z - pt4.Z;
                    return(distance >= -EPSILON);
                }
                else if (axis == HalfAxis.HAxis.AXIS_Z_P)
                {
                    distance = pt3.Z - pt2.Z;
                    return(distance >= -EPSILON);
                }
            }
            distance = 0.0;
            return(false);
        }
Esempio n. 16
0
 public BoxPositionIndexed(BoxPosition boxPosition, int index)
 {
     BPos = boxPosition;
     Index = index;
 }
Esempio n. 17
0
 public BoxPosition Transform(Transform3D transform)
 {
     return(BoxPosition.Transform(this, transform));
 }
Esempio n. 18
0
 protected void Add(BoxPosition position) => _listBoxPosition.Add(position);
Esempio n. 19
0
 public bool IsOnFace(HalfAxis.HAxis axis, BoxPosition boxPosition, ref List <Vector3D> points)
 {
     return(false);
 }
Esempio n. 20
0
        private List<PackPalletSolution> GenerateSolutions()
        {
            List<PackPalletSolution> solutions = new List<PackPalletSolution>();

            HalfAxis.HAxis[] axes = { HalfAxis.HAxis.AXIS_Z_N, HalfAxis.HAxis.AXIS_Z_P };
            // loop throught all patterns
            foreach (LayerPattern pattern in LayerPattern.All)
            {
                // loop throught all axes
                foreach (HalfAxis.HAxis axis in axes) // axis
                {
                    // loop through
                    Layer2D layer = BuildLayer(_packProperties, _palletProperties, _constraintSet, axis, false, false);
                    double actualLength = 0.0, actualWidth = 0.0;
                    if (!pattern.GetLayerDimensionsChecked(layer, out actualLength, out actualWidth))
                        continue;
                    pattern.GenerateLayer(layer, actualLength, actualWidth);

                    // filter by layer weight
                    if (_constraintSet.MaximumLayerWeight.Activated
                        && (layer.Count * _packProperties.Weight > _constraintSet.MaximumLayerWeight.Value))
                        continue;
                    // filter by maximum space
                    if (_constraintSet.MaximumSpaceAllowed.Activated
                        && layer.MaximumSpace > _constraintSet.MaximumSpaceAllowed.Value)
                        continue;
                    double layerHeight = layer.BoxHeight;

                    string title = string.Format("{0}-{1}", pattern.Name, axis.ToString());
                    double zLayer = 0.0;
                    BoxLayer boxLayer = new BoxLayer(zLayer, 0);
                    foreach (LayerPosition layerPos in layer)
                    {
                        LayerPosition layerPosTemp = AdjustLayerPosition(layerPos);
                        BoxPosition boxPos = new BoxPosition(
                            layerPosTemp.Position
                                - (0.5 * _constraintSet.OverhangX) * Vector3D.XAxis
                                - (0.5 * _constraintSet.OverhangY) * Vector3D.YAxis
                                + zLayer * Vector3D.ZAxis
                            , layerPosTemp.LengthAxis
                            , layerPosTemp.WidthAxis
                            );
                        boxLayer.Add(boxPos);
                    }
                    boxLayer.MaximumSpace = layer.MaximumSpace;
                    BBox3D layerBBox = boxLayer.BoundingBox(_packProperties);
                    // filter by overhangX
                    if (_constraintSet.MinOverhangX.Activated
                        && (0.5 * (layerBBox.Length - _palletProperties.Length) < _constraintSet.MinOverhangX.Value))
                        continue;
                    // filter by overhangY
                    if (_constraintSet.MinOverhangY.Activated
                        && (0.5 * (layerBBox.Width - _palletProperties.Width) < _constraintSet.MinOverhangY.Value))
                        continue;

                    double interlayerThickness = null != _interlayerProperties ? _interlayerProperties.Thickness : 0;
                    double interlayerWeight = null != _interlayerProperties ? _interlayerProperties.Weight : 0;

                    PackPalletSolution sol = new PackPalletSolution(null, title, boxLayer);
                    int noLayer = 1,
                        noInterlayer = (null != _interlayerProperties && _constraintSet.HasFirstInterlayer) ? 1 : 0;

                    bool maxHeightReached = _constraintSet.MaximumPalletHeight.Activated
                        && (_packProperties.Height
                        + noInterlayer * interlayerThickness
                        + noLayer * layer.BoxHeight) > _constraintSet.MaximumPalletHeight.Value;
                    bool maxWeightReached = _constraintSet.MaximumPalletWeight.Activated
                        && (_palletProperties.Weight
                        + noInterlayer * interlayerWeight
                        + noLayer * boxLayer.Count * _packProperties.Weight > _constraintSet.MaximumPalletWeight.Value);

                    noLayer = 0; noInterlayer = 0;
                    int iCountInterlayer = 0, iCountSwap = 1;
                    bool bSwap = false;
                    while (!maxHeightReached && !maxWeightReached)
                    {
                        bool bInterlayer = (0 == iCountInterlayer) && ((noLayer != 0) || _constraintSet.HasFirstInterlayer);
                        // actually insert new layer
                        sol.AddLayer(bSwap, bInterlayer);
                        // increment number of layers
                        noLayer++;
                        noInterlayer += (bInterlayer ? 1 : 0);
                        // update iCountInterlayer && iCountSwap
                        ++iCountInterlayer;
                        if (iCountInterlayer >= _constraintSet.InterlayerPeriod) iCountInterlayer = 0;
                        ++iCountSwap;
                        if (iCountSwap > _constraintSet.LayerSwapPeriod) { iCountSwap = 1; bSwap = !bSwap; }
                        // update maxHeightReached & maxWeightReached
                        maxHeightReached = _constraintSet.MaximumPalletHeight.Activated
                            && (_palletProperties.Height
                            + (noInterlayer + (iCountInterlayer == 0 ? 1 : 0)) * interlayerThickness
                            + (noLayer + 1) * layer.BoxHeight) > _constraintSet.MaximumPalletHeight.Value;
                        maxWeightReached = _constraintSet.MaximumPalletWeight.Activated
                            && (_palletProperties.Weight
                            + (noInterlayer + (iCountInterlayer == 0 ? 1 : 0)) * interlayerWeight
                            + (noLayer + 1) * boxLayer.Count * _packProperties.Weight > _constraintSet.MaximumPalletWeight.Value);
                    }

                    if (sol.PackCount > 0)
                        solutions.Add(sol);
                } // axis
            } // pattern
            solutions.Sort();
            return solutions;
        }
Esempio n. 21
0
        public Box(uint pickId, BProperties bProperties, BoxPosition bPosition)
        {
            if (!bPosition.IsValid)
                throw new GraphicsException("Invalid BoxPosition: can not create box");
            _pickId = pickId;
            _dim[0] = bProperties.Length;
            _dim[1] = bProperties.Width;
            _dim[2] = bProperties.Height;

            _colors = bProperties.Colors;

            BoxProperties boxProperties = bProperties as BoxProperties;
            if (null != boxProperties)
            {
                List<Pair<HalfAxis.HAxis, Texture>> textures = boxProperties.TextureList;
                foreach (Pair<HalfAxis.HAxis, Texture> tex in textures)
                {
                    int iIndex = (int)tex.first;
                    if (null == _textureLists[iIndex])
                        _textureLists[iIndex] = new List<Texture>();
                    _textureLists[iIndex].Add(tex.second);
                }
                _showTape = boxProperties.ShowTape;
                _tapeWidth = boxProperties.TapeWidth;
                _tapeColor = boxProperties.TapeColor;
            }

            // set position
            Position = bPosition.Position;
            // set direction length
            LengthAxis = HalfAxis.ToVector3D(bPosition.DirectionLength);
            // set direction width
            WidthAxis = HalfAxis.ToVector3D(bPosition.DirectionWidth);
            // IsBundle ?
            _isBundle = bProperties.IsBundle;
            if (bProperties.IsBundle)
            {
                BundleProperties bundleProp = bProperties as BundleProperties;
                if (null != bundleProp)
                    _noFlats = bundleProp.NoFlats;
            }
        }
Esempio n. 22
0
        /// <summary>
        /// build optimal solutions with 2 layer types
        /// </summary>
        /// <returns></returns>
        private List<CasePalletSolution> GenerateOptimizedCombinationOfLayers()
        {
            List<CasePalletSolution> solutions = new List<CasePalletSolution>();

            // generate best layers
            Layer[] bestLayers = new Layer[3];
            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);

            string[] dir = { "X", "Y", "Z" };
            for (int i = 0; i < 3; ++i)
            {
                HalfAxis.HAxis axisOrtho = (HalfAxis.HAxis)(2 * i + 1);
                HalfAxis.HAxis axis0 = (HalfAxis.HAxis)((2 * (i + 1)) % 6 + 1);
                HalfAxis.HAxis axis1 = (HalfAxis.HAxis)((2 * (i + 2)) % 6 + 1);

                int noLayer0 = 0, noLayer1 = 0;
                if (GetOptimalRequest(
                    _bProperties.Dimension(axis0), bestLayers[i % 3].Count
                    , _bProperties.Dimension(axis1), bestLayers[(i + 1) % 3].Count
                    , out noLayer0, out noLayer1))
                {
                    Layer layer0 = bestLayers[i % 3];
                    Layer layer1 = bestLayers[(i + 1) % 3];

                    // sol0
                    CasePalletSolution sol0 = new CasePalletSolution(null, string.Format("combination_{0}{1}", dir[i % 3], dir[(i % 3) + 1]), false);
                    double zLayer = _palletProperties.Height;
                    double cornerThickness = null != _cornerProperties ? _cornerProperties.Thickness : 0.0;

                    for (int j = 0; j < noLayer0; ++j)
                    {
                        BoxLayer layer = sol0.CreateNewLayer(zLayer, string.Empty);
                        foreach (LayerPosition layerPos in layer0)
                        {
                            LayerPosition layerPosTemp = AdjustLayerPosition(layerPos);
                            BoxPosition boxPos = new BoxPosition(
                                layerPosTemp.Position
                                - 0.5 * _constraintSet.OverhangX * Vector3D.XAxis
                                - 0.5 * _constraintSet.OverhangY * Vector3D.YAxis
                                + zLayer * Vector3D.ZAxis
                                , layerPosTemp.LengthAxis
                                , layerPosTemp.WidthAxis
                                );
                            layer.Add(boxPos);
                        }
                        zLayer += layer0.BoxHeight;
                    }
                    for (int j = 0; j < noLayer1; ++j)
                    {
                        BoxLayer layer = sol0.CreateNewLayer(zLayer, string.Empty);
                        foreach (LayerPosition layerPos in layer1)
                        {
                            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 += layer1.BoxHeight;
                    }
                    solutions.Add(sol0);

                    // sol1
                    CasePalletSolution sol1 = new CasePalletSolution(null, string.Format("combination_{0}{1}", dir[i % 3], dir[(i % 3) + 1]), false);
                    zLayer = _palletProperties.Height;

                    for (int j = 0; j < noLayer0; ++j)
                    {
                        BoxLayer layer = sol1.CreateNewLayer(zLayer, string.Empty);
                        foreach (LayerPosition layerPos in layer1)
                        {
                            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 += layer1.BoxHeight;
                    }
                    for (int j = 0; j < noLayer1; ++j)
                    {
                        BoxLayer layer = sol1.CreateNewLayer(zLayer, string.Empty);
                        foreach (LayerPosition layerPos in layer0)
                        {
                            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 += layer0.BoxHeight;
                    }
                    solutions.Add(sol1);
                }
            }
            return solutions;
        }
Esempio n. 23
0
        public Box(uint pickId, PackProperties packProperties, BoxPosition bPosition)
        {
            if (!bPosition.IsValid)
                throw new GraphicsException("Invalid BoxPosition: can not create box");
            _pickId = pickId;
            _dim[0] = packProperties.Length;
            _dim[1] = packProperties.Width;
            _dim[2] = packProperties.Height;

            _colors = new Color[]
            {
                Color.Chocolate, Color.Chocolate, Color.Chocolate, Color.Chocolate, Color.Chocolate, Color.Chocolate
            };
            // set position
            Position = bPosition.Position;
            // set direction length
            LengthAxis = HalfAxis.ToVector3D(bPosition.DirectionLength);
            // set direction width
            WidthAxis = HalfAxis.ToVector3D(bPosition.DirectionWidth);
        }
Esempio n. 24
0
        public Box(uint pickId, InterlayerProperties interlayerProperties, BoxPosition bPosition)
        {
            _pickId = pickId;
            _dim[0] = interlayerProperties.Length;
            _dim[1] = interlayerProperties.Width;
            _dim[2] = interlayerProperties.Thickness;
            _colors = new Color[6];
            for (int i = 0; i < 6; ++i)
                _colors[i] = interlayerProperties.Color;

            // set position
            Position = bPosition.Position;
            // set direction length
            LengthAxis = HalfAxis.ToVector3D(bPosition.DirectionLength);
            // set direction width
            WidthAxis = HalfAxis.ToVector3D(bPosition.DirectionWidth);
        }
Esempio n. 25
0
 public BoxPosition(BoxPosition bpos)
 {
     Position        = bpos.Position;
     DirectionLength = bpos.DirectionLength;
     DirectionWidth  = bpos.DirectionWidth;
 }
Esempio n. 26
0
        private List<BoxCasePalletSolution> GenerateSolutions()
        {
            List<BoxCasePalletSolution> solutions = new List<BoxCasePalletSolution>();

            // loop through all pallet solutions
            foreach (PalletSolutionDesc desc in _palletSolutionList)
            {
                CasePalletSolution palletSolution = desc.LoadPalletSolution();
                if (null == palletSolution)
                {
                    _log.Warn(string.Format("Failed to load pallet solution "));
                    continue; 
                }
                BoxProperties caseProperties = palletSolution.Analysis.BProperties as BoxProperties;

                // loop through all patterns
                foreach (LayerPattern pattern in LayerPattern.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(_boxProperties, caseProperties, axisOrtho1, swapPos == 1);
                                Layer2D layer2 = BuildLayer(_boxProperties, caseProperties, axisOrtho2, swapPos == 1);
                                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 < 4; ++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";
                                    }

                                    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" : "");

                                    BoxCasePalletSolution sol = new BoxCasePalletSolution(null, title, desc, layer1T == layer2T);
                                    int iLayerIndex = 0;
                                    bool innerLoopStop = false;
                                    double offsetX = 0.5 * (caseProperties.Length - caseProperties.InsideLength);
                                    double offsetY = 0.5 * (caseProperties.Width - caseProperties.InsideWidth);
                                    double zLayer = 0.5 * (caseProperties.Height - caseProperties.InsideHeight);
                                    int iInterlayer = 0;
                                    int boxCount = 0;

                                    while (
                                        !innerLoopStop
                                        &&
                                        ((zLayer + _boxProperties.Dimension(axisOrtho1) < caseProperties.InsideHeight))
                                        )
                                    {
                                        if (_constraintSet.HasInterlayer)
                                        {
                                            if (iInterlayer >= _constraintSet.InterlayerPeriod)
                                            {
                                                InterlayerPos interlayerPos = sol.CreateNewInterlayer(zLayer, 0);
                                                zLayer += _interlayerProperties.Thickness;
                                                iInterlayer = 0;
                                            }
                                            ++iInterlayer;
                                        }

                                        // select current layer type
                                        Layer2D currentLayer = iLayerIndex % 2 == 0 ? layer1T : layer2T;
                                        BoxLayer layer = sol.CreateNewLayer(zLayer, 0);

                                        foreach (LayerPosition layerPos in currentLayer)
                                        {
                                            int iCount = sol.Count + 1;
                                            innerLoopStop = (_constraintSet.UseMaximumCaseWeight && ((boxCount+1) * _boxProperties.Weight + caseProperties.Weight > _constraintSet.MaximumCaseWeight))
                                            || (_constraintSet.UseMaximumNumberOfItems && ((boxCount+1) > _constraintSet.MaximumNumberOfItems));

                                            if (!innerLoopStop)
                                            {
                                                BoxPosition boxPos = new BoxPosition(
                                                    layerPos.Position
                                                    + offsetX * Vector3D.XAxis
                                                    + offsetY * Vector3D.YAxis
                                                    + zLayer * Vector3D.ZAxis
                                                    , layerPos.LengthAxis
                                                    , layerPos.WidthAxis
                                                    );
                                                layer.Add(boxPos);
                                                ++boxCount;
                                            }
                                            else
                                                break;
                                        }

                                        // increment layer index
                                        ++iLayerIndex;
                                        zLayer += currentLayer.BoxHeight;
                                    }
                                    // insert solution
                                    if (
                                        sol.Count > 0
                                        && (!_constraintSet.UseMinimumNumberOfItems || sol.Count >=_constraintSet.MinimumNumberOfItems)
                                        )
                                        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
            }// loop through all pallet solutions
            // sort solutions
            solutions.Sort();
            // return list of solutions
            return solutions;
        }
Esempio n. 27
0
        private List<BoxCaseSolution> GenerateSolutions()
        {
            List<BoxCaseSolution> solutions = new List<BoxCaseSolution>();

            int[] patternColumnCount = new int[6];
            // loop throw all patterns
            foreach (LayerPattern pattern in LayerPattern.All)
            {
                // loop through all vertical axes
                for (int i = 0; i < 6; ++i)
                {
                    HalfAxis.HAxis axisOrtho = (HalfAxis.HAxis)i;
                    if (!_constraintSet.AllowOrthoAxis(axisOrtho))
                        continue;
                    try
                    {
                        // build layer
                        Layer2D layer = BuildLayer(_bProperties, _caseProperties, axisOrtho, false);
                        double actualLength = 0.0, actualWidth = 0.0;
                        if (!pattern.GetLayerDimensionsChecked(layer, out actualLength, out actualWidth))
                            continue;
                        pattern.GenerateLayer(layer, actualLength, actualWidth);

                        string title = string.Empty;
                        BoxCaseSolution sol = new BoxCaseSolution(null, axisOrtho, pattern.Name);
                        double offsetX = 0.5 * (_caseProperties.Length - _caseProperties.InsideLength);
                        double offsetY = 0.5 * (_caseProperties.Width - _caseProperties.InsideWidth);
                        double zLayer = 0.5 * (_caseProperties.Height - _caseProperties.InsideHeight);
                        bool maxWeightReached = _constraintSet.UseMaximumCaseWeight && (_caseProperties.Weight + _bProperties.Weight > _constraintSet.MaximumCaseWeight);
                        bool maxHeightReached = _bProperties.Dimension(axisOrtho) > _caseProperties.InsideHeight;
                        bool maxNumberReached = false;
                        int boxCount = 0;

                        while (!maxWeightReached && !maxHeightReached && !maxNumberReached)
                        {
                            BoxLayer bLayer = sol.CreateNewLayer(zLayer, 0);

                            foreach (LayerPosition layerPos in layer)
                            {
                                // increment
                                ++boxCount;
                                if (maxNumberReached = _constraintSet.UseMaximumNumberOfBoxes && (boxCount > _constraintSet.MaximumNumberOfBoxes))
                                    break;

                                double weight = _caseProperties.Weight + boxCount * _bProperties.Weight;
                                maxWeightReached = _constraintSet.UseMaximumCaseWeight && weight >  _constraintSet.MaximumCaseWeight;
                                if (maxWeightReached)
                                    break;
                                // insert new box in current layer
                                LayerPosition layerPosTemp = AdjustLayerPosition(layerPos);
                                BoxPosition boxPos = new BoxPosition(
                                    layerPosTemp.Position
                                    + offsetX * Vector3D.XAxis
                                    + offsetY * Vector3D.YAxis
                                    + zLayer * Vector3D.ZAxis
                                    , layerPosTemp.LengthAxis
                                    , layerPosTemp.WidthAxis
                                    );
                                bLayer.Add(boxPos);
                            }
                            zLayer += layer.BoxHeight;
                            if (!maxWeightReached && !maxNumberReached)
                                maxHeightReached = zLayer + layer.BoxHeight > 0.5 * (_caseProperties.Height + _caseProperties.InsideHeight);
                        }
                        // set maximum criterion
                        if (maxNumberReached) sol.LimitReached = BoxCaseSolution.Limit.LIMIT_MAXNUMBERREACHED;
                        else if (maxWeightReached) sol.LimitReached = BoxCaseSolution.Limit.LIMIT_MAXWEIGHTREACHED;
                        else if (maxHeightReached) sol.LimitReached = BoxCaseSolution.Limit.LIMIT_MAXHEIGHTREACHED;

                        if (string.Equals(pattern.Name, "Column", StringComparison.CurrentCultureIgnoreCase))
                            patternColumnCount[i] = Math.Max(patternColumnCount[i], sol.BoxPerCaseCount);

                        // insert solution
                        if (sol.BoxPerCaseCount >= patternColumnCount[i])
                            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 patterns

            // sort solutions
            solutions.Sort();
            /*
            // removes solutions that do not equal the best number
            if (solutions.Count > 0)
            {
                int indexFrom = 0, maxCount = solutions[0].BoxPerCaseCount;
                while (indexFrom < solutions.Count && solutions[indexFrom].BoxPerCaseCount == maxCount)
                    ++indexFrom;
                solutions.RemoveRange(indexFrom, solutions.Count - indexFrom);
            }
            */ 
            return solutions;        
        }