Пример #1
0
        //Convert Miscellany Item to CromulentBisgetti Item
        private static Item ItemToCB(Miscellany.ContainerPacking.Entities.Item i)
        {
            decimal ddim1  = Miscellany.Math.Functions.ToDecimal(i.Dim1);
            decimal ddim2  = Miscellany.Math.Functions.ToDecimal(i.Dim2);
            decimal ddim3  = Miscellany.Math.Functions.ToDecimal(i.Dim3);
            Item    cbItem = new Item(i.ID, ddim1, ddim2, ddim3, i.Quantity);

            return(cbItem);
        }
Пример #2
0
        //Convert a CromulentBisgetti Item to a Miscellany Item
        private static Miscellany.ContainerPacking.Entities.Item ItemToMiscellany(Item i)
        {
            double ddim1 = Miscellany.Math.Functions.ToDouble(i.Dim1);
            double ddim2 = Miscellany.Math.Functions.ToDouble(i.Dim2);
            double ddim3 = Miscellany.Math.Functions.ToDouble(i.Dim3);

            //Create Item
            Miscellany.ContainerPacking.Entities.Item mItem = new Miscellany.ContainerPacking.Entities.Item(i.ID, ddim1, ddim2, ddim3, i.Quantity);
            //Add packed information
            mItem.IsPacked = i.IsPacked;
            if (i.IsPacked)
            {
                //Swap Y and Z values to shift from the CromulentBisgetti coordinate system and Dynamo
                mItem.PackDimX = Miscellany.Math.Functions.ToDouble(i.PackDimX);
                mItem.PackDimY = Miscellany.Math.Functions.ToDouble(i.PackDimZ);
                mItem.PackDimZ = Miscellany.Math.Functions.ToDouble(i.PackDimY);
                mItem.CoordX   = Miscellany.Math.Functions.ToDouble(i.CoordX);
                mItem.CoordY   = Miscellany.Math.Functions.ToDouble(i.CoordZ);
                mItem.CoordZ   = Miscellany.Math.Functions.ToDouble(i.CoordY);
            }
            return(mItem);
        }
        public static Dictionary <string, object> PackContainersWithGroupsContinuously(List <Miscellany.ContainerPacking.Entities.Container> containers, List <List <Miscellany.ContainerPacking.Entities.Item> > itemsToPack, int algorithm = 1, int minimumItems = 20)
        {
            //Select algorithm using integer
            List <int> algorithms = new List <int> {
                algorithm
            };

            //Create CromulentBisgetti Items, retaining the nested structure
            List <List <Item> > items = new List <List <Item> >();

            foreach (List <Miscellany.ContainerPacking.Entities.Item> l in itemsToPack)
            {
                List <Item> subList = new List <Item>();
                foreach (Miscellany.ContainerPacking.Entities.Item i in l)
                {
                    Item cbItem = ItemToCB(i);
                    subList.Add(cbItem);
                }
                items.Add(subList);
            }

            //Reverse List to start from back so removals don't cause problems to indexing
            items.Reverse();

            //Output lists
            List <List <Miscellany.ContainerPacking.Entities.Item> > itemsPacked = new List <List <Miscellany.ContainerPacking.Entities.Item> >();
            bool          IsCompletePack               = false;
            List <int>    PackTimeInMilliseconds       = new List <int>();
            int           TotalPackTimeInMilliseconds  = 0;
            List <double> PercentContainerVolumePacked = new List <double>();
            List <double> PercentItemVolumePacked      = new List <double>();

            //Items Count
            int currentPackGroup = items.Count - 1; //Set to last index

            //Temporary group of Items to pack
            List <Item> tempItemsToPack = new List <Item>();

            //Loop through the containers
            foreach (Miscellany.ContainerPacking.Entities.Container container in containers)
            {
                //No more pack groups to consider
                if (currentPackGroup < 0)
                {
                    break;
                }

                //How many Items in temp list?
                int tempCount = tempItemsToPack.Count;

                //Ensure count matches the number of groups remaining
                currentPackGroup = items.Count - 1;

                if (tempCount >= minimumItems)
                {
                    //There are more Items than the minimum or the same
                }
                else if (currentPackGroup < 0 || (currentPackGroup == 0 && items[currentPackGroup].Count == 0))
                {
                    //There are fewer Items than the minimum but there are no more Items to draw on
                    if (tempCount == 0)
                    {
                        //No Items left so break the loop
                        break;
                    }
                }
                else
                {
                    //There are fewer Items than the minimum but there are further Items to use
                    int whileCount = 0;
                    while (tempCount < minimumItems)
                    {
                        whileCount++;
                        if (whileCount > 10)
                        {
                            continue; //temp
                        }
                        if (currentPackGroup < 0)
                        {
                            break;
                        }
                        if (items[currentPackGroup].Count == 0)
                        {
                            //No items left, move onto next group for next loop
                            items.RemoveAt(currentPackGroup);
                            currentPackGroup--;
                        }
                        else if (items[currentPackGroup].Count <= (minimumItems - tempCount))
                        {
                            //Fewer Items are available than desired
                            tempItemsToPack.AddRange(items[currentPackGroup]); //Add all Items
                            items.RemoveAt(currentPackGroup);                  //Remove all items from the group
                            currentPackGroup--;                                //Move to the next group index for the next loop
                            tempCount = tempItemsToPack.Count;                 //Set the cou/*
                        }
                        else if (items[currentPackGroup].Count > (minimumItems - tempCount))
                        {
                            //The desired number or greater are available
                            int numberToTake = minimumItems - tempCount;
                            if (numberToTake < 1)
                            {
                                continue;
                            }
                            for (int i = numberToTake - 1; i >= 0; i--)
                            {
                                //Take each required Item and remove from list
                                tempItemsToPack.Add(items[currentPackGroup][i]);
                                items[currentPackGroup].RemoveAt(i);
                            }
                            tempCount = tempItemsToPack.Count; //Report the current size of the temporary group
                        }
                        //tempCount++;
                    }
                }

                //Create CromulentBisgetti Container
                Container        con  = ContainerToCB(container);
                List <Container> cons = new List <Container> {
                    con
                };

                //Get container packing result
                ContainerPackingResult containerPackingResult = CromulentBisgetti.ContainerPacking.PackingService.Pack(cons, tempItemsToPack, algorithms).FirstOrDefault();

                //Get the single algorthim packing result from the container packing result
                AlgorithmPackingResult algorithmPackingResult = containerPackingResult.AlgorithmPackingResults.FirstOrDefault();

                //Packed Items
                List <Miscellany.ContainerPacking.Entities.Item> itemsPackedPass = new List <Miscellany.ContainerPacking.Entities.Item>();
                foreach (Item i in algorithmPackingResult.PackedItems)
                {
                    Miscellany.ContainerPacking.Entities.Item mItem = ItemToMiscellany(i);
                    itemsPackedPass.Add(mItem);
                }
                itemsPacked.Add(itemsPackedPass);
                IsCompletePack = algorithmPackingResult.IsCompletePack;
                if (IsCompletePack)          //If all the items from that group are packed
                {
                    tempItemsToPack.Clear(); //Clear all Items from temp list
                }
                else
                {
                    tempItemsToPack = algorithmPackingResult.UnpackedItems; //items is set to unpacked items for next loop
                }
                PackTimeInMilliseconds.Add(Convert.ToInt32(algorithmPackingResult.PackTimeInMilliseconds));
                TotalPackTimeInMilliseconds += Convert.ToInt32(algorithmPackingResult.PackTimeInMilliseconds);
                PercentContainerVolumePacked.Add(Miscellany.Math.Functions.ToDouble(algorithmPackingResult.PercentContainerVolumePacked));
                PercentItemVolumePacked.Add(Miscellany.Math.Functions.ToDouble(algorithmPackingResult.PercentItemVolumePacked));
            }

            //Convert CromulentBisgetti items to Miscellany Items for Unpacked Items
            List <Miscellany.ContainerPacking.Entities.Item> itemsUnpacked = new List <Miscellany.ContainerPacking.Entities.Item>();

            foreach (List <Item> l in items)
            {
                foreach (Item i in l)
                {
                    Miscellany.ContainerPacking.Entities.Item mItem = ItemToMiscellany(i);
                    itemsUnpacked.Add(mItem);
                }
            }

            //Return values
            var d = new Dictionary <string, object>();

            d.Add("packedItems", itemsPacked);
            d.Add("unpackedItems", itemsUnpacked);
            d.Add("isCompletePack", IsCompletePack);
            d.Add("packTimeInMilliseconds", PackTimeInMilliseconds);
            d.Add("totalPackTimeInMilliseconds", TotalPackTimeInMilliseconds);
            d.Add("percentContainerVolumePacked", PercentContainerVolumePacked);
            d.Add("percentItemVolumePacked", PercentItemVolumePacked);
            return(d);
        }
