private static void CheckComponentCount <TVertex, TEdge>(
            [NotNull] IVertexAndEdgeListGraph <TVertex, TEdge> graph,
            [NotNull] IMutableBidirectionalGraph <AdjacencyGraph <TVertex, TEdge>, CondensedEdge <TVertex, TEdge, 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.");
        }
        private void CheckComponentCount <TVertex, TEdge>(
            IVertexAndEdgeListGraph <TVertex, TEdge> g,
            IMutableBidirectionalGraph <AdjacencyGraph <TVertex, TEdge>, CondensedEdge <TVertex, TEdge, AdjacencyGraph <TVertex, TEdge> > > cg)
            where TEdge : IEdge <TVertex>
        {
            // check number of vertices = number of storngly connected components
            IDictionary <TVertex, int> components;
            int componentCount = g.StronglyConnectedComponents(out components);

            Assert.Equal(componentCount, cg.VertexCount);
        }
示例#3
0
        public static bool ContainsCycle <TVertex>(this IVertexAndEdgeListGraph <TVertex, Edge <TVertex> > graph)
        {
            if (graph.Edges.Any(e => e.IsSelfEdge <TVertex, Edge <TVertex> >()))
            {
                return(true);
            }
            IDictionary <TVertex, int> components;

            graph.StronglyConnectedComponents(out components);
            return(components.Select(c => c.Value).Distinct().Count() != graph.Vertices.Count());
        }