public override bool GetLayerDimensions(Layer2D layer, out double actualLength, out double actualWidth)
        {
            double boxLength = layer.BoxLength;
            double boxWidth = layer.BoxWidth;
            double palletLength = GetPalletLength(layer);
            double palletWidth = GetPalletWidth(layer);

            // compute optimal layout by evaluating all spirale configurations
            int sizeX_area1 = 0, sizeY_area1 = 0, sizeX_area2 = 0, sizeY_area2 = 0;
            GetOptimalSizesXY(boxLength, boxWidth, palletLength, palletWidth
                , out sizeX_area1, out sizeY_area1, out sizeX_area2, out sizeY_area2);

            // actual length / actual width
            actualLength = sizeX_area1 * boxLength + sizeX_area2 * boxWidth;
            actualWidth = sizeY_area1 * boxWidth + sizeY_area2 * boxLength;
            if (2.0 * sizeX_area1 * boxLength > palletLength
                && 2.0 * sizeY_area1 * boxWidth > actualWidth)
                actualWidth = 2.0 * sizeY_area1 * boxWidth;
            else if (2.0 * sizeY_area1 * boxWidth > palletWidth
                && 2.0 * sizeX_area1 * boxLength > actualLength)
                actualLength = 2.0 * sizeX_area1 * boxLength;
            else if (2.0 * sizeX_area2 * boxWidth > palletLength
                && 2.0 * sizeY_area2 * boxLength > actualWidth)
                actualWidth = 2.0 * sizeY_area2 * boxLength;
            else if (2.0 * sizeY_area2 * boxLength > palletWidth
                && 2.0 * sizeX_area2 * boxWidth > actualLength)
                actualLength = 2.0 * sizeX_area2 * boxWidth;

            return sizeX_area1 > 0 && sizeX_area2 > 0 && sizeY_area1 > 0 && sizeY_area2 > 0;
        }
Esempio n. 2
0
        public override void GenerateLayer(Layer2D layer, double actualLength, double actualWidth)
        {
            layer.Clear();

            double boxLength = layer.BoxLength;
            double boxWidth = layer.BoxWidth;
            double palletLength = GetPalletLength(layer);
            double palletWidth = GetPalletWidth(layer);

            int sizeX = (int)Math.Floor(palletLength / boxLength);
            int sizeY = (int)Math.Floor(palletWidth / boxWidth);

            double offsetX = 0.5 * (palletLength - actualLength);
            double offsetY = 0.5 * (palletWidth - actualWidth);

            double spaceX = sizeX > 1 ? (actualLength - sizeX * boxLength) / (sizeX - 1) : 0.0;
            double spaceY = sizeY > 1 ? (actualWidth - sizeY * boxWidth) / (sizeY - 1) : 0.0;

            for (int i = 0; i < sizeX; ++i)
                for (int j = 0; j < sizeY; ++j)
                    AddPosition(layer
                        , new Vector2D(
                            offsetX + i * (boxLength + spaceX)
                            , offsetY + j * (boxWidth + spaceY)
                            )
                        , HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Y_P);
            // set spacing to ZERO i.e. no spacing with column layout
            layer.UpdateMaxSpace(spaceX);
            layer.UpdateMaxSpace(spaceY);
        }
        public override bool GetLayerDimensions(Layer2D layer, out double actualLength, out double actualWidth)
        {
            double boxLength = layer.BoxLength;
            double boxWidth = layer.BoxWidth;
            double palletLength = GetPalletLength(layer);
            double palletWidth = GetPalletWidth(layer);

            // compute optimal layout
            int sizeX_area1 = 0, sizeY_area1 = 0
                , sizeX_area2 = 0, sizeY_area2 = 0
                , sizeX_area3 = 0, sizeY_area3 = 0
                , dir_area3 = 0;

            GetOptimalSizesXY(
            boxLength, boxWidth, palletLength, palletWidth
            , out sizeX_area1, out sizeY_area1
            , out sizeX_area2, out sizeY_area2
            , out sizeX_area3, out sizeY_area3
            , out dir_area3);

            actualLength = sizeX_area1 * boxLength + sizeX_area2 * boxWidth;
            actualWidth = sizeY_area1 * boxWidth + sizeY_area2 * boxLength;

            if (2.0 * sizeX_area2 * boxWidth + sizeX_area3 * ((dir_area3 == 0) ? boxLength : boxWidth) > actualLength)
                actualLength = 2.0 * sizeX_area2 * boxWidth + sizeX_area3 * ((dir_area3 == 0) ? boxLength : boxWidth);
            if (2.0 * sizeY_area1 * boxWidth + sizeY_area3 * ((dir_area3 == 0) ? boxWidth : boxLength) > actualWidth)
                actualWidth = 2.0 * sizeY_area1 * boxWidth + sizeY_area3 * ((dir_area3 == 0) ? boxWidth : boxLength);

            return sizeX_area1 > 0 && sizeY_area1 > 0
                && sizeX_area2 > 0 && sizeY_area2 > 0;
        }
Esempio n. 4
0
 public static Bitmap Draw(Layer2D layer, BProperties bProperties, double height, Size size, bool selected)
 {
     Graphics2DImage graphics = new Graphics2DImage(size);
     using (SolutionViewerLayer solViewer = new SolutionViewerLayer(layer))
     {   solViewer.Draw(graphics, bProperties, height, selected); }
     return graphics.Bitmap;
 }
Esempio n. 5
0
 protected double GetPalletWidth(Layer2D layer)
 { 
     if (!layer.Swapped)
         return layer.PalletWidth;
     else
         return layer.PalletLength;        
 }
Esempio n. 6
0
        public List<Layer2D> BuildLayers(Vector3D dimBox, Vector2D dimContainer, ConstraintSetAbstract constraintSet, bool keepOnlyBest)
        {
            // instantiate list of layers
            List<Layer2D> listLayers0 = new List<Layer2D>();

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

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

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

            return listLayers0;
        }
Esempio n. 7
0
 public bool GetLayerDimensionsChecked(Layer2D layer, out double actualLength, out double actualWidth)
 {
     bool result = GetLayerDimensions(layer, out actualLength, out actualWidth);
     if (actualLength > GetPalletLength(layer))
         throw new EngineException(string.Format("Pattern name={0} : actualLength={1} > palletLength={2} ?"
             , this.Name, actualLength, GetPalletLength(layer)));
     if (actualWidth > GetPalletWidth(layer))
         throw new EngineException(string.Format("Pattern name={0} : actualWidth={1} > palletWidth={2} ?"
             , this.Name, actualWidth, GetPalletWidth(layer)));
     return result;
 }
Esempio n. 8
0
        public override bool GetLayerDimensions(Layer2D layer, out double actualLength, out double actualWidth)
        {
            double palletLength = layer.PalletLength;
            double palletWidth = layer.PalletWidth;
            double boxLength = layer.BoxLength;
            double boxWidth = layer.BoxWidth;
            actualLength = Math.Floor(palletLength / boxLength) * boxLength;
            actualWidth = Math.Floor(palletWidth / boxWidth) * boxWidth;

            return (palletLength >= boxLength) && (palletWidth >= boxWidth);
        }
