示例#1
0
        public void TestIssue30B()
        {
            var box1 = Factory.CreateBox("C_Small_1", 21, 21, 3, 1, 20, 20, 2, 100);
            var box2 = Factory.CreateBox("B_Large_2", 1301, 1301, 1301, 1, 1300, 1300, 1300, 1000);
            var box3 = Factory.CreateBox("A_Medium_3", 101, 101, 11, 5, 100, 100, 10, 500);

            var list1 = new BoxList();

            list1.Insert(box1);
            list1.Insert(box2);
            list1.Insert(box3);
            var sorted1 = list1.ToList();

            Assert.Equal(box1.Reference, sorted1[0].Reference);
            Assert.Equal(box3.Reference, sorted1[1].Reference);
            Assert.Equal(box2.Reference, sorted1[2].Reference);

            var list2 = new BoxList();

            list2.Insert(box1);
            list2.Insert(box2);
            list2.Insert(box3);
            var sorted2 = list1.ToList();

            Assert.Equal(box1.Reference, sorted1[0].Reference);
            Assert.Equal(box3.Reference, sorted1[1].Reference);
            Assert.Equal(box2.Reference, sorted1[2].Reference);
        }
示例#2
0
        public void AddingBoxesGeneratesIds()
        {
            var box = new Box()
            {
                Description = "Small",
                OuterWidth  = 21,
                OuterLength = 21,
                OuterDepth  = 3,
                EmptyWeight = 1,
                InnerWidth  = 20,
                InnerLength = 20,
                InnerDepth  = 2,
                MaxWeight   = 100
            };

            var box2 = new Box()
            {
                Description = "Large",
                OuterWidth  = 201,
                OuterLength = 201,
                OuterDepth  = 21,
                EmptyWeight = 1,
                InnerWidth  = 200,
                InnerLength = 200,
                InnerDepth  = 20,
                MaxWeight   = 1000
            };

            var box3 = new Box()
            {
                Description = "Medium",
                OuterWidth  = 101,
                OuterLength = 101,
                OuterDepth  = 11,
                EmptyWeight = 5,
                InnerWidth  = 100,
                InnerLength = 100,
                InnerDepth  = 10,
                MaxWeight   = 500
            };

            var boxes = new BoxList();

            boxes.Insert(box);
            boxes.Insert(box2);
            boxes.Insert(box3);

            var packer = new Packer();

            packer.AddBoxes(boxes);

            var packerBoxes = packer.GetBoxes().GetContent().Cast <Box>();

            foreach (var packerBox in packerBoxes)
            {
                Assert.IsNotEmpty(packerBox.GeneratedId);
            }
        }
示例#3
0
        public void TestSorting()
        {
            var box1 = Factory.CreateBox("C_Small", 21, 21, 3, 1, 20, 20, 2, 100);
            var box2 = Factory.CreateBox("B_Large", 201, 201, 21, 1, 200, 200, 20, 1000);
            var box3 = Factory.CreateBox("A_Medium", 101, 101, 11, 5, 100, 100, 10, 500);

            var list = new BoxList();

            list.Insert(box1);
            list.Insert(box2);
            list.Insert(box3);

            var sorted = list.ToList();

            Assert.Equal("C_Small", sorted[0].Reference);
            Assert.Equal("A_Medium", sorted[1].Reference);
            Assert.Equal("B_Large", sorted[2].Reference);
        }
示例#4
0
        public void TestIssue163()
        {
            var box2 = Factory.CreateBox("C2", 202, 152, 32, 10, 200, 150, 30, 100);
            var box3 = Factory.CreateBox("B3", 202, 152, 32, 10, 200, 150, 30, 250);
            var box1 = Factory.CreateBox("A1", 202, 152, 32, 10, 200, 150, 30, 50);

            var list = new BoxList();

            list.Insert(box1);
            list.Insert(box2);
            list.Insert(box3);

            var sorted = list.ToList();

            Assert.Equal(box1.Reference, sorted[0].Reference);
            Assert.Equal(box2.Reference, sorted[1].Reference);
            Assert.Equal(box3.Reference, sorted[2].Reference);
        }
