コード例 #1
0
        private (Graph, Graph) RandomTest(Random r, int n, int maxLvlSize)
        {
            Graph t = new AdjacencyListsGraph <SimpleAdjacencyList>(false, n);
            Graph g = new AdjacencyListsGraph <AVLAdjacencyList>(false, n);
            int   minLvl = 0, maxLvl = 0;

            while (maxLvl < n - 1)
            {
                int lvlCnt = r.Next(1, Math.Min(maxLvlSize, n - maxLvl - 1));
                for (int i = 0; i < lvlCnt; ++i)
                {
                    int parent = r.Next(minLvl, maxLvl);
                    t.AddEdge(parent, maxLvl + i + 1);
                    g.AddEdge(parent, maxLvl + i + 1);
                    for (int j = 0; j < i; ++j)
                    {
                        if (r.Next(0, 2) == 1)
                        {
                            g.AddEdge(maxLvl + i + 1, maxLvl + j + 1);
                        }
                    }
                }
                minLvl = maxLvl + 1;
                maxLvl = maxLvl + lvlCnt;
            }
            return(g, t);
        }
コード例 #2
0
        //głębokie drzewo
        private (Graph, Graph) Test05()
        {
            Graph t = new AdjacencyListsGraph <AVLAdjacencyList>(false, 16);

            t.AddEdge(0, 3);
            t.AddEdge(3, 5);
            t.AddEdge(5, 1);
            t.AddEdge(1, 6);
            t.AddEdge(6, 11);
            t.AddEdge(0, 7);
            t.AddEdge(7, 10);
            t.AddEdge(10, 15);
            t.AddEdge(10, 4);
            t.AddEdge(4, 8);
            t.AddEdge(0, 12);
            t.AddEdge(12, 13);
            t.AddEdge(13, 2);
            t.AddEdge(2, 9);
            t.AddEdge(9, 14);
            Graph g = t.Clone();

            g.AddEdge(3, 12);
            g.AddEdge(5, 7);
            g.AddEdge(10, 13);
            g.AddEdge(4, 13);
            g.AddEdge(1, 4);
            g.AddEdge(4, 2);
            return(g, t);
        }
コード例 #3
0
        private (Graph, Graph) FullGraph(RandomGraphGenerator rgg, int n)
        {
            Graph g = rgg.UndirectedGraph(typeof(AdjacencyMatrixGraph), n, 1);
            Graph t = new AdjacencyListsGraph <SimpleAdjacencyList>(false, n);

            for (int i = 1; i < n; ++i)
            {
                t.AddEdge(0, i);
            }
            return(g, t);
        }
コード例 #4
0
        //drzewo
        private (Graph g, Graph t) Test03()
        {
            Graph t = new AdjacencyListsGraph <SimpleAdjacencyList>(false, 10);

            t.AddEdge(0, 1);
            t.AddEdge(0, 2);
            t.AddEdge(0, 8);
            t.AddEdge(1, 9);
            t.AddEdge(1, 3);
            t.AddEdge(2, 4);
            t.AddEdge(2, 6);
            t.AddEdge(6, 7);
            t.AddEdge(4, 5);
            return(t.Clone(), t);
        }
コード例 #5
0
        //3 cykle
        private (Graph g, Graph t) Test02()
        {
            Graph t = new AdjacencyListsGraph <SimpleAdjacencyList>(false, 5);

            t.AddEdge(0, 1);
            t.AddEdge(0, 2);
            t.AddEdge(0, 3);
            t.AddEdge(0, 4);
            Graph g = new AdjacencyListsGraph <HashTableAdjacencyList>(t);

            g.AddEdge(1, 3);
            g.AddEdge(1, 4);
            g.AddEdge(1, 2);
            return(g, t);
        }
コード例 #6
0
        public override void VerifyTestCase(out Result resultCode, out string message, object settings)
        {
            if (cycles == null)
            {
                message    = "Nie zwrócono wyniku";
                resultCode = Result.BadResult;
                return;
            }
            if (!AreEqual(g1, g) || !AreEqual(t1, t))
            {
                message    = "Zmodyfikowano grafy";
                resultCode = Result.BadResult;
                return;
            }
            Graph tLookup = new AdjacencyListsGraph <HashTableAdjacencyList>(t);
            Graph gLookup = new AdjacencyListsGraph <HashTableAdjacencyList>(g);
            var   test    = gLookup.Clone();

            foreach (var e in tLookup.GetEdges())
            {
                test.DelEdge(e);
            }
            foreach (var cycle in cycles)
            {
                bool   notInTree = false;
                bool[] vertices  = new bool[g.VerticesCount];
                if (!cycleChecker.Check(cycle, out message))
                {
                    resultCode = Result.BadResult;
                    return;
                }
                foreach (var e in cycle)
                {
                    if (!tLookup.ContainsEdge(e))
                    {
                        if (notInTree)
                        {
                            message    = "Wiele krawędzi spoza drzewa";
                            resultCode = Result.BadResult;
                            return;
                        }
                        notInTree = true;
                        if (!test.ContainsEdge(e))
                        {
                            message    = $"Wiele cykli z krawędzią {e}";
                            resultCode = Result.BadResult;
                            return;
                        }
                        test.DelEdge(e);
                    }
                }
            }
            if (test.EdgesCount != 0)
            {
                var e = test.GetEdges().First();
                message    = $"Brak cyklu z krawędzią {e}";
                resultCode = Result.BadResult;
                return;
            }
            resultCode = Result.Success;
            message    = "OK";
        }