Esempio n. 9
0
        public void AddPosition(Layer2D layer, Vector2D vPosition, HalfAxis.HAxis lengthAxis, HalfAxis.HAxis widthAxis)
        {
            Matrix4D matRot = Matrix4D.Identity;
            Vector3D vTranslation = Vector3D.Zero;

            if (layer.Swapped && !layer.Inversed)
            {
                matRot = new Matrix4D(
                    0.0, -1.0, 0.0, 0.0
                    , 1.0, 0.0, 0.0, 0.0
                    , 0.0, 0.0, 1.0, 0.0
                    , 0.0, 0.0, 0.0, 1.0
                    );
                vTranslation = new Vector3D(layer.PalletLength, 0.0, 0.0);
            }
            else if (!layer.Swapped && layer.Inversed)
            {
                matRot = new Matrix4D(
                    -1.0, 0.0, 0.0, 0.0
                    , 0.0, -1.0, 0.0, 0.0
                    , 0.0, 0.0, 1.0, 0.0
                    , 0.0, 0.0, 0.0, 1.0
                    );
                vTranslation = new Vector3D(layer.PalletLength, layer.PalletWidth, 0.0);
            }
            else if (layer.Swapped && layer.Inversed)
            {
                matRot = new Matrix4D(
                    0.0, 1.0, 0.0, 0.0
                    , -1.0, 0.0, 0.0, 0.0
                    , 0.0, 0.0, 1.0, 0.0
                    , 0.0, 0.0, 0.0, 1.0
                    );
                vTranslation = new Vector3D(0.0, layer.PalletWidth, 0.0);
            }
            Transform3D transfRot = new Transform3D(matRot);
            HalfAxis.HAxis lengthAxisSwapped = StackBuilder.Basics.HalfAxis.ToHalfAxis(transfRot.transform(StackBuilder.Basics.HalfAxis.ToVector3D(lengthAxis)));
            HalfAxis.HAxis widthAxisSwapped = StackBuilder.Basics.HalfAxis.ToHalfAxis(transfRot.transform(StackBuilder.Basics.HalfAxis.ToVector3D(widthAxis)));

            matRot.M14 = vTranslation[0];
            matRot.M24 = vTranslation[1];
            matRot.M34 = vTranslation[2];

            Transform3D transfRotTranslation = new Transform3D(matRot);
            Vector3D vPositionSwapped = transfRotTranslation.transform(new Vector3D(vPosition.X, vPosition.Y, 0.0));

            if (!layer.IsValidPosition(new Vector2D(vPositionSwapped.X, vPositionSwapped.Y), lengthAxisSwapped, widthAxisSwapped))
            {
                _log.Warn(string.Format("Attempt to add an invalid position in pattern = {0}, Swapped = {1}", this.Name, layer.Swapped));
                return;
            }
            layer.AddPosition(new Vector2D(vPositionSwapped.X, vPositionSwapped.Y), lengthAxisSwapped, widthAxisSwapped);
        }
Esempio n. 10
0
        public override void GenerateLayer(Layer2D layer, double actualLength, double actualWidth)
        {
            // initialization
            layer.Clear();

            double boxLength = layer.BoxLength;
            double boxWidth = layer.BoxWidth;
            double palletLength = GetPalletLength(layer);
            double palletWidth = GetPalletWidth(layer);

            // compute optimal layout by evaluating all spirale configurations
            int sizeX_area1 = 0, sizeY_area1 = 0, sizeX_area2 = 0, sizeY_area2 = 0;
            GetOptimalSizesXY(boxLength, boxWidth, palletLength, palletWidth
                , out sizeX_area1, out sizeY_area1, out sizeX_area2, out sizeY_area2);

            // compute offsets
            double offsetX = 0.5 * (palletLength - actualLength);
            double offsetY = 0.5 * (palletWidth - actualWidth);

            // area1
            for (int i=0; i<sizeX_area1; ++i)
                for (int j = 0; j<sizeY_area1; ++j)
                {
                    AddPosition(layer
                        , new Vector2D(offsetX + i * boxLength, offsetY + j * boxWidth)
                        , HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Y_P);
                    AddPosition(layer
                        , new Vector2D(palletLength - offsetX - i * boxLength, palletWidth - offsetY - j * boxWidth)
                        , HalfAxis.HAxis.AXIS_X_N, HalfAxis.HAxis.AXIS_Y_N);
                }
            double spaceX_Area1 = actualLength - 2.0 * sizeX_area1 * boxLength;
            double spaceY_Area1 = actualWidth - 2.0 * sizeY_area1 * boxWidth;

            // area2
            for (int i=0; i<sizeX_area2; ++i)
                for (int j = 0; j<sizeY_area2; ++j)
                {
                    AddPosition(layer
                        , new Vector2D(palletLength - offsetX - i * boxWidth, offsetY + j * boxLength)
                        , HalfAxis.HAxis.AXIS_Y_P, HalfAxis.HAxis.AXIS_X_N);
                    AddPosition(layer
                        , new Vector2D(offsetX + i * boxWidth, palletWidth - offsetY - j * boxLength)
                        , HalfAxis.HAxis.AXIS_Y_N, HalfAxis.HAxis.AXIS_X_P);
                }

            double spaceX_Area2 = actualLength - 2.0 * sizeX_area2 * boxWidth;
            double spaceY_Area2 = actualWidth - 2.0 * sizeY_area2 * boxLength;
            double spaceX = spaceX_Area1 > 0 ? spaceX_Area1 : spaceX_Area2;
            double spaceY = spaceY_Area1 > 0 ? spaceY_Area1 : spaceY_Area2;

            layer.UpdateMaxSpace( Math.Min(spaceX, spaceY) );
        }
Esempio n. 11
0
 /// ランダムな座標を取得する.
 Point2 GetRandomPosition(Layer2D layer)
 {
     Point2 p;
     while(true) {
         p.x = Random.Range(0, layer.Width);
         p.y = Random.Range(0, layer.Height);
         if(layer.Get(p.x, p.y) == 1) {
             // 通過可能
             break;
         }
     }
     return p;
 }
Esempio n. 12
0
 public Layer2D BuildLayer(Vector3D dimBox, Vector2D dimContainer, LayerDesc layerDesc)
 {
     // instantiate layer
     Layer2D layer = new Layer2D(dimBox, dimContainer, layerDesc.AxisOrtho, false);
     // get layer pattern
     LayerPattern pattern = LayerPattern.GetByName(layerDesc.PatternName);
     // dimensions
     double actualLength = 0.0, actualWidth = 0.0;
     if (!pattern.GetLayerDimensionsChecked(layer, out actualLength, out actualWidth))
         return null;
     pattern.GenerateLayer(layer, actualLength, actualWidth);
     return layer;
 }
        public override void GenerateLayer(Layer2D layer, double actualLength, double actualWidth)
        {
            layer.Clear();

            double boxLength = layer.BoxLength;
            double boxWidth = layer.BoxWidth;
            double palletLength = GetPalletLength(layer);
            double palletWidth = GetPalletWidth(layer);

            int maxSizeXLength = 0, maxSizeXWidth = 0, maxSizeYLength = 0, maxSizeYWidth = 0;
            GetSizeXY(boxLength, boxWidth, palletLength, palletWidth
                , out maxSizeXLength, out maxSizeXWidth, out maxSizeYLength, out maxSizeYWidth);

            double offsetX = 0.5 * (palletLength - actualLength);
            double offsetY = 0.5 * (palletWidth - actualWidth);

            double spaceX = maxSizeXLength + maxSizeXWidth > 1 ? (actualLength - (maxSizeXLength * boxLength + maxSizeXWidth * boxWidth)) / (maxSizeXLength + maxSizeXWidth - 1) : 0.0;
            double spaceYLength = maxSizeYLength > 1 ? (actualWidth - maxSizeYLength * boxWidth) / (maxSizeYLength - 1) : 0.0;
            double spaceYWidth = maxSizeYWidth > 1 ? (actualWidth - maxSizeYWidth * boxLength) / (maxSizeYWidth - 1) : 0.0;

            for (int i = 0; i < maxSizeXLength/2; ++i)
                for (int j = 0; j < maxSizeYLength; ++j)
                {
                    AddPosition(
                        layer
                        , new Vector2D(
                            offsetX + i * (boxLength + spaceX)
                            , offsetY + j * (boxWidth + spaceYLength))
                        , HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Y_P);

                    AddPosition(
                        layer
                        , new Vector2D(
                            palletLength - offsetX - i * (boxLength + spaceX)
                            , palletWidth - offsetY - j * (boxWidth + spaceYLength))
                        , HalfAxis.HAxis.AXIS_X_N, HalfAxis.HAxis.AXIS_Y_N);
                }
            for (int i = 0; i < maxSizeXWidth; ++i)
                for (int j = 0; j < maxSizeYWidth; ++j)
                    AddPosition(
                        layer
                        , new Vector2D(
                            offsetX + maxSizeXLength/2 * (boxLength + spaceX) + i * (boxWidth + spaceX) + boxWidth
                            , offsetY + j * (boxLength + spaceYWidth))
                        , HalfAxis.HAxis.AXIS_Y_P, HalfAxis.HAxis.AXIS_X_N);

            layer.UpdateMaxSpace(spaceX);
            layer.UpdateMaxSpace(spaceYLength);
            layer.UpdateMaxSpace(spaceYWidth);
        }
