Esempio n. 1
0
        public static void DeleteVerticesAndMergeEdges <TVertex, TEdge>
            (this IMutableBidirectionalGraph <TVertex, TEdge> graph, TVertex vertexToDelete,
            Func <TEdge, TEdge, TEdge> mergeFunc)
            where TEdge : IEdge <TVertex>
        {
            if (graph.IsInEdgesEmpty(vertexToDelete) || graph.IsOutEdgesEmpty(vertexToDelete))
            {
                //simple case
                graph.RemoveVertex(vertexToDelete);
            }
            else
            {
                //need to keep connections
                var newEdges = from e1 in graph.InEdges(vertexToDelete)
                               from e2 in graph.OutEdges(vertexToDelete)
                               select mergeFunc(e1, e2);

                //create edges
                var newEdgesList = newEdges.ToList();

                graph.AddEdgeRange(newEdgesList);
                graph.RemoveVertex(vertexToDelete);
            }
        }