Exemplo n.º 1
0
    public static void TestVertexDisjointPath3(bool log = true, int loops = 1000)
    {
        for (int loop = 0; loop < loops; ++loop)
        {
            var g        = new UndirectedGraph <int>();
            var rnd      = new Random();
            int vertices = 10 + rnd.Next(1000);
            int edges    = vertices / 2 + rnd.Next(vertices * vertices / 4);
            for (int i = 0; i < edges; ++i)
            {
                int start = rnd.Next(vertices);
                int end   = rnd.Next(vertices);
                if (start != end)
                {
                    g.AddEdge(start, end);
                }
            }
            g.RemoveEdge(0, vertices - 1); // Remove trivial path!
            if (log)
            {
                Console.WriteLine(g);
            }

            var paths        = g.FindVertexDisjointPaths1(0, vertices - 1);
            var usedVertices = CheckVDP(g, paths, log);
            // Find a cut
            var cut = g.FindCutVDP(0, paths);
            if (log)
            {
                Console.WriteLine("Size of cut: {0}", cut.Count());
            }
            if (paths.Count() != cut.Count())
            {
                throw new Exception("Cut and disjoint path count differ.");
            }
            foreach (var v in cut)
            {
                g.RemoveVertex(v);
            }
            if (g.FindPath(0, vertices - 1).Count() > 0)
            {
                Console.WriteLine(g);
                throw new Exception("Graph not disconnected!");
            }
        }
    }