Ejemplo n.º 1
0
        public void Cuboids_OneBin_CanPackWithLeftovers()
        {
            // Arrange
            var bin = new List <Cuboid> {
                Cuboid.ByLengths(400, 500, 300)
            };
            var items = new List <Cuboid>
            {
                Cuboid.ByLengths(100, 200, 100),
                Cuboid.ByLengths(200, 200, 250),
                Cuboid.ByLengths(100, 150, 300),
                Cuboid.ByLengths(300, 200, 350),
                Cuboid.ByLengths(150, 200, 500),
                Cuboid.ByLengths(200, 100, 100),
                Cuboid.ByLengths(100, 150, 200),
                Cuboid.ByLengths(200, 150, 200),
                Cuboid.ByLengths(250, 200, 300)
            };
            var expectedIndices = new List <List <int> > {
                new List <int> {
                    3, 7, 6, 8, 1
                }
            };
            var expectedPackedContainerVolumes = new List <List <int> > {
                new List <int> {
                    3, 7, 6, 8, 1
                }
            };
            var expectedPercentageContainerVolumePacked = 91.67;
            var expectedPercentageItemVolumePacked      = 70.06;

            // Act
            Dictionary <string, object> result = Packing.PackCuboids(items, bin);

            // Assert
            // Check if the result is a dictionary that contains the expected output port keys
            CollectionAssert.AreEqual(result.Keys, expectedNodeOutputDictionaryKeys);

            // extract results from dictionary
            var actualPackeditems    = (List <List <Cuboid> >)result[packedItemsOutputPort];
            var actualRemainItems    = (List <int>)result[remainingIndicesOutputPort];
            var actualPackedIndices  = (List <List <int> >)result[indicesOutputPort];
            var actualPercentContVol = (result[percentContainerVolumePackedPort] as IEnumerable <double>).First();
            var actualPercentItemVol = (result[percentItemVolumePackedPort] as IEnumerable <double>).First();

            // Checks if the right amount of items has been packed
            Assert.AreEqual(1, actualPackeditems.Count);             // the number of bins this was packed into is 1
            Assert.AreEqual(5, actualPackeditems.Sum(x => x.Count)); // total number of packed cuboids is 5
            Assert.AreEqual(4, actualRemainItems.Count);

            // Check the packing percentages are correct
            Assert.AreEqual(expectedPercentageContainerVolumePacked, Math.Round(actualPercentContVol, 2));
            Assert.AreEqual(expectedPercentageItemVolumePacked, Math.Round(actualPercentItemVol, 2));

            // Checks that the right items has been packed
            Assert.AreEqual(1, actualPackedIndices.Count); // the number of bins this was packed into is 1
            CollectionAssert.AreEqual(actualPackedIndices, expectedIndices);
        }
Ejemplo n.º 2
0
        public void Cuboids_MultiBin_CanPackWithNoLeftovers()
        {
            // Arrange
            var bins = new List <Cuboid> {
                Cuboid.ByLengths(100, 100, 200), // holds 2 of items below
                Cuboid.ByLengths(100, 200, 100), // holds 2 of items below
                Cuboid.ByLengths(100, 200, 100), // would hold 1 of items below, if there were more remaining
            };
            var items = new List <Cuboid>();

            for (int i = 0; i < 4; i++)
            {
                items.Add(Cuboid.ByLengths(100, 100, 100));
            }

            var expectedIndices = new List <List <int> > {
                new List <int> {
                    0, 1
                },
                new List <int> {
                    2, 3
                }
            };

            // Act
            Dictionary <string, object> result = Packing.PackCuboids(items, bins);

            // Assert
            // Checks if the right amount of items has been packed
            var packeditems = (List <List <Cuboid> >)result[packedItemsOutputPort];

            Assert.AreEqual(2, packeditems.Count);             // the number of bins this was packed into is 2
            Assert.AreEqual(4, packeditems.Sum(x => x.Count)); // total number of packed cuboids is 4

            var remainItems = (List <int>)result[remainingIndicesOutputPort];

            Assert.AreEqual(0, remainItems.Count);

            // Checks that the right items has been packed
            var packedIndices = (List <List <int> >)result[indicesOutputPort];

            Assert.AreEqual(2, packedIndices.Count); // the number of bins this was packed into is 2
            CollectionAssert.AreEqual(packedIndices, expectedIndices);
        }
