private static void CheckComponentCount <TVertex, TEdge>(
            [NotNull] IVertexListGraph <TVertex, TEdge> graph,
            [NotNull] IVertexSet <AdjacencyGraph <TVertex, TEdge> > condensedGraph)
            where TEdge : IEdge <TVertex>
        {
            // Check number of vertices = number of strongly connected components
            var components     = new Dictionary <TVertex, int>();
            int componentCount = graph.StronglyConnectedComponents(components);

            Assert.AreEqual(componentCount, condensedGraph.VertexCount, "Component count does not match.");
        }
Exemplo n.º 2
0
        private static List <List <string> > GetCycle(MatrixWithHeaders matrixWithHeaders)
        {
            IVertexListGraph <object, IEdge <object> > graph = Graph.AdjacentyMatrixToGraph(matrixWithHeaders);
            List <List <object> > candidates = new List <List <object> >();
            List <List <string> > outlines   = new List <List <string> >();

            var stronglyConnectedDict = (IDictionary <object, int>)(new Dictionary <object, int>());
            var z = graph.StronglyConnectedComponents(out stronglyConnectedDict);

            for (int x = 0; x < z; x++)
            {
                candidates.Add(new List <object>());
                outlines.Add(new List <string>());
            }

            foreach (var item in stronglyConnectedDict)
            {
                candidates[item.Value].Add(item.Key);
            }

            int counter = 0;

            foreach (var item in candidates)
            {
                if (item.Count > 1)
                {
                    foreach (var subitem in item)
                    {
                        outlines[counter].Add(subitem.ToString());
                    }
                    counter++;
                }
            }

            return(outlines);
        }