Пример #4
0
        public static Dictionary <string, object> PackContainer(Miscellany.ContainerPacking.Entities.Container container, List <Miscellany.ContainerPacking.Entities.Item> itemsToPack, int algorithm = 1)
        {
            //Create CromulentBisgetti Container
            Container con = ContainerToCB(container);

            //Create CromulentBisgetti Items
            List <Item> items = new List <Item>();

            foreach (Miscellany.ContainerPacking.Entities.Item i in itemsToPack)
            {
                Item cbItem = ItemToCB(i);
                items.Add(cbItem);
            }

            //Create list with single container
            List <Container> containers = new List <Container> {
                con
            };

            //Select algorithm using integer
            List <int> algorithms = new List <int> {
                algorithm
            };

            //Get container packing result
            ContainerPackingResult containerPackingResult = CromulentBisgetti.ContainerPacking.PackingService.Pack(containers, items, algorithms).FirstOrDefault();

            //Get the single algorthim packing result from the container packing result
            AlgorithmPackingResult algorithmPackingResult = containerPackingResult.AlgorithmPackingResults.FirstOrDefault();
            bool   IsCompletePack               = algorithmPackingResult.IsCompletePack;
            int    PackTimeInMilliseconds       = Convert.ToInt32(algorithmPackingResult.PackTimeInMilliseconds); //Max limit of int32 for milliseconds is596 hours
            double PercentContainerVolumePacked = Miscellany.Math.Functions.ToDouble(algorithmPackingResult.PercentContainerVolumePacked);
            double PercentItemVolumePacked      = Miscellany.Math.Functions.ToDouble(algorithmPackingResult.PercentItemVolumePacked);
            //int BestFitOrientation = algorithmPackingResult.best

            //Convert CromulentBisgetti items to Miscellany Items
            //Packed Items
            List <Miscellany.ContainerPacking.Entities.Item> itemsPacked = new List <Miscellany.ContainerPacking.Entities.Item>();

            foreach (Item i in algorithmPackingResult.PackedItems)
            {
                Miscellany.ContainerPacking.Entities.Item mItem = ItemToMiscellany(i);
                itemsPacked.Add(mItem);
            }
            //Unpacked Items
            List <Miscellany.ContainerPacking.Entities.Item> itemsUnpacked = new List <Miscellany.ContainerPacking.Entities.Item>();

            foreach (Item i in algorithmPackingResult.UnpackedItems)
            {
                Miscellany.ContainerPacking.Entities.Item mItem = ItemToMiscellany(i);
                itemsUnpacked.Add(mItem);
            }

            //Return values
            var d = new Dictionary <string, object>();

            d.Add("packedItems", itemsPacked);
            d.Add("unpackedItems", itemsUnpacked);
            d.Add("isCompletePack", IsCompletePack);
            d.Add("packTimeInMilliseconds", PackTimeInMilliseconds);
            d.Add("percentContainerVolumePacked", PercentContainerVolumePacked);
            d.Add("percentItemVolumePacked", PercentItemVolumePacked);
            d.Add("orientation", PercentItemVolumePacked);
            return(d);
        }
        public static Dictionary <string, object> PackContainersWithGroups(List <Miscellany.ContainerPacking.Entities.Container> containers, List <List <Miscellany.ContainerPacking.Entities.Item> > itemsToPack, int algorithm = 1)
        {
            //Select algorithm using integer
            List <int> algorithms = new List <int> {
                algorithm
            };
            //Create CromulentBisgetti Items
            List <List <Item> > items = new List <List <Item> >();

            foreach (List <Miscellany.ContainerPacking.Entities.Item> l in itemsToPack)
            {
                List <Item> subList = new List <Item>();
                foreach (Miscellany.ContainerPacking.Entities.Item i in l)
                {
                    Item cbItem = ItemToCB(i);
                    subList.Add(cbItem);
                }
                items.Add(subList);
            }

            //Reverse List to start from back so removals don't cause problems to indexing
            items.Reverse();

            //Output lists
            List <List <Miscellany.ContainerPacking.Entities.Item> > itemsPacked = new List <List <Miscellany.ContainerPacking.Entities.Item> >();
            bool          IsCompletePack               = false;
            List <int>    PackTimeInMilliseconds       = new List <int>();
            int           TotalPackTimeInMilliseconds  = 0;
            List <double> PercentContainerVolumePacked = new List <double>();
            List <double> PercentItemVolumePacked      = new List <double>();

            //Items Count
            int currentPackGroup = items.Count - 1;

            //Loop through the containers
            foreach (Miscellany.ContainerPacking.Entities.Container container in containers)
            {
                if (items.Count == 0)
                {
                    break;
                }
                if (items[currentPackGroup].Count == 0)
                {
                    items.RemoveAt(currentPackGroup); //Remove empty list
                    currentPackGroup--;               //move to next group
                }

                //Create list of items to pack
                List <Item> itemsToPackGroup = items[currentPackGroup];

                //Create CromulentBisgetti Container
                Container        con  = ContainerToCB(container);
                List <Container> cons = new List <Container> {
                    con
                };

                //Get container packing result
                ContainerPackingResult containerPackingResult = CromulentBisgetti.ContainerPacking.PackingService.Pack(cons, itemsToPackGroup, algorithms).FirstOrDefault();

                //Get the single algorthim packing result from the container packing result
                AlgorithmPackingResult algorithmPackingResult = containerPackingResult.AlgorithmPackingResults.FirstOrDefault();

                //Packed Items
                List <Miscellany.ContainerPacking.Entities.Item> itemsPackedPass = new List <Miscellany.ContainerPacking.Entities.Item>();
                foreach (Item i in algorithmPackingResult.PackedItems)
                {
                    Miscellany.ContainerPacking.Entities.Item mItem = ItemToMiscellany(i);
                    itemsPackedPass.Add(mItem);
                }
                itemsPacked.Add(itemsPackedPass);
                IsCompletePack = algorithmPackingResult.IsCompletePack;
                if (IsCompletePack)                   //If all the items from that group are packed
                {
                    items.RemoveAt(currentPackGroup); //Remove group from list to pack
                    currentPackGroup--;               //Move on to the next group
                }
                else
                {
                    items[currentPackGroup] = algorithmPackingResult.UnpackedItems; //items is set to unpacked items for next loop
                }
                PackTimeInMilliseconds.Add(Convert.ToInt32(algorithmPackingResult.PackTimeInMilliseconds));
                TotalPackTimeInMilliseconds += Convert.ToInt32(algorithmPackingResult.PackTimeInMilliseconds);
                PercentContainerVolumePacked.Add(Miscellany.Math.Functions.ToDouble(algorithmPackingResult.PercentContainerVolumePacked));
                PercentItemVolumePacked.Add(Miscellany.Math.Functions.ToDouble(algorithmPackingResult.PercentItemVolumePacked));
                if (items.Count == 0) //No more groups to pack
                {
                    break;
                }
            }

            //Convert CromulentBisgetti items to Miscellany Items for Unpacked Items
            List <Miscellany.ContainerPacking.Entities.Item> itemsUnpacked = new List <Miscellany.ContainerPacking.Entities.Item>();

            foreach (List <Item> l in items)
            {
                foreach (Item i in l)
                {
                    Miscellany.ContainerPacking.Entities.Item mItem = ItemToMiscellany(i);
                    itemsUnpacked.Add(mItem);
                }
            }

            //Return values
            var d = new Dictionary <string, object>();

            d.Add("packedItems", itemsPacked);
            d.Add("unpackedItems", itemsUnpacked);
            d.Add("isCompletePack", IsCompletePack);
            d.Add("packTimeInMilliseconds", PackTimeInMilliseconds);
            d.Add("totalPackTimeInMilliseconds", TotalPackTimeInMilliseconds);
            d.Add("percentContainerVolumePacked", PercentContainerVolumePacked);
            d.Add("percentItemVolumePacked", PercentItemVolumePacked);
            return(d);
        }