Esempio n. 14
0
    // レベルデータを読み込む
    public void Load(string fLevel)
    {
        // レイヤー生成.
        _layer = new Layer2D();
        // レベルデータ取得.
        TextAsset tmx = Resources.Load(fLevel) as TextAsset;

        // XML解析開始.
        XmlDocument xmlDoc = new XmlDocument();
        xmlDoc.LoadXml(tmx.text);
        XmlNodeList mapList = xmlDoc.GetElementsByTagName("map");
        foreach (XmlNode map in mapList)
        {
          XmlNodeList childList = map.ChildNodes;
          foreach (XmlNode child in childList)
          {
        if (child.Name != "layer") { continue; } // layerノード以外は見ない.

        // マップ属性を取得.
        XmlAttributeCollection attrs = child.Attributes;
        int w = int.Parse(attrs.GetNamedItem("width").Value); // 幅を取得.
        int h = int.Parse(attrs.GetNamedItem("height").Value); // 高さを取得.
        // レイヤー生成.
        _layer.Create(w, h);
        XmlNode node = child.FirstChild; // 子ノードは<data>のみ.
        XmlNode n = node.FirstChild; // テキストノードを取得.
        string val = n.Value; // テキストを取得.
        // CSV(マップデータ)を解析.
        int y = 0;
        foreach (string line in val.Split('\n'))
        {
          // 空白文字を削除
          var line2 = line.Trim();
          if (line2 == "") { continue; } // 空文字は除外.
          int x = 0;
          foreach (string s in line2.Split(','))
          {
            int v = 0;
            // ","で終わるのでチェックが必要.
            if (int.TryParse(s, out v) == false) { continue; }
            // 値を設定.
            _layer.Set(x, y, v);
            x++;
          }
          y++;
        }
          }
        }
    }
        public override bool GetLayerDimensions(Layer2D layer, out double actualLength, out double actualWidth)
        {
            double boxLength = layer.BoxLength;
            double boxWidth = layer.BoxWidth;
            double palletLength = GetPalletLength(layer);
            double palletWidth = GetPalletWidth(layer);

            int maxSizeXLength = 0, maxSizeXWidth = 0, maxSizeYLength = 0, maxSizeYWidth = 0;
            GetSizeXY(boxLength, boxWidth, palletLength, palletWidth
                , out maxSizeXLength, out maxSizeXWidth, out maxSizeYLength, out maxSizeYWidth);

            actualLength = maxSizeXLength * boxLength + maxSizeXWidth * boxWidth;
            actualWidth = Math.Max(maxSizeYLength * boxWidth, maxSizeYWidth * boxLength);

            return maxSizeXLength > 0 && maxSizeXWidth > 0 && maxSizeYLength > 0 && maxSizeYWidth > 0 && (maxSizeXLength % 2 == 0);
        }
        protected override void OnStart()
        {
            var scene = new Scene();
            var layer = new Layer2D();
            var obj   = new TextureObject2D();

            camera = new CameraObject2D();

            obj.Texture = Engine.Graphics.CreateTexture2D("Data/Texture/Sample1.png");
            camera.Src  = new RectI(100, 100, 312, 312);
            camera.Dst  = new RectI(10, 10, 200, 160);

            layer.AddObject(obj);
            layer.AddObject(camera);
            scene.AddLayer(layer);
            Engine.ChangeScene(scene);
        }
Esempio n. 17
0
        protected override void OnStart()
        {
            var scene = new Scene();
            var layer = new Layer2D();

            obj = new TextureObject2D()
            {
                Texture        = Engine.Graphics.CreateTexture2D("Data/Texture/Cloud1.png"),
                Position       = new Vector2DF(320, 240),
                Angle          = 5,
                CenterPosition = new Vector2DF(128, 128),
            };

            layer.AddObject(obj);
            scene.AddLayer(layer);
            Engine.ChangeScene(scene);
        }
Esempio n. 18
0
        /// <summary>
        /// Used to compute load dimension
        /// </summary>
        public bool GetDimensions(List <LayerDesc> layers, Packable packable, Vector2D dimContainer, out Vector2D actualDimensions)
        {
            actualDimensions = new Vector2D();
            foreach (LayerDesc layerDesc in layers)
            {
                // dimensions
                double actualLength = 0.0, actualWidth = 0.0;

                if (packable.IsBrick)
                {
                    LayerDescBox layerDescBox = layerDesc as LayerDescBox;
                    // instantiate layer
                    var layer = new Layer2D(packable.OuterDimensions, dimContainer, layerDescBox.AxisOrtho, layerDesc.Swapped);
                    // get layer pattern
                    LayerPatternBox pattern = LayerPatternBox.GetByName(layerDesc.PatternName);
                    // dimensions
                    if (!pattern.GetLayerDimensionsChecked(layer, out actualLength, out actualWidth))
                    {
                        _log.Error(string.Format("Failed to get layer dimension : {0}", pattern.Name));
                        break;
                    }
                }
                else if (packable.IsCylinder)
                {
                    CylinderProperties cylProp = packable as CylinderProperties;
                    // instantiate layer
                    var layer = new Layer2DCyl(cylProp.RadiusOuter, cylProp.Height, dimContainer, layerDesc.Swapped);
                    // get layer pattern
                    LayerPatternCyl pattern = LayerPatternCyl.GetByName(layerDesc.PatternName);
                    // dimensions
                    if (!pattern.GetLayerDimensions(layer, out actualLength, out actualWidth))
                    {
                        _log.Error(string.Format("Failed to get layer dimension : {0}", pattern.Name));
                        break;
                    }
                }
                else
                {
                    throw new EngineException(string.Format("Unexpected packable {0} (Type = {1})", packable.Name, packable.GetType().ToString()));
                }

                actualDimensions.X = Math.Max(actualDimensions.X, layerDesc.Swapped ? actualWidth : actualLength);
                actualDimensions.Y = Math.Max(actualDimensions.Y, layerDesc.Swapped ? actualLength : actualWidth);
            }
            return(true);
        }
        public override bool GetLayerDimensions(Layer2D layer, out double actualLength, out double actualWidth)
        {
            double boxLength    = layer.BoxLength;
            double boxWidth     = layer.BoxWidth;
            double palletLength = GetPalletLength(layer);
            double palletWidth  = GetPalletWidth(layer);

            int maxSizeXLength = 0, maxSizeXWidth = 0, maxSizeYLength = 0, maxSizeYWidth = 0;

            GetSizeXY(boxLength, boxWidth, palletLength, palletWidth
                      , out maxSizeXLength, out maxSizeXWidth, out maxSizeYLength, out maxSizeYWidth);

            actualLength = maxSizeXLength * boxLength + maxSizeXWidth * boxWidth;
            actualWidth  = Math.Max(maxSizeYLength * boxWidth, maxSizeYWidth * boxLength);

            return(maxSizeXLength > 0 && maxSizeYLength > 0 && maxSizeXWidth > 0 && maxSizeYWidth > 0);
        }
Esempio n. 20
0
        protected override void OnStart()
        {
            var obj1 = new CollidingObject1();

            obj1.Position = new Vector2DF(320, 240);
            var obj2 = new CollidingObject2();

            obj2.Position = new Vector2DF(600, 20);

            var scene = new Scene();
            var layer = new Layer2D();

            Engine.ChangeScene(scene);
            scene.AddLayer(layer);
            layer.AddObject(obj1);
            layer.AddObject(obj2);
        }