Ejemplo n.º 3
0
        //////////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////////



        /// <summary>
        /// Create geometry representation of tool.
        /// </summary>
        /// <param name="frame">Tool frame at drill tip</param>
        /// <returns></returns>
        private static Solid vis_tool(Plane frame)
        {
            List <Solid>     model = new List <Solid>();
            CoordinateSystem cs    = CoordinateSystem.ByPlane(frame);
            Vector           x     = frame.XAxis;
            Vector           y     = frame.YAxis;
            Vector           z     = frame.Normal.Reverse();
            double           h     = frame.Origin.Z;

            Solid bit0 = Cone.ByCoordinateSystemHeightRadii(cs.Translate(z, 2), 2, 3, 0.1);
            Solid bit1 = Cone.ByCoordinateSystemHeightRadii(cs.Translate(z, 68 + 2), 68, 3, 3);
            Solid bit2 = Cone.ByCoordinateSystemHeightRadii(cs.Translate(z, 5 + 68 + 2), 5, 5, 5);
            Solid bit3 = Cone.ByCoordinateSystemHeightRadii(cs.Translate(z, 5 + 5 + 68 + 2), 5, 4, 4);
            Solid bod0 = Cone.ByCoordinateSystemHeightRadii(cs.Translate(z, 3 + 5 + 5 + 68 + 2), 3, 12, 12);
            Solid bod1 = Cone.ByCoordinateSystemHeightRadii(cs.Translate(z, 80 + 3 + 5 + 5 + 68 + 2), 80, 24, 24);
            Solid bod2 = Cone.ByCoordinateSystemHeightRadii(cs.Translate(z, 80 + 80 + 3 + 5 + 5 + 68 + 2), 80, 34, 34);
            Solid bod3 = Cuboid.ByLengths(cs.Translate(z, 40 + 80 + 3 + 5 + 5 + 68 + 2).Translate(y, 20), 40, 40, 40);
            Solid leg0 = Cone.ByCoordinateSystemHeightRadii(cs.Translate(z, h).Translate(x, 40).Translate(y, 40), h - (80 + 3 + 5 + 5 + 68 + 2), 4, 4);
            Solid leg1 = Cone.ByCoordinateSystemHeightRadii(cs.Translate(z, h).Translate(x, 40).Translate(y, -40), h - (80 + 3 + 5 + 5 + 68 + 2), 4, 4);
            Solid leg2 = Cone.ByCoordinateSystemHeightRadii(cs.Translate(z, h).Translate(x, -40).Translate(y, -40), h - (80 + 3 + 5 + 5 + 68 + 2), 4, 4);
            Solid leg3 = Cone.ByCoordinateSystemHeightRadii(cs.Translate(z, h).Translate(x, -40).Translate(y, 40), h - (80 + 3 + 5 + 5 + 68 + 2), 4, 4);
            Solid box0 = Cuboid.ByLengths(cs.Translate(z, 3 + 80 + 3 + 5 + 5 + 68 + 2), 96, 96, 10);
            Solid box1 = Cuboid.ByLengths(cs.Translate(z, h - 5), 96, 96, 10);

            model.Add(bit0);
            model.Add(bit1);
            model.Add(bit2);
            model.Add(bit3);
            model.Add(bod0);
            model.Add(bod1);
            model.Add(bod2);
            model.Add(bod3);
            model.Add(leg0);
            model.Add(leg1);
            model.Add(leg2);
            model.Add(leg3);
            model.Add(box0);
            model.Add(box1);

            Solid solid = Solid.ByUnion(model);

            return(solid);
        }
