Exemple #1
0
        /**
         * Adds all the vertices and all the edges of the specified source graph to the specified
         * destination graph. First all vertices of the source graph are added to the destination graph.
         * Then every edge of the source graph is added to the destination graph. This method returns
         * <code>true</code> if the destination graph has been modified as a result of this operation,
         * otherwise it returns <code>false</code>.
         *
         * <p>
         * The behavior of this operation is undefined if any of the specified graphs is modified while
         * operation is in progress.
         * </p>
         *
         * @param destination the graph to which vertices and edges are added
         * @param source the graph used as source for vertices and edges to add
         * @param <V> the graph vertex type
         * @param <E> the graph edge type
         *
         * @return <code>true</code> if and only if the destination graph has been changed as a result
         *         of this operation.
         */
        public static bool addGraph <V, E>(Graph <V, E> destination, Graph <V, E> source)
        {
            bool modified = addAllVertices(destination, source.vertexSet());

            modified |= addAllEdges(destination, source, source.edgeSet());

            return(modified);
        }
Exemple #2
0
        /**
         * Filters vertices from the given graph and subsequently removes them. If the vertex to be
         * removed has one or more predecessors, the predecessors will be connected directly to the
         * successors of the vertex to be removed.
         *
         * @param graph graph to be mutated
         * @param predicate a non-interfering stateless predicate to apply to each vertex to determine
         *        if it should be removed from the graph
         * @param <V> the graph vertex type
         * @param <E> the graph edge type
         *
         * @return true if at least one vertex has been removed; false otherwise.
         */
        public static bool removeVerticesAndPreserveConnectivity <V, E>(Graph <V, E> graph, Predicate <V> predicate)
        {
            List <V> verticesToRemove = new List <V>();

            foreach (V node in graph.vertexSet())
            {
                if (predicate(node))
                {
                    verticesToRemove.Add(node);
                }
            }

            return(removeVertexAndPreserveConnectivity(graph, verticesToRemove));
        }
Exemple #3
0
        /**
         * Adds all the vertices and all the edges of the specified source digraph to the specified
         * destination digraph, reversing all of the edges. If you want to do this as a linked view of
         * the source graph (rather than by copying to a destination graph), use
         * {@link EdgeReversedGraph} instead.
         *
         * <p>
         * The behavior of this operation is undefined if any of the specified graphs is modified while
         * operation is in progress.
         *
         * @param destination the graph to which vertices and edges are added
         * @param source the graph used as source for vertices and edges to add
         * @param <V> the graph vertex type
         * @param <E> the graph edge type
         *
         * @see EdgeReversedGraph
         */
        public static void addGraphReversed <V, E>(Graph <V, E> destination, Graph <V, E> source)
        {
            if (!source.getType().isDirected() || !destination.getType().isDirected())
            {
                throw new ArgumentException("graph must be directed");
            }

            addAllVertices(destination, source.vertexSet());

            foreach (E edge in source.edgeSet())
            {
                destination.addEdge(source.getEdgeTarget(edge), source.getEdgeSource(edge));
            }
        }