Esempio n. 21
0
        protected override void OnStart()
        {
            var scene            = new Scene();
            var layer            = new Layer2D();
            var obj              = new MyObject(100, 128);
            var notDrawnObject   = new MyObject(300, 128);
            var notUpdatedObject = new MyObject(500, 128);

            notDrawnObject.IsDrawn     = false;
            notUpdatedObject.IsUpdated = false;

            layer.AddObject(obj);
            layer.AddObject(notDrawnObject);
            layer.AddObject(notUpdatedObject);
            scene.AddLayer(layer);
            Engine.ChangeScene(scene);
        }
Esempio n. 22
0
        public ILayer2D BuildLayer(Packable packable, Vector2D dimContainer, LayerDesc layerDesc, double minSpace)
        {
            ILayer2D layer = null;

            if (packable.IsBrick)
            {
                // casts
                LayerDescBox layerDescBox = layerDesc as LayerDescBox;
                // layer instantiation
                layer = new Layer2D(packable.OuterDimensions, dimContainer, layerDesc.PatternName, layerDescBox.AxisOrtho, layerDesc.Swapped)
                {
                    ForcedSpace = minSpace
                };
                // get layer pattern
                LayerPatternBox pattern = LayerPatternBox.GetByName(layerDesc.PatternName);
                // dimensions
                if (!pattern.GetLayerDimensionsChecked(layer as Layer2D, out double actualLength, out double actualWidth))
                {
                    return(null);
                }
                pattern.GenerateLayer(
                    layer as Layer2D
                    , actualLength
                    , actualWidth);
                return(layer);
            }
            else if (packable.IsCylinder)
            {
                // casts
                CylinderProperties cylProperties = packable as CylinderProperties;
                // layer instantiation
                layer = new Layer2DCyl(cylProperties.RadiusOuter, cylProperties.Height, dimContainer, layerDesc.Swapped);
                // get layer pattern
                LayerPatternCyl pattern = LayerPatternCyl.GetByName(layerDesc.PatternName);
                if (!pattern.GetLayerDimensions(layer as Layer2DCyl, out double actualLength, out double actualWidth))
                {
                    return(null);
                }
                pattern.GenerateLayer(layer as Layer2DCyl, actualLength, actualWidth);
            }
            else
            {
                throw new EngineException(string.Format("Unexpected packable {0} (Type = {1})", packable.Name, packable.GetType().ToString()));
            }
            return(layer);
        }
Esempio n. 23
0
        protected override void OnStart()
        {
            var scene = new Scene();
            var layer = new Layer2D();
            var obj   = new TextureObject2D()
            {
                Texture = Engine.Graphics.CreateTexture2D("Data/Texture/Sample1.png"),
            };

            obj.Scale = new Vector2DF(2.0f, 2.0f);

            layer.AddObject(obj);
            layer.AddPostEffect(new PostEffect(Engine.Graphics));
            scene.AddLayer(layer);

            Engine.ChangeScene(scene);
        }
Esempio n. 24
0
        protected override void OnRegistered()
        {
            Layer2D back   = new Layer2D();
            Layer2D text   = new Layer2D();
            Layer2D window = new Layer2D();

            // 背景を設定する
            back.AddPostEffect(
                new Background(
                    new Vector3DF(0.0f, 0.4f, 1.0f),
                    new Vector3DF(0.4f, 0.7f, 1.0f)
                    )
                );

            // テキストの中心座標をオブジェクトの中心にする
            Vector2DF center = new Vector2DF(0.5f, 0.5f);

            // 「ENTRY」
            AGText title = new AGText(72, 4, center);

            title.SetText("ENTRY");
            title.Position = new Vector2DF(640, 70);
            text.AddObject(title);

            // 「コントローラーを登録します。準備ができたらスタートボタンを長押ししてください。」
            AGText announce = new AGText(36, 4, center);

            announce.SetText("コントローラーを登録します。\n準備ができたらスタートボタンを長押ししてください。");
            announce.Position = new Vector2DF(640, 720);
            text.AddObject(announce);

            // ウィンドウを追加する
            for (int i = 1; i <= 4; ++i)
            {
                window.AddObject(new EntryWindow(i)
                {
                    NoisyValue = 0.025f
                });
            }

            // レイヤーを追加する
            AddLayer(back);
            AddLayer(text);
            AddLayer(window);
        }
Esempio n. 25
0
    // レベルデータを読み込む
    void Start()
    {
        // レイヤー生成
        Layer2D layer = new Layer2D();
        // レベルデータ取得
        TextAsset tmx = Resources.Load ("Levels/test2") as TextAsset;

        // XML解析開始
        XmlDocument xmlDoc = new XmlDocument();
        xmlDoc.LoadXml (tmx.text);
        XmlNodeList mapList = xmlDoc.GetElementsByTagName("map");
        foreach(XmlNode map in mapList) {
            XmlNodeList childList = map.ChildNodes;
            foreach(XmlNode child in childList) {
                if(child.Name != "layer") { continue; } // layerノード以外は見ない

                // マップ属性を取得
                XmlAttributeCollection attrs = child.Attributes;
                int w = int.Parse(attrs.GetNamedItem("width").Value); // 幅を取得
                int h = int.Parse(attrs.GetNamedItem("height").Value); // 高さを取得
                // レイヤー生成
                layer.Create(w, h);
                XmlNode node = child.FirstChild; // 子ノードは<data>のみ
                XmlNode n = node.FirstChild; // テキストノードを取得
                string val = n.Value; // テキストを取得
                // CSV(マップデータ)を解析
                int y = 0;
                foreach(string line in val.Split('\n')) {
                    int x = 0;
                    foreach(string s in line.Split(',')) {
                        int v = 0;
                        // ","で終わるのでチェックが必要
                        if(int.TryParse(s, out v) == false) { continue; }
                        // 値を設定
                        layer.Set (x, y, v);
                        x++;
                    }
                    y++;
                }
            }
        }

        // デバッグ出力
        layer.Dump();
    }
Esempio n. 26
0
    /// <summary>
    /// タイルを設置
    /// </summary>
    /// <param name="floor">Floor.</param>
    private void Setblock(Layer2D floor, int start, int goal)
    {
        GameObject obj;
        float      stock = 0;

        for (int i = 0; i < floor.Width; i++)
        {
            for (int j = 0; j < floor.Height; j++)
            {
                if (floor.Get(i, j) == WALL)
                {
                    stock++;
                    // 壁生成
                    if (floor.Get(i, j + 1) <= NONE || j == floor.Height - 2)
                    {
                        obj = (GameObject)Instantiate(block, new Vector2(i, j - stock / 2 + 0.5f), new Quaternion());
                        obj.transform.localScale = new Vector2(1, stock);
                        obj.transform.parent     = gameObject.transform;
                        stock = 0;
                        obj.transform.SetAsFirstSibling();
                    }

                    // 左右のつなぎ目を埋める
                    int right = 0;
                    int left  = 0;
                    if (floor.Get(i + 1, j) != NONE)
                    {
                        right = 1;
                    }
                    if (floor.Get(i - 1, j) != NONE)
                    {
                        left = 1;
                    }
                    if (right == 0 && left == 0)
                    {
                        break;
                    }
                    obj = (GameObject)Instantiate(block, new Vector2(i + (right - left) * 0.5f, j), new Quaternion());
                    obj.transform.localScale = new Vector2(right + left, 1);
                    obj.transform.parent     = gameObject.transform;
                    obj.transform.SetAsFirstSibling();
                }
            }
        }
    }
