Exemplo n.º 1
0
        public static void TestGunrockCcSimpleExampleQuickGraphRepresentation()
        {
            int[][] graph = new int[9][];
            graph[0] = new [] { 1, 2, 3 };
            graph[1] = new [] { 0, 2, 4 };
            graph[2] = new [] { 3, 4, 5 };
            graph[3] = new [] { 5, 6 };
            graph[4] = new [] { 2, 5, 6 };
            graph[5] = new [] { 6 };
            graph[6] = new int[] { };
            graph[7] = new int[] { };
            graph[8] = new int[] { };


            DelegateVertexAndEdgeListGraph <int, SEquatableEdge <int> > g = Enumerable.Range(0, graph.Length).ToDelegateVertexAndEdgeListGraph(v => Array.ConvertAll(graph[v], w => new SEquatableEdge <int>(v, w))
                                                                                                                                               );

            var arrayAdjacencyGraph = g.ToArrayAdjacencyGraph();
            var res = ConnectedComponents.FindComponents <SEquatableEdge <int>, IEdgeListGraph <int, SEquatableEdge <int> > >(
                arrayAdjacencyGraph);

            foreach (var keyValuePair in res)
            {
                Console.WriteLine(keyValuePair.Key + " is in CC #" + keyValuePair.Value);
            }
        }
Exemplo n.º 2
0
        //shows the same type of results as gunrock version - useful for testing
        public static void RunQuickGraphSsspShowResults(string path)
        {
            var csrRepresentation = Util.CreateCsrRepresentation(path);
            Dictionary <int, int> findComponents  = ConnectedComponents.FindComponents(csrRepresentation);
            Dictionary <int, int> componentsSizes = new Dictionary <int, int>();

            foreach (var keyValuePair in findComponents)
            {
                Console.WriteLine(keyValuePair);
                if (!componentsSizes.ContainsKey(keyValuePair.Value))
                {
                    componentsSizes.Add(keyValuePair.Value, 1);
                }
                else
                {
                    componentsSizes[keyValuePair.Value] += 1;
                }
            }
            var keyValuePairs = componentsSizes.Values.ToList();

            keyValuePairs.Sort();
            foreach (var keyValuePair in keyValuePairs)
            {
                Console.WriteLine(keyValuePair);
            }
        }
Exemplo n.º 3
0
        public static double MeasureConnectedComponentsGunrockSpeed(string path)
        {
            Stopwatch             sw  = new Stopwatch();
            Dictionary <int, int> res = null;
            int iterationNum          = 10;
            var csrRepresentation     = Util.CreateCsrRepresentation(path);

            for (int i = 0; i < iterationNum; i++)
            {
                sw.Start();
                res = ConnectedComponents.FindComponents(csrRepresentation);
                sw.Stop();
                Console.WriteLine("Iteration " + i);
            }
            var elapsedMs = sw.ElapsedMilliseconds / (double)iterationNum;

            Console.WriteLine("Gunrock: " + elapsedMs + " ms");
            return(elapsedMs);
        }