protected virtual void DestroyCell()
        {
            var temp = new T[_containers.Length - 1];

            for (var i = 0; i < _containers.Length - 1; i++)
            {
                temp[i] = _containers[i];
            }
            var cell = Containers.Last();   //Последняя вьюшку предмета

            if (_choosenCell != null && ChoosenCell.Equals(cell))
            {
                _choosenCell = default(T);
            }
            cell.Destroy();
            _containers = temp;
        }
示例#2
0
        public void run()
        {
            //Pieces.Sort(new GFG());
            Containers.Add(new Container());
            Containers.Last().Size   = Size;
            Containers.Last().Blocks = new List <Block>();
            while (!Algorithm())
            {
                //break;
                if (Blocks.Count() == 0)
                {
                    break;
                }


                Containers.Add(new Container());
                Containers.Last().Size   = Size;
                Containers.Last().Blocks = new List <Block>();
                // if (resp.Count() == 0)
                //     break;

                // respT.Add(resp.ToList());

                //resp.Clear();



                // Table += 1;
            }

            /*Area = areaDespercidiada();
             * Waste = Area;
             * Waste /= (H * W);
             * Waste /= Table;*/

            //imp();
            //return Table;
        }
示例#3
0
        bool Algorithm()
        {
            hojas = new List <List <int> >();
            for (int i = 0; i < Size.y; ++i)
            {
                hojas.Add(new List <int>());
                for (int j = 0; j < Size.x; ++j)
                {
                    hojas[i].Add(0);
                }
            }


            long esp = 0;

            int refenceLine = (int)Size.z;

            bool inf = true;

            Tuple <int, int, int, int> gap = Tuple.Create(-1, -1, -1, -1);

            while (esp < Size.z * Size.x * Size.y && Blocks.Count() > 0)
            {
                gap = FindLowestGap();
                if (gap.Item1 == -1 && gap.Item2 == -1 && gap.Item3 == -1 && gap.Item4 == -1)
                {
                    break;
                }
                int index = FindBestFittingItem(gap.Item4, gap.Item3, (int)Size.z - hojas[gap.Item1][gap.Item2]);
                if (index >= 0)
                {
                    if (inf)
                    {
                        refenceLine = (int)Size.z;
                        //refenceLine = Pieces[index].H + hojas[gap.Item1];
                        inf = false;
                    }

                    Blocks[index].Position = new Vector3(gap.Item2, gap.Item1, hojas[gap.Item1][gap.Item2]);

                    //agregar el bloque al contenerdor correspondiente y eliminarlo de la lista
                    Containers.Last().Blocks.Add(Blocks[index]);

                    FillSheets((int)Blocks[index].Size.z, (int)gap.Item1, (int)Blocks[index].Size.y, (int)gap.Item2, (int)Blocks[index].Size.x);
                    esp += (long)Blocks[index].Size.x * (long)Blocks[index].Size.y * (long)Blocks[index].Size.z;

                    Blocks.Remove(Blocks[index]);

                    //resp.Add(Tuple.Create(Pieces[index].Id + (Pieces[index].Quant - Pieces[index].Available).ToString(), gap.Item1, H - (hojas[gap.Item1] + Pieces[index].H), Pieces[index].Normal));



                    //init = 0;
                }
                else
                {
                    if (index == -1)
                    {
                        //int menor = Math.Min((gap.Item1 - 1 >= 0) ? (hojas[gap.Item1 - 1] - hojas[gap.Item1]) : H, (gap.Item2 + gap.Item1 < W) ? (hojas[gap.Item2 + gap.Item1] - hojas[gap.Item2 + gap.Item1 - 1]) : H);
                        int inc = menor(gap.Item1, gap.Item3, gap.Item2, gap.Item4);
                        FillSheets(inc, gap.Item1, gap.Item3, gap.Item2, gap.Item4);

                        esp += inc * gap.Item1 * gap.Item2;
                    }
                    else
                    {
                        if (!inf)
                        {
                            break;
                            refenceLine = (int)Size.z;
                            inf         = true;
                        }
                    }
                }
            }

            return(false);
        }