Esempio n. 27
0
        protected override void OnStart()
        {
            var scene = new Scene();
            var layer = new Layer2D();

            textObjects = new List <TextObject2D>();
            for (int i = 0; i < 8; ++i)
            {
                var text = new TextObject2D();
                text.Font     = Engine.Graphics.CreateDynamicFont("", 32, new Color(255, 0, 0, 255), 0, new Color(0, 0, 0, 0));
                text.Position = new Vector2DF(40, 40 + 50 * i);
                textObjects.Add(text);
                layer.AddObject(text);
            }

            scene.AddLayer(layer);
            asd.Engine.ChangeScene(scene);
        }
        private static Bitmap Regenerate2DImageForLayer(Layer2D l, int width, int height)
        {
            Bitmap   b = new Bitmap(width, height);
            Graphics g = Graphics.FromImage(b);

            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit;
            Dictionary <int, LayerColor> colors = l.GetLayerColors();

            int[] data = l.GenerateData(LayerFlowImageGeneration.X, LayerFlowImageGeneration.Y, width, height);
            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    while (true)
                    {
                        try
                        {
                            if (colors != null && colors.ContainsKey(data[x + y * width]))
                            {
                                LayerColor lc = colors[data[x + y * (width)]];
                                SolidBrush sb = new SolidBrush(Color.FromArgb(lc.A, lc.R, lc.G, lc.B));
                                g.FillRectangle(
                                    sb,
                                    new Rectangle(x, y, 1, 1)
                                    );
                            }
                            else
                            {
                                g.FillRectangle(
                                    m_UnknownAssociation,
                                    new Rectangle(x, y, 1, 1)
                                    );
                            }
                            break;
                        }
                        catch (InvalidOperationException)
                        {
                            // Graphics can be in use elsewhere, but we don't care; just try again.
                        }
                    }
                }
            }
            return(b);
        }
Esempio n. 29
0
        protected override void OnRegistered()
        {
            // 譜面を読み込む
            Game.LoadScore();

            Layer2D back = new Layer2D();

            // 背景の設定
            back.AddPostEffect(
                new Background(
                    new Vector3DF(0.4f, 1.0f, 0.0f),
                    new Vector3DF(0.7f, 1.0f, 0.4f)
                    )
                );

            AddLayer(back);
            AddLayer(new ImageLayer());
            AddLayer(new TextLayer());
        }
Esempio n. 30
0
    public void MoveEnemy(Layer2D layer)
    {
        int xDir = 0;
        int yDir = 0;

        if (Mathf.Abs(target.position.x - transform.position.x) < float.Epsilon)
        {
            yDir = target.position.y > transform.position.y ? 1 : -1;
        }

        else
        {
            xDir = target.position.x > transform.position.x ? 1 : -1;
        }

        var dir = ChipUtil.CreateDirection(new Vector2Int(xDir, yDir));

        AttemptMove(layer, dir);
    }
Esempio n. 31
0
        public Layer2D BuildLayer(Vector3D dimBox, Vector2D dimContainer, LayerDesc layerDesc)
        {
            // instantiate layer
            Layer2D layer = new Layer2D(dimBox, dimContainer, layerDesc.AxisOrtho, layerDesc.Swapped);
            // get layer pattern
            LayerPattern pattern = LayerPattern.GetByName(layerDesc.PatternName);
            // dimensions
            double actualLength = 0.0, actualWidth = 0.0;

            if (!pattern.GetLayerDimensionsChecked(layer, out actualLength, out actualWidth))
            {
                return(null);
            }
            pattern.GenerateLayer(
                layer
                , actualLength
                , actualWidth);
            return(layer);
        }
Esempio n. 32
0
            protected override void OnUpdate()
            {
                void AddEffect(Judge judge)
                {
                    Layer2D   layer = ((GameScene)Layer.Scene).EffectLayer;
                    Vector2DF p     = new Vector2DF(Position.X + Src.Size.X * 0.5f, 520);

                    layer.AddObject(new HitEffect(judge, p));
                }

                if (Time < -500)
                {
                    double v = Pow(Stopwatch.ElapsedMilliseconds, 2);
                    Color = new Color(255, 255, 255, (int)(v * 0.00102));
                }
                else
                {
                    Color = new Color(255, 255, 255);
                }

                // ノーツの移動
                int difference = (int)(Time - NoteInfo.Timing);

                Position = new Vector2DF(Position.X, 520 + difference * 0.05f * Player.HighSpeed);

                // 直前のノーツがnullか,Disposeメソッドがすでに呼び出された場合
                if (PrevNote == null || !PrevNote.IsAlive)
                {
                    // 推れるべきボタンがどれか一つ押されていた場合
                    bool ButtonPressed =
                        Button.Any(b => Controller.GetPush(b));

                    if (difference > 166 || (difference >= -166 && ButtonPressed))
                    {
                        // キャラクターを更新する
                        Character.AddEffet = AddEffect;
                        Character.Update(difference);

                        Dispose();
                    }
                }
            }
        public override bool GetLayerDimensions(Layer2D layer, out double actualLength, out double actualWidth)
        {
            double boxLength = layer.BoxLength;
            double boxWidth = layer.BoxWidth;
            double palletLength = GetPalletLength(layer);
            double palletWidth = GetPalletWidth(layer);

            int iStep = 0, maxSizeXLength = 0, maxSizeXWidth = 0, maxSizeYLength = 0, maxSizeYWidth = 0;
            GetSizeXY(boxLength, boxWidth, palletLength, palletWidth
                , out iStep, out maxSizeXLength, out maxSizeXWidth, out maxSizeYLength, out maxSizeYWidth);

            actualLength = maxSizeXLength * boxLength + maxSizeXWidth * boxWidth;
            if (maxSizeYWidth >= iStep && (iStep * boxLength <= palletLength))
                actualLength = Math.Max(actualLength, iStep * boxLength);
            actualWidth = maxSizeYWidth * boxWidth + maxSizeYLength * boxLength;
            if (maxSizeXLength >= iStep && (iStep * boxWidth <= palletWidth))
                actualWidth = Math.Max(actualWidth, iStep * boxWidth);

            return maxSizeXLength > 0 && maxSizeXWidth > 0 && maxSizeYLength > 0 && maxSizeYWidth > 0;
        }
Esempio n. 34
0
    public void GenerateBossFloor()
    {
        Debug.Log("Bossstage");
        width  = 15;
        height = 15;
        _floor = new Layer2D(width, height);
        _floor.Fill(NONE);
        _divList = new List <DgDivision> ();
        int start = 5;
        int goal  = 5;

        SetBigWall(start, goal);
        // ボスを戦闘モードに
        GameObject.Find("Boss(Clone)").GetComponent <Boss>().ShiftButtleMode(500 + (int)(_floorNum * 100), 300 + (int)(_floorNum * 100), _floorNum);
        // ステージ生成
        stage = (GameObject)Instantiate(BossStage, new Vector2((float)width / 2, (float)height / 2), new Quaternion());
        stage.transform.parent = gameObject.transform;
        // 主人公を配置
        GameObject.Find("Player").transform.position = new Vector2(start, wallSize * 2 / 3);
    }
Esempio n. 35
0
        public void Draw(Graphics3DControl ctrl, Graphics3D graphics)
        {
            Layer2D          selLayer = SelectedLayer;
            PalletProperties pallet   = SelectedPallet;
            Packable         packable = SelectedPackable;

            if (null == selLayer || null == packable || null == pallet)
            {
                return;
            }
            var analysis = new AnalysisCasePallet(packable, pallet, BuildConstraintSet(), true /*temporary*/);

            analysis.AddSolution(new List <LayerDesc> {
                selLayer.LayerDescriptor
            });

            ViewerSolution sv = new ViewerSolution(analysis.Solution);

            sv.Draw(graphics, Transform3D.Identity);
        }
Esempio n. 36
0
        protected override void OnRegistered()
        {
            Layer2D back   = new Layer2D();
            Layer2D text   = new Layer2D();
            Layer2D window = new Layer2D();

            // 背景を設定する
            back.AddPostEffect(
                new Background(
                    new Vector3DF(1.0f, 1.0f, 0.0f),
                    new Vector3DF(1.0f, 1.0f, 0.6f)
                    )
                );

            // テキストの中心座標をオブジェクトの中心にする
            Vector2DF center = new Vector2DF(0.5f, 0.5f);

            // 「RESULT」
            AGText title = new AGText(72, 4, center);

            title.SetText("RESULT");
            title.Position = new Vector2DF(640, 70);
            text.AddObject(title);

            // ウィンドウを追加する
            for (int i = 1; i <= 4; ++i)
            {
                if (Game.Player[i - 1] != null)
                {
                    window.AddObject(new ResultWindow(i)
                    {
                        NoisyValue = 0.025f
                    });
                }
            }

            // レイヤーを追加する
            AddLayer(back);
            AddLayer(text);
            AddLayer(window);
        }
        protected override void OnStart()
        {
            var scene  = new Scene();
            var layer  = new Layer2D();
            var layer2 = new Layer2D();
            var obj    = new MyObject_RepeatedlyAddAndRemoveObject();

            Engine.ChangeScene(scene);
            scene.AddLayer(layer);

            for (int i = 0; i < 4; i++)
            {
                layer.AddObject(obj);
                layer.RemoveObject(obj);
            }
            for (int i = 0; i < 4; i++)
            {
                layer2.AddObject(obj);
                layer2.RemoveObject(obj);
            }
        }