Пример #6
0
        public static Dictionary <string, object> PackContainers(List <Miscellany.ContainerPacking.Entities.Container> containers, List <Miscellany.ContainerPacking.Entities.Item> itemsToPack, int algorithm = 1)
        {
            //Select algorithm using integer
            List <int> algorithms = new List <int> {
                algorithm
            };

            //Create CromulentBisgetti Items
            List <Item> items = new List <Item>();

            foreach (Miscellany.ContainerPacking.Entities.Item i in itemsToPack)
            {
                Item cbItem = ItemToCB(i);
                items.Add(cbItem);
            }

            //Output lists
            List <List <Miscellany.ContainerPacking.Entities.Item> > itemsPacked = new List <List <Miscellany.ContainerPacking.Entities.Item> >();
            bool          IsCompletePack               = false;
            List <int>    PackTimeInMilliseconds       = new List <int>();
            int           TotalPackTimeInMilliseconds  = 0;
            List <double> PercentContainerVolumePacked = new List <double>();
            List <double> PercentItemVolumePacked      = new List <double>();

            //Loop through the containers
            foreach (Miscellany.ContainerPacking.Entities.Container container in containers)
            {
                //Create CromulentBisgetti Container
                Container        con  = ContainerToCB(container);
                List <Container> cons = new List <Container> {
                    con
                };
                //Get container packing result
                ContainerPackingResult containerPackingResult = CromulentBisgetti.ContainerPacking.PackingService.Pack(cons, items, algorithms).FirstOrDefault();
                //Get the single algorthim packing result from the container packing result
                AlgorithmPackingResult algorithmPackingResult = containerPackingResult.AlgorithmPackingResults.FirstOrDefault();
                //Packed Items
                List <Miscellany.ContainerPacking.Entities.Item> itemsPackedPass = new List <Miscellany.ContainerPacking.Entities.Item>();
                foreach (Item i in algorithmPackingResult.PackedItems)
                {
                    Miscellany.ContainerPacking.Entities.Item mItem = ItemToMiscellany(i);
                    itemsPackedPass.Add(mItem);
                }
                itemsPacked.Add(itemsPackedPass);
                items          = algorithmPackingResult.UnpackedItems; //items is set to unpacked items for next loop
                IsCompletePack = algorithmPackingResult.IsCompletePack;
                PackTimeInMilliseconds.Add(Convert.ToInt32(algorithmPackingResult.PackTimeInMilliseconds));
                TotalPackTimeInMilliseconds += Convert.ToInt32(algorithmPackingResult.PackTimeInMilliseconds);
                PercentContainerVolumePacked.Add(Miscellany.Math.Functions.ToDouble(algorithmPackingResult.PercentContainerVolumePacked));
                PercentItemVolumePacked.Add(Miscellany.Math.Functions.ToDouble(algorithmPackingResult.PercentItemVolumePacked));
                if (algorithmPackingResult.IsCompletePack == true)
                {
                    break;
                }
            }

            //Convert CromulentBisgetti items to Miscellany Items for Unpacked Items
            List <Miscellany.ContainerPacking.Entities.Item> itemsUnpacked = new List <Miscellany.ContainerPacking.Entities.Item>();

            foreach (Item i in items)
            {
                Miscellany.ContainerPacking.Entities.Item mItem = ItemToMiscellany(i);
                itemsUnpacked.Add(mItem);
            }

            //Return values
            var d = new Dictionary <string, object>();

            d.Add("packedItems", itemsPacked);
            d.Add("unpackedItems", itemsUnpacked);
            d.Add("isCompletePack", IsCompletePack);
            d.Add("packTimeInMilliseconds", PackTimeInMilliseconds);
            d.Add("totalPackTimeInMilliseconds", TotalPackTimeInMilliseconds);
            d.Add("percentContainerVolumePacked", PercentContainerVolumePacked);
            d.Add("percentItemVolumePacked", PercentItemVolumePacked);
            return(d);
        }