Ejemplo n.º 4
0
        public void BySurfNameCategoryMaterial_ValidInput()
        {
            var cube  = Cuboid.ByLengths();
            var faces = cube.Faces;
            var surfs = faces.Select(x => x.SurfaceGeometry()).ToList();
            var surf  = PolySurface.ByJoinedSurfaces(surfs);

            var mat = DocumentManager.Instance.ElementsOfType <Autodesk.Revit.DB.Material>().First();

            var ds = DirectShape.ByGeometry(surf, Category.ByName("OST_GenericModel"), Material.ByName(mat.Name), "a polysurface");

            Assert.NotNull(ds);
            Assert.AreEqual("a polysurface", ds.Name);
            Assert.AreEqual((surf.Tags.LookupTag(ds.InternalElement.Id.ToString()) as DirectShapeState).materialId, mat.Id.IntegerValue);
            BoundingBoxCentroid(ds).DistanceTo(Point.Origin()).ShouldBeApproximately(0);
            surf.Dispose();
            surfs.ForEach(x => x.Dispose());
            faces.ForEach(x => x.Dispose());
            cube.Dispose();
        }
Ejemplo n.º 5
0
        public void PackTest()
        {
            Cuboid        bin   = Cuboid.ByLengths(400, 500, 300);
            List <Cuboid> items = new List <Cuboid>
            {
                Cuboid.ByLengths(100, 200, 100),
                Cuboid.ByLengths(200, 200, 250),
                Cuboid.ByLengths(100, 150, 300),
                Cuboid.ByLengths(300, 200, 350),
                Cuboid.ByLengths(150, 200, 500),
                Cuboid.ByLengths(200, 100, 100),
                Cuboid.ByLengths(100, 150, 200),
                Cuboid.ByLengths(200, 150, 200),
                Cuboid.ByLengths(250, 200, 300)
            };

            // Check if the result is a dictionary that contains the keys
            // "packedItems", "remainItems" and "packedIndices"
            var result = BinPacking.Pack3D(bin, items);

            Assert.IsTrue(result.Keys.Contains("packedItems"));
            Assert.IsTrue(result.Keys.Contains("remainItems"));
            Assert.IsTrue(result.Keys.Contains("packedIndices"));

            // Checks if the right amount of items has been packed
            var packeditems = (List <Cuboid>)result["packedItems"];

            Assert.AreEqual(5, packeditems.Count);

            var remainItems = (List <Cuboid>)result["remainItems"];

            Assert.AreEqual(4, remainItems.Count);

            // Checks that the right items has been packed
            var packedIndices = (List <int>)result["packedIndices"];

            Assert.AreEqual(packedIndices, new List <int> {
                3, 7, 6, 8, 1
            });
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Create geometry representation of wobj.
        /// </summary>
        /// <param name="frame">Wobj frame at cube centroid</param>
        /// <returns></returns>
        private static Solid vis_wobj(Plane frame)
        {
            List <Solid>     model = new List <Solid>();
            CoordinateSystem cs    = CoordinateSystem.ByPlane(frame);
            Vector           z     = frame.Normal.Reverse();
            double           h     = frame.Origin.Z;

            //Solid cube = Cuboid.ByLengths(cs, 40, 40, 40);
            Solid chu0 = Cylinder.ByCoordinateSystemHeightRadii(cs.Translate(cs.ZAxis.Reverse(), 2 + 20), 2, 10, 10);
            Solid bod0 = Cylinder.ByCoordinateSystemHeightRadii(cs.Translate(cs.ZAxis.Reverse(), 18 + 2 + 20), 18, 22, 22);
            Solid bod1 = Cuboid.ByLengths(cs.Translate(z, h - 18 - (h - 18 - 18 - 2 - 20) / 2), 46, 46, h - 18 - 18 - 2 - 20);
            Solid bod2 = Cylinder.ByCoordinateSystemHeightRadii(cs.Translate(z, h), 18, 22, 22);

            //model.Add(cube);
            model.Add(chu0);
            model.Add(bod0);
            model.Add(bod1);
            model.Add(bod2);

            Solid solid = Solid.ByUnion(model);

            return(solid);
        }
Ejemplo n.º 7
0
 public static List <Node> ByPointsLinesGeometries(List <Point> nodeCenters, List <Line> struts, List <Solid> Nodes)
 {
     return(ByPointsLinesAndGeoOrientationStrategy(nodeCenters, struts, 6, Cuboid.ByLengths(19, 19, 19), OrientationStrategy.AverageStrutsVector));
 }