Esempio n. 38
0
    /// パスを作る
    void CreatePath(Layer2D layer, int x, int y, List <Vec2D> path)
    {
        // 左・上・右・下
        int[] xTbl = { -1, 0, 1, 0 };
        int[] yTbl = { 0, -1, 0, 1 };
        for (var i = 0; i < 4 /*4方向*/; i++)
        {
            int x2  = x + xTbl[i];
            int y2  = y + yTbl[i];
            int val = layer.Get(x2, y2);

            if (val > CHIP_NONE)
            {
                // 経路を発見
                layer.Set(x2, y2, CHIP_NONE);
                path.Add(new Vec2D(x2, y2));

                CreatePath(layer, x2, y2, path);
            }
        }
    }
Esempio n. 39
0
        protected override void OnRegistered()
        {
            //レイヤ初期化
            characterLayer = new Layer2D();
            bulletLayer    = new Layer2D();
            UILayer        = new Layer2D();

            //レイヤを設定
            AddLayer(characterLayer);
            AddLayer(bulletLayer);
            AddLayer(UILayer);

            //プレイヤーと敵を生成
            Player player = new Player(this);

            characterLayer.AddObject(player);

            Enemy enemy = new Enemy(player, this);

            characterLayer.AddObject(enemy);
        }
Esempio n. 40
0
        public SoftmaxLayer2D(Layer2D prevLayer, int sliceCount, Size outputSize) : base(prevLayer, null, sliceCount)
        {
            int x = outputSize.Width;
            int y = outputSize.Height;

            this.buffer = new MemoryBuffer2D <float> [sliceCount];

            for (int i = 0; i < sliceCount; i++)
            {
                this.bias[i]      = GPUHelper.CreateBuffer(x, y);
                this.buffer[i]    = GPUHelper.CreateBuffer(x, y);
                this.activated[i] = GPUHelper.CreateBuffer(x, y);
                this.sumInput[i]  = GPUHelper.CreateBuffer(x, y);
                this.error[i]     = GPUHelper.CreateBuffer(x, y);
                this.weight[i]    = GPUHelper.CreateBuffer(x, y, GetWeightCount());
                this.variable[i]  = GPUHelper.accelerator.Allocate <float>(2);
                float[] vars = { Config.learningRate, 0.0f };
                this.variable[i].CopyFrom(vars, Index1.Zero, Index1.Zero, this.variable[i].Extent);
                this.derived[i] = GPUHelper.CreateBuffer(x, y);
            }
        }
Esempio n. 41
0
        public bool GetDimensions(List <LayerDesc> layers, Vector3D dimBox, Vector2D dimContainer, out Vector2D actualDimensions)
        {
            actualDimensions = new Vector2D();
            foreach (LayerDesc layerDesc in layers)
            {
                // instantiate layer
                Layer2D layer = new Layer2D(dimBox, dimContainer, layerDesc.AxisOrtho, false);
                // get layer pattern
                LayerPattern pattern = LayerPattern.GetByName(layerDesc.PatternName);
                // dimensions
                double actualLength = 0.0, actualWidth = 0.0;
                if (!pattern.GetLayerDimensionsChecked(layer, out actualLength, out actualWidth))
                {
                    return(false);
                }

                actualDimensions.X = Math.Max(actualDimensions.X, actualLength);
                actualDimensions.Y = Math.Max(actualDimensions.Y, actualWidth);
            }
            return(true);
        }
Esempio n. 42
0
        private Layer2D GenerateBestLayer(
            BProperties bProperties, PalletProperties palletProperties, PalletCornerProperties cornerProperties,
            PalletConstraintSet constraintSet, HalfAxis.HAxis hAxis)
        {
            Layer2D bestLayer = null;

            // loop through all patterns
            foreach (LayerPatternBox pattern in LayerPatternBox.All)
            {
                // is pattern allowed
                if (!_constraintSet.AllowPattern(pattern.Name))
                {
                    continue;
                }

                // direction 1
                Layer2D layer1 = BuildLayer(bProperties, palletProperties, cornerProperties,
                                            constraintSet, hAxis, false, false);
                double actualLength = 0.0, actualWidth = 0.0;
                pattern.GetLayerDimensionsChecked(layer1, out actualLength, out actualWidth);
                pattern.GenerateLayer(layer1, actualLength, actualWidth);
                // save as best pattern
                if (null == bestLayer || bestLayer.Count < layer1.Count)
                {
                    bestLayer = layer1;
                }
                // direction 2 (opposite)
                Layer2D layer2 = BuildLayer(bProperties, palletProperties, cornerProperties,
                                            constraintSet, HalfAxis.Opposite(hAxis), false, false);
                actualLength = 0.0; actualWidth = 0.0;
                pattern.GetLayerDimensionsChecked(layer2, out actualLength, out actualWidth);
                pattern.GenerateLayer(layer2, actualLength, actualWidth);
                // save as best pattern
                if (null == bestLayer || bestLayer.Count < layer2.Count)
                {
                    bestLayer = layer2;
                }
            }
            return(bestLayer);
        }
Esempio n. 43
0
        public void Draw(Graphics3D graphics, Packable packable, double height, bool selected, bool annotate)
        {
            graphics.BackgroundColor = selected ? Color.LightBlue : Color.White;
            graphics.CameraPosition  = Graphics3D.Corner_0;

            // draw layer (brick)
            if (_layer is Layer2D)
            {
                Layer2D layer2D = _layer as Layer2D;
                uint    pickId  = 0;
                foreach (LayerPosition bPosition in layer2D)
                {
                    if (packable is PackProperties)
                    {
                        graphics.AddBox(new Pack(pickId++, packable as PackProperties, bPosition));
                    }
                    else if (packable is PackableBrick)
                    {
                        graphics.AddBox(new Box(pickId++, packable as PackableBrick, bPosition));
                    }
                }
            }
            // draw layer (cylinder)
            else if (_layer is Layer2DCyl)
            {
                Layer2DCyl layer2DCyl = _layer as Layer2DCyl;
                uint       pickId     = 0;
                foreach (Vector2D pos in layer2DCyl)
                {
                    Cylinder c = new Cylinder(pickId++, packable as CylinderProperties, new CylPosition(new Vector3D(pos.X, pos.Y, 0.0), HalfAxis.HAxis.AXIS_Z_P));
                    graphics.AddCylinder(c);
                }
            }
            graphics.Flush();
            // annotate thumbnail
            if (annotate)
            {
                Annotate(graphics.Graphics, graphics.Size, height);
            }
        }
Esempio n. 44
0
 /// パスを作る
 void CreatePath(Layer2D layer, int x, int y, List <Vec2D> path)
 {
     // 左・上・右・下を調べる
     int[] xTbl = { -1, 0, 1, 0 };
     int[] yTbl = { 0, -1, 0, 1 };
     for (var i = 0; i < xTbl.Length; i++)
     {
         int x2  = x + xTbl[i];
         int y2  = y + yTbl[i];
         int val = layer.Get(x2, y2);
         if (val > CHIP_NONE)
         {
             // 経路を発見
             // 経路をふさぐ
             layer.Set(x2, y2, CHIP_NONE);
             // 座標を追加
             path.Add(new Vec2D(x2, y2));
             // パス生成を再帰呼び出し
             CreatePath(layer, x2, y2, path);
         }
     }
 }