示例#5
0
        public static IEnumerable <object[]> GetCases_TestCanPackRepresentativeLargerSamples()
        {
            var expected2DDict = new Dictionary <string, Expected>();
            var expected3DDict = new Dictionary <string, Expected>();

            var boxes = new BoxList();

            var itemsDict = new Dictionary <string, List <ItemData> >();

            string[] expectedLines = File.ReadAllLines("./EfficiencyTest/Data/expected.csv");
            string[] boxesLines    = File.ReadAllLines("./EfficiencyTest/Data/boxes.csv");
            string[] itemsLines    = File.ReadAllLines("./EfficiencyTest/Data/items.csv");

            foreach (var expectedLine in expectedLines)
            {
                string[] data = expectedLine.Split(",");
                var      key  = data[0];
                expected2DDict.Add(key, new Expected
                {
                    boxes          = int.Parse(data[1]),
                    weightVariance = double.Parse(data[2], CultureInfo.InvariantCulture),
                    utilisation    = float.Parse(data[3], CultureInfo.InvariantCulture)
                }
                                   );
                expected3DDict.Add(key, new Expected
                {
                    boxes          = int.Parse(data[4]),
                    weightVariance = double.Parse(data[5], CultureInfo.InvariantCulture),
                    utilisation    = float.Parse(data[6], CultureInfo.InvariantCulture)
                }
                                   );
            }

            foreach (var boxLine in boxesLines)
            {
                string[] data = boxLine.Split(",");

                boxes.Insert(Factory.CreateBox(
                                 data[0],
                                 int.Parse(data[1]),
                                 int.Parse(data[2]),
                                 int.Parse(data[3]),
                                 int.Parse(data[4]),
                                 int.Parse(data[5]),
                                 int.Parse(data[6]),
                                 int.Parse(data[7]),
                                 int.Parse(data[8])
                                 )
                             );
            }

            foreach (var itemLine in itemsLines)
            {
                string[] data = itemLine.Split(",");
                var      key  = data[0];

                if (!itemsDict.ContainsKey(key))
                {
                    itemsDict.Add(key, new List <ItemData>());
                }

                itemsDict[key].Add(new ItemData
                {
                    qty    = int.Parse(data[1]),
                    name   = data[2],
                    width  = int.Parse(data[3]),
                    length = int.Parse(data[4]),
                    depth  = int.Parse(data[5]),
                    weight = int.Parse(data[6])
                }
                                   );
            }

            foreach (var kv in itemsDict)
            {
                yield return(new object[] {
                    kv.Key,
                    boxes,
                    itemsDict[kv.Key],
                    expected2DDict[kv.Key],
                    expected3DDict[kv.Key]
                });
            }
        }
示例#6
0
        public void CanAddBoxesInProperOrder()
        {
            var box = new Box()
            {
                Description = "Small",
                OuterWidth  = 21,
                OuterLength = 21,
                OuterDepth  = 3,
                EmptyWeight = 1,
                InnerWidth  = 20,
                InnerLength = 20,
                InnerDepth  = 2,
                MaxWeight   = 100
            };

            var box2 = new Box()
            {
                Description = "Large",
                OuterWidth  = 201,
                OuterLength = 201,
                OuterDepth  = 21,
                EmptyWeight = 1,
                InnerWidth  = 200,
                InnerLength = 200,
                InnerDepth  = 20,
                MaxWeight   = 1000
            };

            var box3 = new Box()
            {
                Description = "Medium",
                OuterWidth  = 101,
                OuterLength = 101,
                OuterDepth  = 11,
                EmptyWeight = 5,
                InnerWidth  = 100,
                InnerLength = 100,
                InnerDepth  = 10,
                MaxWeight   = 500
            };

            var boxes = new BoxList();

            boxes.Insert(box);
            boxes.Insert(box2);
            boxes.Insert(box3);

            var orderedItems = new List <Box>();

            while (!boxes.IsEmpty())
            {
                var bestItem = boxes.GetBest();
                orderedItems.Add(bestItem);
                boxes.ExtractBest();
            }

            var expectedOutcome = new List <Box>()
            {
                box, box3, box2
            };

            for (var counter = 0; counter < expectedOutcome.Count; counter++)
            {
                Assert.AreEqual(orderedItems[counter], expectedOutcome[counter]);
            }
        }
示例#7
0
 public void AddBox(Box box)
 {
     _boxes.Insert(box);
 }