Example #1
0
        public static IEnumerable <Graph> RemoveEdge(this IEnumerable <Graph> connectedComponents,
                                                     Edge edge)
        {
            ICollection <Graph> cc = new List <Graph>(connectedComponents);
            Graph graph            = cc.Single(c => c.Edges.Contains(edge));

            graph.RemoveEdge(edge);

            // check if vertices are still in the same connected component
            IEnumerable <Vertex> bfsA = graph.BreadthFirstSearch(edge.VertexA).ToList();

            if (!bfsA.Contains(edge.VertexB))
            {
                cc.Remove(graph);
                IEnumerable <Edge> edgesA = graph.Edges.Where(e => bfsA.Contains(e.VertexA)).ToList();
                cc.Add(new Graph(bfsA, edgesA));
                cc.Add(new Graph(graph.Vertices.Except(bfsA), graph.Edges.Except(edgesA)));
            }

            return(cc);
        }