Esempio n. 45
0
        public override bool GetLayerDimensions(Layer2D layer, out double actualLength, out double actualWidth)
        {
            double boxLength    = layer.BoxLength;
            double boxWidth     = layer.BoxWidth;
            double palletLength = GetPalletLength(layer);
            double palletWidth  = GetPalletWidth(layer);

            // compute optimal layout by evaluating all spirale configurations
            int sizeX_area1 = 0, sizeY_area1 = 0, sizeX_area2 = 0, sizeY_area2 = 0;

            GetOptimalSizesXY(boxLength, boxWidth, palletLength, palletWidth
                              , out sizeX_area1, out sizeY_area1, out sizeX_area2, out sizeY_area2);

            // actual length / actual width
            actualLength = sizeX_area1 * boxLength + sizeX_area2 * boxWidth;
            actualWidth  = sizeY_area1 * boxWidth + sizeY_area2 * boxLength;
            if (2.0 * sizeX_area1 * boxLength > palletLength &&
                2.0 * sizeY_area1 * boxWidth > actualWidth)
            {
                actualWidth = 2.0 * sizeY_area1 * boxWidth;
            }
            else if (2.0 * sizeY_area1 * boxWidth > palletWidth &&
                     2.0 * sizeX_area1 * boxLength > actualLength)
            {
                actualLength = 2.0 * sizeX_area1 * boxLength;
            }
            else if (2.0 * sizeX_area2 * boxWidth > palletLength &&
                     2.0 * sizeY_area2 * boxLength > actualWidth)
            {
                actualWidth = 2.0 * sizeY_area2 * boxLength;
            }
            else if (2.0 * sizeY_area2 * boxLength > palletWidth &&
                     2.0 * sizeX_area2 * boxWidth > actualLength)
            {
                actualLength = 2.0 * sizeX_area2 * boxWidth;
            }

            return(sizeX_area1 > 0 && sizeX_area2 > 0 && sizeY_area1 > 0 && sizeY_area2 > 0);
        }
Esempio n. 46
0
        public override bool GetLayerDimensions(Layer2D layer, out double actualLength, out double actualWidth)
        {
            double boxLength = layer.BoxLength;
            double boxWidth = layer.BoxWidth;
            double palletLength = GetPalletLength(layer);
            double palletWidth = GetPalletWidth(layer);

            int sizeX_area1 = 0, sizeY_area1 = 0, sizeX_area2 = 0, sizeY_area2 = 0, sizeX_area3 = 0, sizeY_area3 = 0;
            GetOptimalSizeArea1(boxLength, boxWidth, palletLength, palletWidth, out sizeX_area1, out sizeY_area1);
            GetSizeXY(boxLength, boxWidth, palletLength, palletWidth, sizeX_area1, sizeY_area1
                , out sizeX_area2, out sizeY_area2, out sizeX_area3, out sizeY_area3);

            actualLength = Math.Max(sizeX_area2 * boxLength, sizeX_area1 * boxWidth + sizeX_area3 * boxLength);
            actualWidth = Math.Max(sizeY_area1 * boxLength, sizeY_area3 * boxWidth) + sizeY_area2 * boxWidth;

            Debug.Assert(actualLength <= palletLength);
            Debug.Assert(actualWidth <= palletWidth);

            return sizeX_area1 > 0 && sizeY_area1 > 0
                && sizeX_area2 > 0 && sizeY_area2 > 0
                && sizeX_area3 > 0 && sizeY_area3 > 0;
        }
Esempio n. 47
0
        public Layer2D BuildLayer(Vector3D dimBox, Vector2D dimContainer, LayerDescBox layerDesc, double minSpace)
        {
            LayerDescBox layerDescBox = layerDesc as LayerDescBox;
            // instantiate layer
            var layer = new Layer2D(dimBox, dimContainer, layerDescBox.PatternName, layerDescBox.AxisOrtho, layerDesc.Swapped)
            {
                ForcedSpace = minSpace
            };
            // get layer pattern
            LayerPatternBox pattern = LayerPatternBox.GetByName(layerDesc.PatternName);

            // dimensions
            if (!pattern.GetLayerDimensionsChecked(layer, out double actualLength, out double actualWidth))
            {
                return(null);
            }
            pattern.GenerateLayer(
                layer
                , actualLength
                , actualWidth);
            return(layer);
        }
Esempio n. 48
0
        public override void OnNext()
        {
            try
            {
                Layer2D          selLayer   = SelectedLayer;
                List <LayerDesc> layerDescs = new List <LayerDesc>()
                {
                    selLayer.LayerDescriptor
                };
                Solution.SetSolver(new LayerSolver());
                AnalysisCasePallet analysis = AnalysisCast;
                if (null == analysis)
                {
                    _item = _document.CreateNewAnalysisCasePallet(
                        ItemName, ItemDescription
                        , SelectedPackable, SelectedPallet
                        , new List <InterlayerProperties>()
                        , null, null, null
                        , BuildConstraintSet()
                        , layerDescs
                        );
                }
                else
                {
                    analysis.ID.SetNameDesc(ItemName, ItemDescription);
                    analysis.Content          = SelectedPackable;
                    analysis.PalletProperties = SelectedPallet;
                    analysis.ConstraintSet    = BuildConstraintSet();
                    analysis.AddSolution(layerDescs);

                    _document.UpdateAnalysis(analysis);
                }
                Close();
            }
            catch (Exception ex)
            {
                _log.Error(ex.ToString());
            }
        }
Esempio n. 49
0
 public SolutionViewerLayer(Layer2D layer)
 {
     _layer = layer;
 }
Esempio n. 50
0
 public ANodeMgr(Layer2D layer, int xgoal, int ygoal, bool allowdiag=true)
 {
     _layer = layer;
     _allowdiag = allowdiag;
     _openList = new List<ANode>();
     _pool = new Dictionary<int, ANode>();
     _xgoal = xgoal;
     _ygoal = ygoal;
 }
Esempio n. 51
0
 abstract public int GetNumberOfVariants(Layer2D layer);
Esempio n. 52
0
 public override int GetNumberOfVariants(Layer2D layer) { return 1; }
Esempio n. 53
0
        public override void GenerateLayer(Layer2D layer, double actualLength, double actualWidth)
        {
            layer.Clear();

            double boxLength = layer.BoxLength;
            double boxWidth = layer.BoxWidth;
            double palletLength = GetPalletLength(layer);
            double palletWidth = GetPalletWidth(layer);

            int sizeX_area1 = 0, sizeY_area1 = 0, sizeX_area2 = 0, sizeY_area2 = 0, sizeX_area3 = 0, sizeY_area3 = 0;
            GetOptimalSizeArea1(boxLength, boxWidth, palletLength, palletWidth, out sizeX_area1, out sizeY_area1);
            GetSizeXY(boxLength, boxWidth, palletLength, palletWidth, sizeX_area1, sizeY_area1
                , out sizeX_area2, out sizeY_area2, out sizeX_area3, out sizeY_area3);

            // compute offsets
            double offsetX = 0.5 * (palletLength - actualLength);
            double offsetY = 0.5 * (palletWidth - actualWidth);

            // compute spaces
            double spaceX_area1 = (actualLength - (boxWidth * sizeX_area1 + boxLength * sizeX_area3)) / (sizeX_area1 + sizeX_area3 > 1 ? (sizeX_area1 + sizeX_area3 - 1) : 1.0);
            double spaceX_area2 = (actualLength - sizeX_area2 * boxLength) / (sizeX_area2 > 1 ?(sizeX_area2 - 1) : 1.0);
            double spaceX_area3 = spaceX_area1;

            double spaceY_area1 = 0.0, spaceY_area2 = 0.0, spaceY_area3 = 0.0;
            if (sizeY_area1 * boxLength > sizeY_area3 * boxWidth)
            {
                spaceY_area1 =  (actualWidth - sizeY_area1 * boxLength - sizeY_area2 * boxWidth) / (sizeY_area1 + sizeY_area2 > 1 ?(sizeY_area1 + sizeY_area2 - 1) : 1.0);
                spaceY_area2 = spaceY_area1;
                spaceY_area3 =  (sizeY_area1 * (boxLength + spaceY_area1) - sizeY_area3 * boxWidth) / (0 != sizeY_area3 ? sizeY_area3 : 1.0);
            }
            else
            {
                spaceY_area3 =  (actualWidth - (sizeY_area2 + sizeY_area3) * boxWidth) / (sizeY_area2 + sizeY_area3 > 1 ? (sizeY_area2 + sizeY_area3 - 1) : 1.0);
                spaceY_area2 = spaceY_area3;
                spaceY_area1 =  (sizeY_area3 * (boxWidth + spaceY_area3) - sizeY_area1 * boxLength) /(sizeY_area1 > 0 ? sizeY_area1 : 1.0);
            }
            // area1
            for (int i = 0; i < sizeX_area1; ++i)
                for (int j = 0; j < sizeY_area1; ++j)
                    AddPosition(layer
                        , new Vector2D(
                            offsetX + boxWidth + i * (boxWidth + spaceX_area1)
                            , offsetY + j * (boxLength + spaceY_area1))
                        , HalfAxis.HAxis.AXIS_Y_P, HalfAxis.HAxis.AXIS_X_N);
            // area2
            for (int i = 0; i < sizeX_area2; ++i)
                for (int j = 0; j < sizeY_area2; ++j)
                    AddPosition(layer
                        , new Vector2D(
                            offsetX + i * (boxLength + spaceX_area2)
                            , actualWidth + offsetY - (j + 1) * boxWidth - j * spaceY_area2)
                        , HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Y_P);
            // area3
            for (int i = 0; i < sizeX_area3; ++i)
                for (int j = 0; j < sizeY_area3; ++j)
                    AddPosition(layer
                        , new Vector2D(
                            offsetX + sizeX_area1 * (boxWidth + spaceX_area1) + i * (boxLength + spaceX_area3)
                            , offsetY + j * (boxWidth + spaceY_area3))
                        , HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Y_P);

            layer.UpdateMaxSpace(spaceX_area1);
            layer.UpdateMaxSpace(spaceY_area1);
            layer.UpdateMaxSpace(spaceX_area2);
            layer.UpdateMaxSpace(spaceY_area2);
            layer.UpdateMaxSpace(spaceX_area3);
            layer.UpdateMaxSpace(spaceY_area3);
        }
