Пример #1
0
        public void Test_SGG_Creation()
        {
            var g = new SquireGridGraph(ROW, COL, false);


            for (int i = 0; i < g.VerticesNum(); i++)
            {
                int row, col;
                g.GetRowAndColFromVertex(i, out row, out col);

                g.SetNeighbor(row, col, Direction.East, 1);
                g.SetNeighbor(row, col, Direction.South, 1);
                g.SetNeighbor(row, col, Direction.West, 1);
                g.SetNeighbor(row, col, Direction.North, 1);
            }

            ITravel dfs = new Bfs(g, preVisit);

            dfs.Travel(16);
            Assert.AreEqual(6280, g.EdgeNum());
        }
Пример #2
0
        public void Test_Graph_DisjSet()
        {
            var     g  = new SquireGridGraph(ROW, COL, false);
            DisjSet ds = new DisjSet(g.VerticesNum());

            for (int i = 0; i < g.VerticesNum(); i++)
            {
                int row, col, v;

                g.GetRowAndColFromVertex(i, out row, out col);
                g.SetNeighbor(row, col, Direction.East, 1);
                if ((v = g.GetNeighborVertex(i, Direction.East)) != -1)
                {
                    ds.UnionSets(i, v);
                }

                g.SetNeighbor(row, col, Direction.South, 1);
                if ((v = g.GetNeighborVertex(i, Direction.South)) != -1)
                {
                    ds.UnionSets(i, v);
                }

                g.SetNeighbor(row, col, Direction.West, 1);
                if ((v = g.GetNeighborVertex(i, Direction.West)) != -1)
                {
                    ds.UnionSets(i, v);
                }

                g.SetNeighbor(row, col, Direction.North, 1);
                if ((v = g.GetNeighborVertex(i, Direction.North)) != -1)
                {
                    ds.UnionSets(i, v);
                }
            }

            Assert.AreEqual(1, ds.GetConnectedComponentNumber());
        }