Esempio n. 54
0
 abstract public void GenerateLayer(Layer2D layer, double actualLength, double actualWidth);
Esempio n. 55
0
 public Layer2D BuildLayer(Vector3D dimBox, Vector2D dimContainer, LayerDesc layerDesc, Vector2D actualDimensions)
 { 
     // instantiate layer
     Layer2D layer = new Layer2D(dimBox, dimContainer, layerDesc.AxisOrtho, false);
     // get layer pattern
     LayerPattern pattern = LayerPattern.GetByName(layerDesc.PatternName);
     // build layer
     pattern.GenerateLayer(layer, actualDimensions.X, actualDimensions.Y);
     return layer;
 }
Esempio n. 56
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
            Layer2D[] bestLayers = new Layer2D[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))
                {
                    Layer2D layer0 = bestLayers[i % 3];
                    Layer2D 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, 0);
                        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, 0);
                        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, 0);
                        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, 0);
                        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;
        }
        public override void GenerateLayer(Layer2D layer, double actualLength, double actualWidth)
        {
            // initialization
            layer.Clear();

            double boxLength = layer.BoxLength;
            double boxWidth = layer.BoxWidth;
            double palletLength = GetPalletLength(layer);
            double palletWidth = GetPalletWidth(layer);

            // compute optimal layout
            int sizeX_area1 = 0, sizeY_area1 = 0
                , sizeX_area2 = 0, sizeY_area2 = 0
                , sizeX_area3 = 0, sizeY_area3 = 0
                , dir_area3 = 0;

            GetOptimalSizesXY(
            boxLength, boxWidth, palletLength, palletWidth
            , out sizeX_area1, out sizeY_area1
            , out sizeX_area2, out sizeY_area2
            , out sizeX_area3, out sizeY_area3
            , out dir_area3);

            // compute offsets
            double offsetX = 0.5 * (palletLength - actualLength);
            double offsetY = 0.5 * (palletWidth - actualWidth);

            // area1
            for (int i = 0; i < sizeX_area1; ++i)
                for (int j = 0; j < sizeY_area1; ++j)
                {
                    AddPosition(layer
                        , new Vector2D(offsetX + i * boxLength, offsetY + j * boxWidth)
                        , HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Y_P);
                    AddPosition(layer
                        , new Vector2D(palletLength - offsetX - i * boxLength, palletWidth - offsetY - j * boxWidth)
                        , HalfAxis.HAxis.AXIS_X_N, HalfAxis.HAxis.AXIS_Y_N);
                }
            double spaceX_area1 = actualLength - 2 * sizeX_area1 * boxLength;
            double spaceY_area1 = actualWidth - 2 * sizeY_area1 * boxWidth;
            // area2
            for (int i = 0; i < sizeX_area2; ++i)
                for (int j = 0; j < sizeY_area2; ++j)
                {
                    AddPosition(layer
                        , new Vector2D(palletLength - offsetX - i * boxWidth, offsetY + j * boxLength)
                        , HalfAxis.HAxis.AXIS_Y_P, HalfAxis.HAxis.AXIS_X_N);
                    AddPosition(layer
                        , new Vector2D(offsetX + i * boxWidth, palletWidth - offsetY - j * boxLength)
                        , HalfAxis.HAxis.AXIS_Y_N, HalfAxis.HAxis.AXIS_X_P);
                }
            double spaceX_area2 = actualLength - 2 * sizeX_area2 * boxWidth;
            double spaceY_area2 = actualWidth - 2 * sizeY_area2 * boxLength;
            // area3
            for (int i = 0; i < sizeX_area3; ++i)
                for (int j = 0; j < sizeY_area3; ++j)
                {
                    if (dir_area3 == 0)
                        AddPosition(layer
                        , new Vector2D(
                            offsetX + 0.5 * (actualLength  - sizeX_area3 * boxLength) + i * boxLength
                            , offsetY + 0.5 * (actualWidth - sizeY_area3 * boxWidth) + j * boxWidth
                            )
                        , HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Y_P);
                    else
                        AddPosition(layer
                            , new Vector2D(
                            offsetX + 0.5 * (actualLength - sizeX_area3 * boxWidth) + (i+1) * boxWidth
                            , offsetY + 0.5 * (actualWidth - sizeY_area3 * boxLength) + j * boxLength
                            )
                            , HalfAxis.HAxis.AXIS_Y_P, HalfAxis.HAxis.AXIS_X_N);
                }

            double spaceX_area3 = 0.0, spaceY_area3 = 0.0;
            if (dir_area3 == 0)
            {
                spaceX_area3 = 0.5 * (actualLength - sizeX_area3 * boxLength - 2.0 * (spaceX_area1 > 0 ? sizeX_area1 * boxLength : sizeX_area2 * boxWidth));
                spaceY_area3 = 0.5 * (actualWidth - sizeY_area3 * boxWidth - 2.0 * (spaceY_area1 > 0 ? sizeY_area1 * boxWidth : sizeY_area2 * boxLength));
            }
            else
            {
                spaceX_area3 = 0.5 * (actualLength - sizeX_area3 * boxWidth - 2.0 * (spaceX_area1 > 0 ? sizeX_area1 * boxLength : sizeX_area2 * boxWidth));
                spaceY_area3 = 0.5 * (actualWidth - sizeY_area3 * boxLength - 2.0 * (spaceY_area1 > 0 ? sizeY_area1 * boxWidth : sizeY_area2 * boxLength));
            }
            // set spacing
            layer.UpdateMaxSpace(spaceX_area3);
            layer.UpdateMaxSpace(spaceY_area3);
        }
Esempio n. 58
0
 abstract public bool GetLayerDimensions(Layer2D layer, out double actualLength, out double actualWidth);
Esempio n. 59
0
 public LayerItem(Layer2D layer, bool selected) { Layer = layer; Selected = selected; }
Esempio n. 60
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 (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(_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;
                                    BoxLayer 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)
                                        {
                                            BoxLayer 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;
        }